コード例 #1
0
	/**
	 * Test for the JDatabaseDriver::__call method.
	 *
	 * @return  void
	 *
	 * @since   12.1
	 */
	public function test__callQuoteName()
	{
		$this->assertThat(
			$this->db->qn('foo'),
			$this->equalTo($this->db->quoteName('foo')),
			'Tests the qn alias of quoteName.'
		);
	}
コード例 #2
0
 /**
  * Method to provide a shortcut to binding, checking and storing a FOFTable
  * instance to the database table.  The method will check a row in once the
  * data has been stored and if an ordering filter is present will attempt to
  * reorder the table rows based on the filter.  The ordering filter is an instance
  * property name.  The rows that will be reordered are those whose value matches
  * the FOFTable instance for the property specified.
  *
  * @param   mixed   $src             An associative array or object to bind to the FOFTable instance.
  * @param   string  $orderingFilter  Filter for the order updating
  * @param   mixed   $ignore          An optional array or space separated list of properties
  *                                   to ignore while binding.
  *
  * @return  boolean  True on success.
  */
 public function save($src, $orderingFilter = '', $ignore = '')
 {
     // Attempt to bind the source to the instance.
     if (!$this->bind($src, $ignore)) {
         return false;
     }
     // Run any sanity checks on the instance and verify that it is ready for storage.
     if (!$this->check()) {
         return false;
     }
     // Attempt to store the properties to the database table.
     if (!$this->store()) {
         return false;
     }
     // Attempt to check the row in, just in case it was checked out.
     if (!$this->checkin()) {
         return false;
     }
     // If an ordering filter is set, attempt reorder the rows in the table based on the filter and value.
     if ($orderingFilter) {
         $filterValue = $this->{$orderingFilter};
         $this->reorder($orderingFilter ? $this->_db->qn($orderingFilter) . ' = ' . $this->_db->q($filterValue) : '');
     }
     // Set the error to empty and return true.
     $this->setError('');
     return true;
 }
コード例 #3
0
ファイル: map.php プロジェクト: giabmf11/Kunena-Forum
 /**
  * Method to store mapped rows in the database from the JTable instance properties.
  *
  * @param   array    $filter  Touch only these filtered items.
  *
  * @return  boolean  True on success.
  *
  * @link    http://docs.joomla.org/JTable/store
  * @throws  UnexpectedValueException
  */
 public function store(array $filter = null)
 {
     $k = $this->_tbl_key;
     $m = $this->_tbl_mapped;
     if (0 == $this->{$k}) {
         throw new UnexpectedValueException(sprintf('No key specified: %s.', get_class($this)));
     }
     $id = $this->{$k};
     $items = $this->{$m};
     if (!empty($items)) {
         // Load currently mapped variables from database.
         $this->load();
         $filtered = !is_null($filter) ? array_intersect($this->{$m}, $filter) : $this->{$m};
         // Calculate difference (added and deleted items).
         $added = array_diff($items, $filtered);
         $deleted = array_diff($filtered, $items);
         // Create all added items.
         if ($added) {
             $values = array();
             foreach ($added as $var) {
                 $values[] = (int) $id . ',' . (int) $var;
             }
             $query = $this->_db->getQuery(true);
             $query->insert($this->_db->qn($this->_tbl));
             $query->columns(array($this->_db->qn($this->_tbl_key), $this->_db->qn($this->_tbl_mapped)));
             $query->values($values);
             $this->_db->setQuery($query);
             $this->_db->execute();
         }
         // Remove all deleted items.
         if ($deleted) {
             $query = $this->_db->getQuery(true);
             $query->delete($this->_db->qn($this->_tbl));
             $query->where($this->_db->qn($this->_tbl_key) . '=' . (int) $id);
             $query->where($this->_db->qn($this->_tbl_mapped) . ' IN (' . implode(',', $deleted) . ')');
             $this->_db->setQuery($query);
             $this->_db->execute();
         }
     } else {
         $this->delete();
     }
     $this->{$m} = $items;
     if ($this->_locked) {
         $this->_unlock();
     }
     return true;
 }
コード例 #4
0
ファイル: table.php プロジェクト: deenison/joomla-cms
 /**
  * Method to get the next ordering value for a group of rows defined by an SQL WHERE clause.
  * This is useful for placing a new item last in a group of items in the table.
  *
  * @param   string  $where  WHERE clause to use for selecting the MAX(ordering) for the table.
  *
  * @return  mixed  Boolean false an failure or the next ordering value as an integer.
  */
 public function getNextOrder($where = '')
 {
     // If there is no ordering field set an error and return false.
     $ordering = $this->getColumnAlias('ordering');
     if (!in_array($ordering, $this->getKnownFields())) {
         throw new UnexpectedValueException(sprintf('%s does not support ordering.', get_class($this)));
     }
     // Get the largest ordering value for a given where clause.
     $query = $this->_db->getQuery(true);
     $query->select('MAX(' . $this->_db->qn($ordering) . ')');
     $query->from($this->_tbl);
     if ($where) {
         $query->where($where);
     }
     $this->_db->setQuery($query);
     $max = (int) $this->_db->loadResult();
     // Return the largest ordering value + 1.
     return $max + 1;
 }