示例#1
0
 /**
  * Get all options
  *
  * @param bool $force Force
  * @return array|mixed
  */
 public static function getAll($force = false)
 {
     if ($force === true || self::$_config['cache'] === false || self::$_config['cache'] === true && !Cache::read(self::$_config['cache_name'])) {
         $options = self::$_table->find('all');
         $optionsArray = [];
         foreach ($options as $v) {
             $value = $v->{self::$_config['column_value']};
             $setting = Settings::getSetting($v->{self::$_config['column_key']});
             if (!is_null($setting)) {
                 switch ($setting['type']) {
                     case 'boolean':
                         $value = boolval($value);
                         break;
                     case 'integer':
                         $value = intval($value);
                         break;
                     case 'float':
                         $value = floatval($value);
                         break;
                 }
             }
             $optionsArray[$v->{self::$_config['column_key']}] = $value;
         }
         if (self::$_config['cache'] === true) {
             Cache::write(self::$_config['cache_name'], $optionsArray, self::$_config['cache_config']);
         }
         return $optionsArray;
     }
     return Cache::read(self::$_config['cache_name']);
 }
示例#2
0
 public function setTab(string $id) : Setting
 {
     if (!Settings::tabIsRegistered($id)) {
         throw new \Exception('The tab ' . $id . ' does not exist.');
     }
     $this->tab = $id;
     return $this;
 }
示例#3
0
 public function init($event)
 {
     Sidebar::addItem('settings', __('Paramètres'), ['_name' => 'settings', 'tab' => 'general'], 'fa fa-cogs', 15);
     $general = (new SettingsTab('general'))->setName(__('Général'))->setPosition(1);
     Settings::registerTab($general);
     $name = (new Setting('name'))->setType('varchar')->setTab('general')->setEditable(true)->setAttributes(['label' => __('Titre du site')]);
     $slogan = (new Setting('slogan'))->setType('varchar')->setTab('general')->setEditable(true)->setAttributes(['label' => __('Slogan')]);
     $debug = (new Setting('debug'))->setType('boolean')->setTab('general')->setEditable(true)->setAttributes(['label' => __('Mode débogage')]);
     Settings::registerSetting($name);
     Settings::registerSetting($slogan);
     Settings::registerSetting($debug);
 }
示例#4
0
 public function settings($tab)
 {
     $settings = null;
     try {
         $settings = Settings::getAll($tab);
     } catch (\Exception $e) {
         $settings = Settings::getAll('general');
     }
     /* @var $form \Cake\Form\Form */
     $form = $settings->form;
     /* @var $validator \Cake\Validation\Validator */
     $validator = $settings->validator;
     $data = [];
     /* @var $v \ThreeCMS\Core\Settings\Setting */
     foreach ($settings->settings as $v) {
         $data[$v->getKey()] = SettingsData::get($v->getKey());
     }
     if ($this->request->is(['post', 'put'])) {
         $form->validator($validator);
         $form->validate($this->request->data);
         if (!$form->errors()) {
             try {
                 foreach ($this->request->data as $k => $v) {
                     if ($data[$k] != $v) {
                         SettingsData::set($k, $v);
                     }
                 }
             } catch (\Exception $e) {
                 $this->Flash->error(__('Veuillez réessayer.'));
             }
             $this->Flash->success(__('Paramètres enregistrés avec succès !'));
         } else {
             $this->Flash->error(__('Veuillez vérifier les données saisies !'));
         }
     } else {
         $this->request->data = $data;
     }
     $this->set(compact('settings', 'form'));
     $this->setTitle(__('Paramètres'));
 }