Gentics Portal.Node PHP API
 All Classes Namespaces Functions Variables Pages
SettingsModule.php
1 <?php
2 /**
3  *
4  */
5 class SettingsModule extends CWebModule
6 {
7  /**
8  * @var array array of fields which will be available
9  * for editing via web interface and stored in DB.
10  * All other settings will be skipped
11  */
12  public $fields;
13 
14  public $layoutForBackend = '//layouts/gportal';
15  /**
16  * Model initial method
17  *
18  * @return void
19  */
20  public function init()
21  {
22  parent::init();
23  $this->setImport(
24  array(
25  'settings.models.*'
26  )
27  );
28  }
29 
30  /**
31  * Method for getting setting from DB
32  *
33  * @param string $name setting name
34  *
35  * @return mixed
36  */
37  public function get($name)
38  {
39  if (!in_array($name, $this->fields)) {
40  return false;
41  }
42  return Settings::instance()->get($name);
43  }
44 
45  /**
46  * Method for saving setting into DB
47  *
48  * @param string $name setting name
49  * @param mixed $value setting value
50  *
51  * @return bool if success
52  */
53  public function set($name, $value)
54  {
55  if (!in_array($name, $this->fields)) {
56  return false;
57  }
58  Settings::instance()->set($name, $value);
59  return true;
60  }
61 
62  /**
63  * Translates a message to the specified language.
64  *
65  * @param string $str message
66  * @param array $params params
67  * @param string $dic dictionary
68  *
69  * @return string
70  */
71  public static function t($str = '', $params = array(), $dic = 'core')
72  {
73  return Yii::t("SettingsModule." . $dic, $str, $params);
74  }
75 
76 }