-
Notifications
You must be signed in to change notification settings - Fork 452
/
delete.php
83 lines (72 loc) · 2.82 KB
/
delete.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
<?php
namespace Concrete\Controller\Dialog\Express\Preset;
use Concrete\Controller\Dialog\Search\Preset\Delete as PresetDelete;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\Application\EditResponse;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\JsonResponse;
use Permissions;
class Delete extends PresetDelete
{
protected function getEntity()
{
$entity = null;
$em = $this->app->make(EntityManager::class);
if (is_object($em)) {
$entityID = $this->request->query->get('objectID');
if (empty($entityID) && !empty($this->request->request->get('objectID'))) {
$entityID = $this->request->request->get('objectID');
}
$entity = $em->getRepository('Concrete\Core\Entity\Express\Entity')->findOneById($entityID);
if (is_object($entity)) {
$this->objectID = $entityID;
}
}
return $entity;
}
protected function canAccess()
{
$entity = $this->getEntity();
if (is_object($entity)) {
$ep = new Permissions($entity);
return $ep->canViewExpressEntries();
}
return false;
}
public function getSavedSearchEntity()
{
$em = $this->app->make(EntityManager::class);
if (is_object($em)) {
return $em->getRepository('Concrete\Core\Entity\Search\SavedExpressSearch');
}
return null;
}
public function remove_search_preset()
{
if ($this->validateAction()) {
$app = Application::getFacadeApplication();
$securityHelper = $app->make('helper/security');
$presetID = $securityHelper->sanitizeInt($this->request->request->get('presetID'));
if (!empty($presetID)) {
$searchEntity = $this->getSavedSearchEntity();
if (is_object($searchEntity)) {
$searchPreset = $searchEntity->findOneById($presetID);
if (!is_object($searchPreset)) {
$this->error->add(t('Invalid search preset.'));
}
if (!$this->error->has()) {
$response = new EditResponse();
$response->setMessage(t('%s deleted successfully.', $searchPreset->getPresetName()));
$response->setAdditionalDataAttribute('presetID', $presetID);
$em = $this->app->make(\Doctrine\ORM\EntityManager::class);
$em->remove($searchPreset);
$em->flush();
return new JsonResponse($response);
}
}
}
}
$this->error->add(t('You can\'t delete this search preset.'));
return new JsonResponse($this->error);
}
}