예제 #1
0
 /**
  * prepareExecute
  *
  * @return  void
  */
 protected function prepareExecute()
 {
     parent::prepareExecute();
     $pks = (array) $this->pks;
     $this->record->load(array_shift($pks));
     $this->primary = (bool) $this->record->primary;
     $this->topic = $this->model->getRecord('Topic');
     $this->topic->load($this->record->topic_id);
 }
예제 #2
0
 /**
  * prepareExecute
  *
  * @return  void
  */
 protected function prepareExecute()
 {
     parent::prepareExecute();
     if (isset($this->pks)) {
         $this->id = $this->pks;
     }
     $this->parent = $this->model->getRecord('Category');
     $this->record->load($this->id);
     $this->parent->load($this->record->parent_id);
 }
예제 #3
0
 /**
  * Execute the controller.
  *
  * @throws \Exception
  * @return  mixed Return executed result.
  */
 public function execute()
 {
     $session = Ioc::getSession();
     $user = $this->input->getVar('user', array());
     $user = new Data($user);
     $user->id = User::get()->id;
     $user->username = User::get()->username;
     // Store Session
     $temp = clone $user;
     unset($temp->password);
     unset($temp->password2);
     $session->set('profile.edit.data', $temp);
     try {
         if (!$this->validate($user)) {
             return false;
         }
         $record = new Record('users');
         $record->load($user->id);
         $record->bind($user);
         $record->check()->store(true);
     } catch (ValidFailException $e) {
         $this->setRedirect(Router::buildHttp('admin:profile', ['id' => $user->id ?: '']), $e->getMessage(), 'danger');
         return true;
     } catch (\Exception $e) {
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::buildHttp('admin:profile', ['id' => $user->id ?: '']), 'Save fail', 'danger');
         return true;
     }
     // Save success, reset user session
     unset($user->password);
     unset($user->password2);
     $session->set('user', $user);
     $session->remove('profile.edit.data');
     $this->setRedirect(Router::buildHttp('admin:profile'), 'Save Success', 'success');
     return true;
 }
예제 #4
0
 protected function doExecute()
 {
     $data = $this->input->getVar('category');
     $data = new Data($data);
     $data['title'] = trim($data['title']);
     if (!$data['title']) {
         $this->setRedirect(Router::build('admin:categories'), 'Title should not be empty', 'danger');
         return false;
     }
     if (!$data['blog']) {
         $data['blog'] = Blog::get()->id;
     }
     $data['alias'] = OutputFilter::stringURLSafe(trim($data['title']));
     $data['alias'] = $data['alias'] ?: OutputFilter::stringURLSafe((string) new Date());
     $data['state'] = 1;
     if (!$data['ordering']) {
         $max = $this->getMaxOrder($data['blog']);
         $data['ordering'] = $max + 1;
     }
     try {
         $category = new Record('categories');
         if ($data['id']) {
             $category->load($data['id']);
         }
         $category->bind($data);
         $category->check();
         $category->store(true);
     } catch (\Exception $e) {
         if (WINDWALKER_DEBUG) {
             throw $e;
         }
         $this->setRedirect(Router::build('admin:categories'), 'Save Error', 'danger');
         return false;
     }
     $this->setRedirect(Router::build('admin:categories'), 'Create success', 'success');
     return true;
 }
예제 #5
0
 /**
  * Method to test store().
  *
  * @return void
  *
  * @covers Windwalker\Record\Record::store
  */
 public function testStore()
 {
     $data = array('title' => 'Lancelot', 'meaning' => 'First Knight');
     $record = new Record('ww_flower');
     $record->bind($data);
     $record->foo = 'Forbidden';
     $record->store();
     $record = new Record('ww_flower');
     $record->load(array('title' => 'Lancelot'));
     $this->assertEquals('First Knight', $record->meaning);
 }