/
containers.php
86 lines (70 loc) · 2.86 KB
/
containers.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
<?php
namespace Concrete\Controller\SinglePage\Dashboard\Pages;
use Concrete\Core\Entity\Page\Container;
use Concrete\Core\Page\Container\Command\ContainerCommandValidator;
use Concrete\Core\Page\Container\Command\DeleteContainerCommand;
use Concrete\Core\Page\Container\Command\UpdateContainerCommand;
use Concrete\Core\Page\Controller\DashboardPageController;
class Containers extends DashboardPageController
{
public function view()
{
$this->set(
'containers',
$this->entityManager->getRepository(Container::class)
->findBy([], ['containerName' => 'asc'])
);
}
public function edit($containerID = null)
{
$container = $this->getContainer($containerID);
$this->set('container', $container);
$this->set('tokenMessage', 'update_container');
$this->render('/dashboard/pages/containers/form');
}
public function delete_container($containerID = null)
{
if ($this->token->validate('delete_container')) {
$container = $this->getContainer($containerID);
$command = new DeleteContainerCommand($container);
$this->executeCommand($command);
$this->flash('success', t('Container removed successfully.'));
return $this->buildRedirect('/dashboard/pages/containers');
}
$this->error->add($this->token->getErrorMessage());
$this->edit($containerID);
}
public function update_container($containerID = null)
{
if ($this->token->validate('update_container')) {
$container = $this->getContainer($containerID);
$container->setContainerName($this->request->request->get('containerName'));
$container->setContainerHandle($this->request->request->get('containerHandle'));
$container->setContainerIcon($this->request->request->get('containerIcon'));
$command = new UpdateContainerCommand($container);
$validator = $this->app->make(ContainerCommandValidator::class);
$errorList = $validator->validate($command);
if ($errorList->has()) {
$this->error->add($errorList);
} else {
$this->executeCommand($command);
$this->flash('success', t('Container saved successfully.'));
return $this->buildRedirect('/dashboard/pages/containers');
}
} else {
$this->error->add($this->token->getErrorMessage());
}
$this->edit($containerID);
}
protected function getContainer($containerID = null)
{
$container = null;
if ($containerID) {
$container = $this->entityManager->find(Container::class, $containerID);
}
if (!$container) {
return $this->buildRedirect('/dashboard/pages/containers');
}
return $container;
}
}