1 | <?php |
||
17 | class Trigger extends Base |
||
18 | { |
||
19 | |||
20 | /** |
||
21 | * Trigger model instance |
||
22 | * @var \gplcart\core\models\Trigger $trigger |
||
23 | */ |
||
24 | protected $trigger; |
||
25 | |||
26 | /** |
||
27 | * @param TriggerModel $trigger |
||
28 | */ |
||
29 | public function __construct(TriggerModel $trigger) |
||
30 | { |
||
31 | parent::__construct(); |
||
32 | |||
33 | $this->trigger = $trigger; |
||
34 | } |
||
35 | |||
36 | /** |
||
37 | * Callback for "trigger-get" command |
||
38 | */ |
||
39 | public function cmdGetTrigger() |
||
40 | { |
||
41 | $result = $this->getListTrigger(); |
||
42 | $this->outputFormat($result); |
||
43 | $this->outputFormatTableTrigger($result); |
||
44 | $this->output(); |
||
45 | } |
||
46 | |||
47 | /** |
||
48 | * Callback for "trigger-delete" command |
||
49 | */ |
||
50 | public function cmdDeleteTrigger() |
||
51 | { |
||
52 | $id = $this->getParam(0); |
||
53 | |||
54 | if (empty($id) || !is_numeric($id)) { |
||
55 | $this->errorAndExit($this->text('Invalid argument')); |
||
56 | } |
||
57 | |||
58 | if ($this->getParam('store')) { |
||
59 | |||
60 | $deleted = $count = 0; |
||
61 | foreach ($this->trigger->getList(array('store_id' => $id)) as $item) { |
||
62 | $count++; |
||
63 | $deleted += (int) $this->trigger->delete($item['trigger_id']); |
||
64 | } |
||
65 | |||
66 | $result = $count && $count == $deleted; |
||
67 | } else { |
||
68 | $result = $this->trigger->delete($id); |
||
69 | } |
||
70 | |||
71 | if (empty($result)) { |
||
72 | $this->errorAndExit($this->text('Unexpected result')); |
||
73 | } |
||
74 | |||
75 | $this->output(); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * Callback for "trigger-add" command |
||
80 | */ |
||
81 | public function cmdAddTrigger() |
||
91 | |||
92 | /** |
||
93 | * Callback for "trigger-update" command |
||
94 | */ |
||
95 | public function cmdUpdateTrigger() |
||
117 | |||
118 | /** |
||
119 | * Returns an array of triggers |
||
120 | * @return array |
||
121 | */ |
||
122 | protected function getListTrigger() |
||
146 | |||
147 | /** |
||
148 | * Output table format |
||
149 | * @param array $items |
||
150 | */ |
||
151 | protected function outputFormatTableTrigger(array $items) |
||
175 | |||
176 | /** |
||
177 | * Add a new trigger |
||
178 | */ |
||
179 | protected function addTrigger() |
||
189 | |||
190 | /** |
||
191 | * Updates a trigger |
||
192 | * @param string $trigger_id |
||
193 | */ |
||
194 | protected function updateTrigger($trigger_id) |
||
200 | |||
201 | /** |
||
202 | * Add a new trigger at once |
||
203 | */ |
||
204 | protected function submitAddTrigger() |
||
213 | |||
214 | /** |
||
215 | * Add a trigger step by step |
||
216 | */ |
||
217 | protected function wizardAddTrigger() |
||
229 | |||
230 | } |
||
231 |