ApplicationSection.php
2.37 KB
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
<?php
namespace Nextend\Framework\Model;
class ApplicationSection {
private $application = 'system';
/**
* Quick cache implementation to prevent duplicate queries. It might have bugs.
*
* @var array
*/
protected $cache = array();
public function __construct($application) {
$this->application = $application;
}
public function getById($id, $section) {
return Section::getById($id, $section);
}
public function setById($id, $value) {
$this->cache = array();
return Section::setById($id, $value);
}
public function get($section, $referenceKey = null, $default = null) {
if (isset($this->cache[$section . '///' . $referenceKey])) {
return $this->cache[$section . '///' . $referenceKey];
}
$attributes = array(
"application" => $this->application,
"section" => $section
);
if ($referenceKey !== null) {
$attributes['referencekey'] = $referenceKey;
}
$result = Section::$tableSectionStorage->findByAttributes($attributes);
if (is_array($result)) {
$this->cache[$section . '///' . $referenceKey] = $result['value'];
return $result['value'];
}
return $default;
}
public function getAll($section, $referenceKey = null) {
return Section::getAll($this->application, $section, $referenceKey);
}
public function set($section, $referenceKey, $value) {
if (isset($this->cache[$section . '///' . $referenceKey])) {
unset($this->cache[$section . '///' . $referenceKey]);
}
Section::set($this->application, $section, $referenceKey, $value);
}
public function add($section, $referenceKey, $value) {
if (isset($this->cache[$section . '///' . $referenceKey])) {
unset($this->cache[$section . '///' . $referenceKey]);
}
return Section::add($this->application, $section, $referenceKey, $value);
}
public function delete($section, $referenceKey = null) {
if (isset($this->cache[$section . '///' . $referenceKey])) {
unset($this->cache[$section . '///' . $referenceKey]);
}
return Section::delete($this->application, $section, $referenceKey);
}
public function deleteById($id) {
return Section::deleteById($id);
}
}