| 1 |
<?php |
| 2 |
/** |
| 3 |
* |
| 4 |
*/ |
| 5 |
|
| 6 |
/** |
| 7 |
* |
| 8 |
*/ |
| 9 |
class CJTSettingsModel { |
| 10 |
|
| 11 |
/** |
| 12 |
* |
| 13 |
*/ |
| 14 |
const SETTINGS_PAGE_DIR = 'settings'; |
| 15 |
|
| 16 |
/** |
| 17 |
* put your comment there... |
| 18 |
* |
| 19 |
* @var mixed |
| 20 |
*/ |
| 21 |
protected $settingsPagesDir = self::SETTINGS_PAGE_DIR; |
| 22 |
|
| 23 |
/** |
| 24 |
* put your comment there... |
| 25 |
* |
| 26 |
* @param mixed $page |
| 27 |
*/ |
| 28 |
public function loadPage($name) { |
| 29 |
// Settings page file name. |
| 30 |
$pageFile = "{$name}.php"; |
| 31 |
require_once "{$this->settingsPagesDir}/{$pageFile}"; |
| 32 |
// Create settings page object. |
| 33 |
$name = str_replace(array('-', '_'), '', ucwords($name)); |
| 34 |
$className = "CJTSettings{$name}Page"; |
| 35 |
return new $className(); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* put your comment there... |
| 40 |
* |
| 41 |
* @param mixed $settings |
| 42 |
*/ |
| 43 |
public function save($settings) { |
| 44 |
// Each element represent a single settings page. |
| 45 |
foreach ($settings as $page => $data) { |
| 46 |
// Get page object. |
| 47 |
$pObject = $this->loadPage($page); |
| 48 |
// Update page settings. |
| 49 |
$pObject->set($data); |
| 50 |
// Save into the database. |
| 51 |
$pObject->update(); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
} // End class. |
| 56 |
|