1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package Cadmium\System\Modules\Extend |
5
|
|
|
* @author Anton Romanov |
6
|
|
|
* @copyright Copyright (c) 2015-2017, Anton Romanov |
7
|
|
|
* @link http://cadmium-cms.com |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Modules\Extend\Utils\Handler { |
11
|
|
|
|
12
|
|
|
use Modules\Extend, Ajax, Language, Request, Template; |
13
|
|
|
|
14
|
|
|
abstract class Basic extends Extend\Utils\Handler { |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Process the item block |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
protected function processItem(Template\Block $item, array $data) { |
21
|
|
|
|
22
|
|
|
$item->class = (($data['name'] === $this->loader->get('name')) ? 'positive' : 'grey'); |
|
|
|
|
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Process the contents block |
27
|
|
|
*/ |
28
|
|
|
|
29
|
|
|
protected function processContents(Template\Block $contents) { |
30
|
|
|
|
31
|
|
|
$contents->section = $this->loader->getSection(); |
|
|
|
|
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Handle the ajax request |
36
|
|
|
*/ |
37
|
|
|
|
38
|
|
|
protected function handleAjax() : Ajax\Response { |
39
|
|
|
|
40
|
|
|
$ajax = Ajax::createResponse(); |
41
|
|
|
|
42
|
|
|
# Process actions |
43
|
|
|
|
44
|
|
|
if (Request::post('action') === 'activate') { |
45
|
|
|
|
46
|
|
|
$name = Request::post('name'); |
47
|
|
|
|
48
|
|
|
if (!$this->loader->activate($name, true)) return $ajax->setError(Language::get(static::$error_activate)); |
49
|
|
|
|
50
|
|
|
} else if (Request::post('action') === 'list') { |
51
|
|
|
|
52
|
|
|
$ajax->set('items', $this->loader->getItems()); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
# ------------------------ |
56
|
|
|
|
57
|
|
|
return $ajax; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Handle the request |
62
|
|
|
* |
63
|
|
|
* @return Template\Block|Ajax\Response : a block object if the ajax param was set to false, otherwise an ajax response |
64
|
|
|
*/ |
65
|
|
|
|
66
|
|
View Code Duplication |
public function handle(bool $ajax = false) { |
|
|
|
|
67
|
|
|
|
68
|
|
|
$this->loader = new static::$loader_class(Request::get('list')); |
69
|
|
|
|
70
|
|
|
if ($ajax) return $this->handleAjax(); |
71
|
|
|
|
72
|
|
|
# ------------------------ |
73
|
|
|
|
74
|
|
|
return $this->getContents(); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.