20
20
21
21
require_once BASE_PATH .'/core/models/dao/SettingDao.php ' ;
22
22
23
- /** Setting Model Base */
23
+ /** Configuration setting base model class. */
24
24
abstract class SettingModelBase extends AppModel
25
25
{
26
- /** Constructor */
26
+ /** Constructor. */
27
27
public function __construct ()
28
28
{
29
29
parent ::__construct ();
@@ -39,50 +39,74 @@ public function __construct()
39
39
$ this ->initialize (); // required
40
40
}
41
41
42
- /** Get DAO by name */
42
+ /**
43
+ * Return a configuration setting given its name and module name.
44
+ *
45
+ * @param string $name configuration setting name
46
+ * @param string $module module name
47
+ * @return false|SettingDao configuration setting DAO or false on failure
48
+ * @throws Zend_Exception
49
+ */
43
50
abstract public function getDaoByName ($ name , $ module = 'core ' );
44
51
45
- /** get value by name */
52
+ /**
53
+ * Return the value of a configuration setting given its name and module
54
+ * name.
55
+ *
56
+ * @param string $name configuration setting name
57
+ * @param string $module module name
58
+ * @return bool|int|float|string|void configuration setting value or void on failure
59
+ * @throws Zend_Exception
60
+ */
46
61
public function getValueByName ($ name , $ module = 'core ' )
47
62
{
48
- $ dao = $ this ->getDaoByName ($ name , $ module );
49
- if ($ dao === false ) {
63
+ $ settingDao = $ this ->getDaoByName ($ name , $ module );
64
+ if ($ settingDao === false ) {
50
65
return ;
51
66
}
52
-
53
- return $ dao ->getValue ();
67
+ return $ settingDao ->getValue ();
54
68
}
55
69
56
- /** Set Configuration value. Set value as null to delete */
70
+ /** Set Configuration value. */
71
+
72
+ /**
73
+ * Set the value of a configuration setting given its name and module name.
74
+ * Set value to null to delete the configuration setting.
75
+ *
76
+ * @param string $name configuration setting name
77
+ * @param bool|int|float|string|void $value configuration setting value or
78
+ * null to delete the configuration setting
79
+ * @param string $module module name
80
+ * @return false|SettingDao configuration setting DAO or false if the
81
+ * configuration setting was deleted
82
+ * @throws Zend_Exception
83
+ */
57
84
public function setConfig ($ name , $ value , $ module = 'core ' )
58
85
{
59
86
if (!is_string ($ name )) {
60
- throw new Zend_Exception ('Setting name is not a string. ' );
87
+ throw new Zend_Exception ('Configuration setting name is not a string. ' );
61
88
}
62
89
if (!is_bool ($ value ) && !is_numeric ($ value ) && !is_string ($ value )) {
63
- throw new Zend_Exception ('Setting value is not a boolean, number, or string. ' );
90
+ throw new Zend_Exception ('Configuration setting value is not a boolean, number, or string. ' );
64
91
}
65
92
if (!is_string ($ module )) {
66
- throw new Zend_Exception ('Module name is not a string. ' );
93
+ throw new Zend_Exception ('Configuration setting module name is not a string. ' );
67
94
}
68
- $ dao = $ this ->getDaoByName ($ name , $ module );
69
- if ($ dao !== false && $ dao ->getValue () === $ value ) {
70
- return ;
71
- }
72
- if ($ dao !== false && $ value === null ) {
73
- $ this ->delete ($ dao );
74
- } elseif ($ dao !== false ) {
75
- $ dao ->setValue ($ value );
76
- $ this ->save ($ dao );
77
- } else {
78
- $ dao = $ this ->initDao ('Setting ' , array (
95
+ $ settingDao = $ this ->getDaoByName ($ name , $ module );
96
+ if ($ settingDao === false ) {
97
+ $ settingDao = $ this ->initDao ('Setting ' , array (
79
98
'name ' => $ name ,
80
99
'value ' => $ value ,
81
100
'module ' => $ module ,
82
101
));
83
- $ this ->save ($ dao );
102
+ $ this ->save ($ settingDao );
103
+ } elseif ($ value === null ) {
104
+ $ this ->delete ($ settingDao );
105
+ $ settingDao = false ;
106
+ } elseif ($ settingDao ->getValue () !== $ value ) {
107
+ $ settingDao ->setValue ($ value );
108
+ $ this ->save ($ settingDao );
84
109
}
85
-
86
- return $ dao ;
110
+ return $ settingDao ;
87
111
}
88
112
}
0 commit comments