/
delete.php
71 lines (63 loc) · 2.63 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
<?php
namespace Concrete\Controller\Dialog\Search\Preset;
use Concrete\Controller\Backend\UserInterface;
use Concrete\Core\Support\Facade\Application;
use Concrete\Core\Application\EditResponse;
use Symfony\Component\HttpFoundation\JsonResponse;
use Doctrine\ORM\EntityManager;
abstract class Delete extends UserInterface
{
protected $viewPath = '/dialogs/search/preset/delete';
protected $validationToken = 'remove_search_preset';
public $objectID = null;
public function getDeleteSearchPresetAction()
{
return $this->action('remove_search_preset');
}
public function view()
{
$app = Application::getFacadeApplication();
$searchPreset = null;
$securityHelper = $app->make('helper/security');
$presetID = $securityHelper->sanitizeInt($this->request->query->get('presetID'));
$searchEntity = $this->getSavedSearchEntity();
if (!empty($presetID) && is_object($searchEntity)) {
$searchPreset = $searchEntity->findOneById($presetID);
}
$this->set('searchPreset', $searchPreset);
$this->set('form', $app->make('helper/form'));
$this->set('token', $app->make('helper/validation/token'));
}
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(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);
}
public function getObjectID()
{
return (string) $this->objectID;
}
}