Ejemplo n.º 1
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);
 }
Ejemplo n.º 2
0
 /**
  * save
  *
  * @param int|string $pk
  * @param Data       $data
  *
  * @return  void
  *
  * @throws ValidFailException
  */
 protected function save($pk, Data $data)
 {
     // Pre save
     if (!UserHelper::canDeletePost($this->record)) {
         throw new ValidFailException('Permission deny');
     }
     if ($this->primary) {
         $this->hmvc($controller = new TopicDeleteController(), array('cid' => $this->record->topic_id));
     } else {
         parent::save($pk, $data);
     }
     // Post save
     $this->topic->replies--;
     $this->topic->store();
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 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;
 }
Ejemplo n.º 5
0
 /**
  * postSaveHook
  *
  * @param Record $record
  *
  * @return  void
  */
 protected function postSaveHook(Record $record)
 {
     /** @var NestedRecord $record */
     $record->rebuild();
     $record->rebuildPath();
 }
Ejemplo n.º 6
0
 /**
  * postSaveHook
  *
  * @param NestedRecord|Record $record
  *
  * @return  void
  */
 protected function postSaveHook(Record $record)
 {
     $record->rebuildPath();
 }
Ejemplo n.º 7
0
 public function testHasField()
 {
     $record = new Record('ww_flower');
     $this->assertTrue($record->hasField('title'));
     $this->assertFalse($record->hasField('chicken'));
 }
Ejemplo n.º 8
0
 /**
  * Method to test bind().
  *
  * @return void
  *
  * @covers Windwalker\Record\Record::bind
  * @TODO   Implement testBind().
  */
 public function testBind()
 {
     $record = new Record('ww_flower');
     $record->bind(array('title' => 'sakura', 'fake' => 'cat'));
     $this->assertEquals('sakura', $record->title);
     $this->assertEquals(null, $record->fake);
 }
Ejemplo n.º 9
0
 /**
  * Method to set new item ordering as first or last.
  *
  * @param   Record $record    Item table to save.
  * @param   string $position `first` or other are `last`.
  *
  * @return  void
  */
 public function setOrderPosition(Record $record, $position = self::ORDER_POSITION_LAST)
 {
     $orderField = $this->state->get('order.column', 'ordering');
     if (!$record->hasField($orderField)) {
         return;
     }
     $position = $this->get('order.position', $position);
     if ($position == static::ORDER_POSITION_FIRST) {
         if (empty($record->{$orderField})) {
             $record->{$orderField} = 1;
             $this->state->set('order.position', static::ORDER_POSITION_FIRST);
         }
     } else {
         // Set ordering to the last item if not set
         if (empty($record->{$orderField})) {
             $query = $this->db->getQuery(true)->select(sprintf('MAX(%s)', $orderField))->from($record->getTableName());
             $condition = $this->getReorderConditions($record);
             // Condition should be an array.
             if (count($condition)) {
                 $query->where($this->getReorderConditions($record));
             }
             $max = $this->db->setQuery($query)->loadResult();
             $record->{$orderField} = $max + 1;
         }
     }
 }