Beispiel #1
0
 /**
  * Method to save the form data.
  *
  * @param   array  $data  The form data.
  *
  * @return  boolean  True on success, False on error.
  */
 public function save($data)
 {
     $result = parent::save($data);
     // Reorder
     if ($result && $this->state->get('order.position') == 'first') {
         $pk = $this->state->get($this->getName() . '.id');
         $this->reorder(array($pk), array(0));
         $this->state->set('order.position', null);
     }
     return $result;
 }
 /**
  * Prepare execute hook.
  *
  * @throws \UnexpectedValueException
  * @return void
  */
 protected function prepareExecute()
 {
     parent::prepareExecute();
     $this->user = $this->container->get('user');
     $this->lang = $this->container->get('language');
     $this->model = $this->getModel($this->viewItem);
     $this->table = $this->model->getTable($this->viewItem, $this->prefix . 'Table');
     // Determine model
     if (!$this->model instanceof CrudModel) {
         throw new \UnexpectedValueException(sprintf('%s model need extend to CrudModel', $this->name));
     }
     // Determine the name of the primary key for the data.
     if (empty($this->key)) {
         $this->key = $this->table->getKeyName();
     }
     // To avoid data collisions the urlVar may be different from the primary key.
     if (empty($this->urlVar)) {
         $this->urlVar = $this->key;
     }
 }
Beispiel #3
0
 /**
  * Method to allow derived classes to preprocess the form.
  *
  * @param   JForm   $form   A JForm object.
  * @param   mixed   $data   The data expected for the form.
  * @param   string  $group  The name of the plugin group to import (defaults to "content").
  *
  * @return  void
  *
  * @throws  Exception if there is an error in the form event.
  */
 protected function preprocessForm(JForm $form, $data, $group = 'content')
 {
     if (JComponentHelper::getParams('com_users')->get('frontend_userparams')) {
         $form->loadFile('frontend', false);
         if (JFactory::getUser()->authorise('core.login.admin')) {
             $form->loadFile('frontend_admin', false);
         }
     }
     parent::preprocessForm($form, $data, $group);
 }
Beispiel #4
0
 /**
  * getTable
  *
  * @param string $name
  * @param string $prefix
  * @param array  $options
  *
  * @return  JTable
  */
 public function getTable($name = 'User', $prefix = 'JTable', $options = array())
 {
     return parent::getTable($name, $prefix, $options);
 }
 /**
  * Method to test delete().
  *
  * @return void
  *
  * @covers Windwalker\Model\CrudModel::delete
  */
 public function testDelete()
 {
     $crudModel = new CrudModel(array('name' => 'CrudModel', 'prefix' => 'Stub', 'ignore_request' => true), $this->getContainerForSave());
     $id = 1;
     $originalData = $crudModel->getItem($id);
     // Execute method
     $crudModel->delete($id);
     // $id is pass by reference which will be cast into array
     $result = $crudModel->getItem($id[0]);
     $this->assertNull($result->id);
     $this->assertNull($result->foo);
     $this->assertNull($result->type);
     $this->assertEmpty($result->params);
 }