|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Models; |
|
4
|
|
|
|
|
5
|
|
|
use Core\Container; |
|
6
|
|
|
use Core\Model; |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Class ConfigModel |
|
10
|
|
|
* @package App\Models |
|
11
|
|
|
*/ |
|
12
|
|
|
class ConfigModel extends Model |
|
13
|
|
|
{ |
|
14
|
|
|
|
|
15
|
|
|
private $configsTbl; |
|
16
|
|
|
private $configsClassTbl; |
|
17
|
|
|
private $configTypeTbl; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(Container $container) |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct($container); |
|
22
|
|
|
|
|
23
|
|
|
$this->configsTbl = $this->getTablePrefix('configs'); |
|
24
|
|
|
$this->configsClassTbl = $this->getTablePrefix('configs_class'); |
|
25
|
|
|
$this->configTypeTbl = $this->getTablePrefix('configs_type'); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* Returns all the configs orderd with their class names |
|
30
|
|
|
* @return array |
|
31
|
|
|
* @throws \Exception |
|
32
|
|
|
*/ |
|
33
|
|
|
public function getAllConfigOrdered(): array |
|
34
|
|
|
{ |
|
35
|
|
|
$returnData = []; |
|
36
|
|
|
//getting our tables |
|
37
|
|
|
|
|
38
|
|
|
$sql = "SELECT idconfigs, configs_name, configs_type_name, configs_value, class FROM $this->configsTbl |
|
39
|
|
|
INNER JOIN $this->configsClassTbl ON $this->configsTbl.configs_class_idconfigsclass = $this->configsClassTbl.idconfigsclass |
|
40
|
|
|
INNER JOIN $this->configTypeTbl ON $this->configsTbl.configs_type_idconfigs_type = $this->configTypeTbl.idconfigs_type |
|
41
|
|
|
ORDER BY class, $this->configsTbl.order, configs_name;"; |
|
42
|
|
|
|
|
43
|
|
|
$this->query($sql); |
|
44
|
|
|
$this->execute(); |
|
45
|
|
|
$configClass = $this->fetchAll(); |
|
46
|
|
|
foreach ($configClass as $class) { |
|
47
|
|
|
//we remove the first 3 characters as they are used for ordering (10_global_site_configuration) |
|
48
|
|
|
$className = substr($class->class, 3); |
|
49
|
|
|
|
|
50
|
|
|
if (!isset($returnData[$className])) { |
|
51
|
|
|
$returnData[$className] = []; |
|
52
|
|
|
} |
|
53
|
|
|
$returnData[$className][] = $class; |
|
54
|
|
|
} |
|
55
|
|
|
return $returnData; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* gets the entire config table |
|
60
|
|
|
* @return array |
|
61
|
|
|
* @throws \ReflectionException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function getAllConfig() |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->getResultSet(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* updates the site config table |
|
70
|
|
|
* @param int $idTable |
|
71
|
|
|
* @param string $param parameter to update |
|
72
|
|
|
* @return bool update success |
|
73
|
|
|
* @throws \Exception error |
|
74
|
|
|
*/ |
|
75
|
|
|
public function updateConfig(int $idTable, string $param): bool |
|
76
|
|
|
{ |
|
77
|
|
|
$sql = "UPDATE $this->configsTbl SET configs_value = :param WHERE idconfigs = :id"; |
|
78
|
|
|
$this->query($sql); |
|
79
|
|
|
$this->bind(':param', $param); |
|
80
|
|
|
$this->bind(':id', $idTable); |
|
81
|
|
|
return $this->finalExecute(); |
|
82
|
|
|
|
|
83
|
|
|
} |
|
84
|
|
|
} |