/
GeneralDelete.php
131 lines (104 loc) · 3.11 KB
/
GeneralDelete.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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
declare(strict_types=1);
/*
* This file is part of the QuidPHP package <https://quidphp.com>
* Author: Pierre-Philippe Emond <emondpph@gmail.com>
* License: https://github.com/quidphp/lemur/blob/master/LICENSE
*/
namespace Quid\Lemur\Cms;
use Quid\Base;
use Quid\Core;
use Quid\Lemur;
// generalDelete
// class for the route which allows deleting rows from the general navigation page of the CMS
class GeneralDelete extends Core\RouteAlias
{
// trait
use _common;
use _general;
use Lemur\Route\_formSubmit;
use Lemur\Segment\_table;
// config
protected static array $config = [
'path'=>[
'en'=>'table/[table]/multi/delete',
'fr'=>'table/[table]/multiple/effacer'],
'segment'=>[
'table'=>'structureSegmentTable'],
'match'=>[
'method'=>'post',
'csrf'=>true,
'genuine'=>true,
'post'=>['-table-'=>['='=>'[table]']],
'session'=>'canAccess'],
'parent'=>General::class,
'group'=>'submit'
];
// dynamique
protected array $ids = []; // conserve les ids pour la route
// onBefore
// validation des permissions avant de lancer la route
// les ids à effacer sont conservé
final protected function onBefore()
{
$return = false;
if(parent::onBefore())
{
$ids = $this->request()->get('primaries');
$this->makeIds((string) $ids);
$return = (!empty($this->ids));
}
return $return;
}
// canTrigger
// si la route peut être lancé
final public function canTrigger():bool
{
return parent::canTrigger() && $this->hasTable() && $this->table()->hasPermission('view','general','delete','rows','lemurDelete','multiDelete');
}
// makeIds
// prend une valeur et store la propriété ids
final protected function makeIds(string $ids):void
{
if(!empty($ids))
{
$default = static::getDefaultSegment();
$ids = Base\Str::explodeTrimClean($default,$ids);
if(is_array($ids) && !empty($ids) && Base\Arr::onlyNumeric($ids))
$this->ids = Base\Arr::cast($ids);
}
}
// ids
// retourne le tableau des ids
final protected function ids():array
{
return $this->ids;
}
// rows
// retourne l'objet rows
final protected function rows():Core\Rows
{
return $this->table()->rows(...$this->ids());
}
// routeSuccess
// retourne la route en cas de succès ou échec de la suppression
final public function routeSuccess():Core\Route
{
return $this->general();
}
// proceed
// efface la row ou les rows
final protected function proceed():?int
{
$return = null;
$post = $this->post();
$post = $this->onBeforeCommit($post);
$timestamp = $this->request()->postTimestamp();
if($post !== null)
$return = $this->rows()->delete(['com'=>true,'timestamp'=>$timestamp]);
return $this->proceedAfter($return);
}
}
// init
GeneralDelete::__init();
?>