Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit 38f82f1

Browse files
author
Jamie Snape
committed
Add documentation and tidy setting model
1 parent ee615c9 commit 38f82f1

File tree

2 files changed

+55
-34
lines changed

2 files changed

+55
-34
lines changed

core/models/base/SettingModelBase.php

Lines changed: 50 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
require_once BASE_PATH.'/core/models/dao/SettingDao.php';
2222

23-
/** Setting Model Base */
23+
/** Configuration setting base model class. */
2424
abstract class SettingModelBase extends AppModel
2525
{
26-
/** Constructor */
26+
/** Constructor. */
2727
public function __construct()
2828
{
2929
parent::__construct();
@@ -39,50 +39,74 @@ public function __construct()
3939
$this->initialize(); // required
4040
}
4141

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+
*/
4350
abstract public function getDaoByName($name, $module = 'core');
4451

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+
*/
4661
public function getValueByName($name, $module = 'core')
4762
{
48-
$dao = $this->getDaoByName($name, $module);
49-
if ($dao === false) {
63+
$settingDao = $this->getDaoByName($name, $module);
64+
if ($settingDao === false) {
5065
return;
5166
}
52-
53-
return $dao->getValue();
67+
return $settingDao->getValue();
5468
}
5569

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+
*/
5784
public function setConfig($name, $value, $module = 'core')
5885
{
5986
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.');
6188
}
6289
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.');
6491
}
6592
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.');
6794
}
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(
7998
'name' => $name,
8099
'value' => $value,
81100
'module' => $module,
82101
));
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);
84109
}
85-
86-
return $dao;
110+
return $settingDao;
87111
}
88112
}

core/models/pdo/SettingModel.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,15 @@
2020

2121
require_once BASE_PATH.'/core/models/base/SettingModelBase.php';
2222

23-
/**
24-
* SettingModel
25-
* Pdo Model.
26-
*/
23+
/** Configuration setting model. */
2724
class SettingModel extends SettingModelBase
2825
{
2926
/**
30-
* Get by name.
27+
* Return a configuration setting given its name and module name.
3128
*
32-
* @param string $name
33-
* @param string $module
34-
* @return false|SettingDao
29+
* @param string $name configuration setting name
30+
* @param string $module module name
31+
* @return false|SettingDao configuration setting DAO or false on failure
3532
* @throws Zend_Exception
3633
*/
3734
public function getDaoByName($name, $module = 'core')

0 commit comments

Comments
 (0)