1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: class QModelConnectorOptions extends QBaseClass {
15: protected $options = array();
16: protected $blnChanged = false;
17:
18: const TableOptionsFieldName = '*';
19:
20: public function __construct() {
21: if (file_exists(__CONFIGURATION__ . '/codegen_options.json')) {
22: $strContent = file_get_contents(__CONFIGURATION__ . '/codegen_options.json');
23:
24: if ($strContent) {
25: $this->options = json_decode($strContent, true);
26: }
27: }
28:
29:
30: }
31:
32: 33: 34:
35: function Save() {
36: if (!$this->blnChanged) {
37: return;
38: }
39: $flags = 0;
40: if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
41: $flags = JSON_PRETTY_PRINT;
42: }
43: $strContent = json_encode ($this->options, $flags);
44:
45: file_put_contents(__CONFIGURATION__ . '/codegen_options.json', $strContent);
46: $this->blnChanged = false;
47: }
48:
49: 50: 51:
52: function __destruct() {
53: $this->Save();
54: }
55:
56:
57: 58: 59: 60: 61: 62: 63: 64:
65: public function SetOption ($strTableName, $strFieldName, $strOptionName, $mixValue) {
66: $this->options[$strTableName][$strFieldName][$strOptionName] = $mixValue;
67: $this->blnChanged = true;
68: }
69:
70: 71: 72: 73: 74: 75: 76:
77: public function SetOptions ($strClassName, $strFieldName, $mixValue) {
78: if (empty ($mixValue)) {
79: unset($this->options[$strClassName][$strFieldName]);
80: }
81: else {
82: $this->options[$strClassName][$strFieldName] = $mixValue;
83: }
84: $this->blnChanged = true;
85: }
86:
87: 88: 89: 90: 91: 92: 93:
94: public function UnsetOption ($strClassName, $strFieldName, $strOptionName) {
95: unset ($this->options[$strClassName][$strFieldName][$strOptionName]);
96: $this->blnChanged = true;
97: }
98:
99: 100: 101: 102: 103: 104: 105: 106:
107: public function GetOption ($strClassName, $strFieldName, $strOptionName) {
108: if (isset ($this->options[$strClassName][$strFieldName][$strOptionName])) {
109: return $this->options[$strClassName][$strFieldName][$strOptionName];
110: } else {
111: return null;
112: }
113: }
114:
115: 116: 117: 118: 119: 120:
121: public function GetOptions ($strClassName, $strFieldName) {
122: if (isset($this->options[$strClassName][$strFieldName])) {
123: return $this->options[$strClassName][$strFieldName];
124: } else {
125: return array();
126: }
127: }
128:
129: }