-
Notifications
You must be signed in to change notification settings - Fork 0
/
admin.php
106 lines (67 loc) · 2.38 KB
/
admin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
require(__DIR__.'/mondongo/lib/vendor/symfony/src/Symfony/Component/HttpFoundation/UniversalClassLoader.php');
use Symfony\Component\HttpFoundation\UniversalClassLoader;
$loader = new UniversalClassLoader();
$loader->registerNamespaces(array(
'Mondongo' => __DIR__.'/mondongo/lib',
'Model' => __DIR__,
));
$loader->register();
$mondongo = new Mondongo\Mondongo();
$mondongo->setConnection("connection_1", new Mondongo\Connection("localhost", "test"));
Mondongo\Container::setDefault($mondongo);
?>
<?php
/*************** ACTIONS **************/
$action = $_GET['action'];
switch($action)
{
case "add":
$Person = new Model\Document\Person();
$Person->setName($_POST['name']);
$Person->setSurname($_POST['surname']);
$Person->save();
break;
case "delete":
$repository = $mondongo->getRepository("Model\Repository\Person");
$Person = $repository->findOneById(new MongoId($_GET['id']));
$Person->delete();
break;
case "modify":
$repository = $mondongo->getRepository("Model\Repository\Person");
$Person = $repository->findOneById(new MongoId($_GET['id']));
$Person->setName($_POST['name']);
$Person->setSurname($_POST['surname']);
$Person->save();
break;
}
?>
<?php
/********** add new document *******/
?>
<form action="admin.php?action=add" method="post">
<input type="text" name="name"/>
<input type="text" name="surname"/>
<input type="submit" value="save"/>
</form>
<?php
/****** show documents *****/
$repository = $mondongo->getRepository("Model\Repository\Person");
$documents = $repository->find();
if(!$documents) $documents = array();
?>
<ul>
<?php foreach($documents as $document):?>
<?php if($document->getId() == $_GET['id']):?>
<li>
<form action="admin.php?action=modify&id=<?php echo $document->getId() ?>" method="post">
<input type="text" value="<?php echo $document->getName() ?>" name="name"/>
<input type="text" value="<?php echo $document->getSurName() ?>" name="surname"/>
<input type="submit" value="save" />
</form>
</li>
<?php else: ?>
<li><?php echo $document->getName() ?> <?php echo $document->getSurName() ?> <a href="admin.php?action=edit&id=<?php echo $document->getId() ?>">Edit</a> <a href="admin.php?action=delete&id=<?php echo $document->getId() ?>">Delete</a></li>
<?php endif; ?>
<?php endforeach; ?>
</ul>