コード例 #1
0
 /**
  * Method to test store().
  *
  * @return void
  *
  * @covers Windwalker\Table\Table::store
  */
 public function testStore()
 {
     $tableName = '#__test_table2';
     $table = new Table($tableName);
     $table->bar = 'foo';
     $table->params = array('foo' => 'bar');
     $table->store();
     $this->assertEquals('{"foo":"bar"}', $table->params);
 }
コード例 #2
0
 /**
  * onBeforeDelete
  *
  * @param mixed $pk
  *
  * @return  void
  */
 public function onBeforeDelete($pk)
 {
     if ($this->table instanceof Table) {
         $this->tableClone = clone $this->table;
         $this->tableClone->load($pk);
     }
 }
コード例 #3
0
 public function testGlobalRelationConfig()
 {
     /** @var RelationContainer $relations */
     $relations = Container::getInstance()->get('relation.container');
     $relation = $relations->getRelation(static::TABLE_LOCATIONS);
     $relation->addOneToMany('sakuras', new StubTableSakura(), array('id' => 'location'));
     $relation->addOneToMany('roses', new StubTableRose(), array('id' => 'location'));
     $location = new Table(static::TABLE_LOCATIONS, 'id', \JFactory::getDbo());
     $location->load(3);
     $sakuras = $location->sakuras;
     $roses = $location->roses;
     $this->assertInstanceOf('Windwalker\\Data\\Data', $sakuras[0]);
     $this->assertInstanceOf('Windwalker\\Data\\DataSet', $sakuras);
     $this->assertInstanceOf('Windwalker\\Data\\DataSet', $roses);
     $this->assertEquals(array(11, 12, 13, 14, 15), $sakuras->id);
     $this->assertEquals(array(11, 12, 13, 14, 15), $roses->id);
     $relations->setRelation(static::TABLE_LOCATIONS, new Relation());
 }
コード例 #4
0
 /**
  * Get Table object by string name and prefix.
  *
  * @param   string  $table   The table name.
  * @param   string  $prefix  The table class prefix.
  *
  * @return  \JTable  Found table.
  */
 protected function getTable($table, $prefix = null)
 {
     if (!is_string($table)) {
         throw new \InvalidArgumentException('Table name should be string.');
     }
     if ($table = \JTable::getInstance($table, $prefix ?: $this->prefix)) {
         return $table;
     }
     return new Table($table, 'id', $this->parent->getDbo());
 }
コード例 #5
0
 /**
  * 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;
     }
 }
コード例 #6
0
 /**
  * Class init.
  *
  * @param \JDatabaseDriver $db
  */
 public function __construct($db = null)
 {
     parent::__construct('#__testflower_roses', 'id', $db);
 }
コード例 #7
0
 /**
  * Method to delete a row from the database table by primary key value.
  *
  * @param   mixed  $pk  An optional primary key value to delete.  If not set the instance property value is used.
  *
  * @return  boolean  True on success.
  *
  * @throws  UnexpectedValueException
  */
 public function delete($pk = null)
 {
     return parent::delete($pk);
 }
コード例 #8
0
 /**
  * Constructor
  */
 public function __construct()
 {
     parent::__construct('#__test_table');
 }
コード例 #9
0
 /**
  * Class init.
  *
  * @param \JDatabaseDriver $db
  */
 public function __construct($db = null)
 {
     parent::__construct('#__testflower_location_data', 'id', $db);
 }