1
+ <?php
2
+ /*=========================================================================
3
+ MIDAS Server
4
+ Copyright (c) Kitware SAS. 20 rue de la Villette. All rights reserved.
5
+ 69328 Lyon, FRANCE.
6
+
7
+ See Copyright.txt for details.
8
+ This software is distributed WITHOUT ANY WARRANTY; without even
9
+ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10
+ PURPOSE. See the above copyright notices for more information.
11
+ =========================================================================*/
12
+ require_once BASE_PATH .'/core/models/dao/SettingDao.php ' ;
13
+
14
+ /** Setting Model Base*/
15
+ abstract class SettingModelBase extends AppModel
16
+ {
17
+ /** Constructor*/
18
+ public function __construct ()
19
+ {
20
+ parent ::__construct ();
21
+ $ this ->_name = 'setting ' ;
22
+ $ this ->_key = 'setting_id ' ;
23
+
24
+ $ this ->_mainData = array (
25
+ 'setting_id ' => array ('type ' => MIDAS_DATA ),
26
+ 'name ' => array ('type ' => MIDAS_DATA ),
27
+ 'module ' => array ('type ' => MIDAS_DATA ),
28
+ 'value ' => array ('type ' => MIDAS_DATA )
29
+ );
30
+ $ this ->initialize (); // required
31
+ } // end __construct()
32
+
33
+ /** Abstract functions */
34
+ abstract function getDaoByName ($ name , $ module = 'core ' );
35
+
36
+ /** get value by name */
37
+ public function getValueByName ($ name , $ module = 'core ' )
38
+ {
39
+ $ dao = $ this ->getDaoByName ($ name , $ module );
40
+ if ($ dao == false )
41
+ {
42
+ return null ;
43
+ }
44
+ return $ dao ->getValue ();
45
+ }
46
+
47
+ /** Set Configuration value. Set value as null to delete */
48
+ public function setConfig ($ name , $ value , $ module = 'core ' )
49
+ {
50
+ if (!is_string ($ name ) || !is_string ($ value ) || !is_string ($ module ))
51
+ {
52
+ throw new Zend_Exception ('Error Parameters ' );
53
+ }
54
+ $ dao = $ this ->getDaoByName ($ name , $ module );
55
+ if ($ dao != false && $ dao ->getValue () == $ value )
56
+ {
57
+ return ;
58
+ }
59
+ if ($ dao != false && $ value === null )
60
+ {
61
+ $ this ->delete ($ previousDao );
62
+ }
63
+ elseif ($ dao != false )
64
+ {
65
+ $ dao ->setValue ($ value );
66
+ $ this ->save ($ dao );
67
+ }
68
+ else
69
+ {
70
+ $ dao = new SettingDao ();
71
+ $ dao ->setName ($ name );
72
+ $ dao ->setModule ($ module );
73
+ $ dao ->setValue ($ value );
74
+ $ this ->save ($ dao );
75
+ }
76
+ return $ dao ;
77
+ }
78
+
79
+ } // end class AssetstoreModelBase
0 commit comments