コード例 #1
0
 public function settingAction()
 {
     $settingModel = Core_Model::factory('System_Model_Setting');
     $options = array();
     $settings = $settingModel->find_many();
     foreach ($settings as $setting) {
         $options[$setting->name] = trim($setting->value);
     }
     if ($this->isPost()) {
         $sql = array();
         $params = array();
         $options = array_merge($options, $this->_request['params']);
         // Update settings
         $sql[] = 'UPDATE ' . $settingModel->getTableName() . ' SET value = CASE';
         foreach (array_keys($options) as $key) {
             $sql[] = " WHEN name='{$key}' THEN :{$key}";
             $params["{$key}"] = trim($this->_request['params'][$key]);
         }
         $sql[] = ' END';
         $settingModel->raw_execute(implode('', $sql), $params);
         // Write cache
         $this->_cache['db']->save($options, 'db_settings');
         $this->view->success = 'Change settings successfully';
     }
     $this->view->options = $options;
 }
コード例 #2
0
 public function init()
 {
     parent::init();
     $this->postModel = Core_Model::factory('Post_Model_Post');
     // Get all categories
     $categoryModel = Core_Model::factory('Category_Model_Category');
     $this->view->subcategories = array_filter($categoryModel->find_many(), create_function('$obj', 'return $obj->id_parent != 0;'));
 }
コード例 #3
0
ファイル: Auth.php プロジェクト: 2eye-studios/development
 public static function checkAuth($username, $password)
 {
     $userModel = Core_Model::factory('User_Model_User');
     $user = $userModel->where_equal('username', $username)->find_one();
     if ($user) {
         return $user->password == sha1($user->salt . $password) ? $user : false;
     }
     return false;
 }
コード例 #4
0
 public function deleteAction()
 {
     if ($this->isAjax() && $this->isPost()) {
         $this->_noRender = true;
         $params = $this->_request['params'];
         $postModel = Core_Model::factory('Post_Model_Post');
         if ($postModel->where_raw('(`id_category` = ? OR `id_subcategory` = ?)', array($params['id'], $params['id']))->find_one()) {
             echo json_encode(array('success' => true, 'redirect' => false, 'msg' => 'This category is associated with some posts'));
         } else {
             $subCategories = array_filter($this->view->categories, create_function('$obj', 'return $obj->id_parent == ' . (int) $params['id'] . ';'));
             // Update parent of subcategories
             if ($subCategories) {
                 foreach ($subCategories as $category) {
                     $category->id_parent = 0;
                     $category->save();
                 }
             }
             $this->categoryModel->find_one($params['id'])->delete();
             echo json_encode(array('success' => true, 'redirect' => true, 'href' => $this->_router->generate('route_admin_category')));
         }
     }
 }