1 | <?php |
||
2 | |||
3 | namespace Apps\Model\Admin\Main; |
||
4 | |||
5 | |||
6 | use Ffcms\Core\App; |
||
7 | use Ffcms\Core\Arch\Model; |
||
8 | |||
9 | /** |
||
10 | * Class FormYandexCounter |
||
11 | * @package Apps\Model\Admin\Main |
||
12 | */ |
||
13 | class FormYandexCounter extends Model |
||
14 | { |
||
15 | public $counter; |
||
16 | |||
17 | private $_counters; |
||
18 | |||
19 | /** |
||
20 | * FormYandexCounter constructor. |
||
21 | * @param array $counters |
||
22 | */ |
||
23 | public function __construct(array $counters) |
||
24 | { |
||
25 | $this->_counters = $counters; |
||
26 | parent::__construct(false); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Validation rules |
||
31 | * @return array |
||
32 | */ |
||
33 | public function rules(): array |
||
34 | { |
||
35 | return [ |
||
36 | ['counter', 'required'], |
||
37 | ['counter', 'int'] |
||
38 | ]; |
||
39 | } |
||
40 | |||
41 | /** |
||
42 | * Save counter id to configuration file |
||
43 | */ |
||
44 | public function make() |
||
45 | { |
||
46 | $cfg = App::$Properties->getAll('Yandex'); |
||
47 | $cfg['metrika']['id'] = (int)$this->counter; |
||
48 | |||
49 | App::$Properties->writeConfig('Yandex', $cfg); |
||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Get counter id->name |
||
54 | * @return array |
||
55 | */ |
||
56 | public function getCounters(): array |
||
57 | { |
||
58 | return $this->_counters; |
||
59 | } |
||
60 | } |