public function reorder($where = '')
	{
		// If there is no ordering field set an error and return false.
		if (!property_exists($this, 'ordering'))
		{
			$e = new Exception(Lang::txt('JLIB_DATABASE_ERROR_CLASS_DOES_NOT_SUPPORT_ORDERING', get_class($this)));
			$this->setError($e);
			return false;
		}

		// Initialise variables.
		$k = $this->_tbl_key;

		// Get the primary keys and ordering values for the selection.
		$query = $this->_db->getQuery();
		$query->select($this->_tbl_key);
		$query->select('ordering');
		$query->from($this->_tbl);
		$query->where('ordering', '>=', '0');
		$query->order('ordering', 'asc');

		// Setup the extra where and ordering clause data.
		if ($where)
		{
			$query->whereRaw($where);
		}

		$this->_db->setQuery($query->toString());
		$rows = $this->_db->loadObjectList();

		// Check for a database error.
		if ($this->_db->getErrorNum())
		{
			$e = new Exception(Lang::txt('JLIB_DATABASE_ERROR_REORDER_FAILED', get_class($this), $this->_db->getErrorMsg()));
			$this->setError($e);

			return false;
		}

		// Compact the ordering values.
		foreach ($rows as $i => $row)
		{
			// Make sure the ordering is a positive integer.
			if ($row->ordering >= 0)
			{
				// Only update rows that are necessary.
				if ($row->ordering != $i + 1)
				{
					// Update the row ordering field.
					$query = $this->_db->getQuery();
					$query->update($this->_tbl);
					$query->set(array(
						'ordering' => ($i + 1)
					));
					$query->whereEquals($this->_tbl_key, $row->$k);
					$this->_db->setQuery($query->toString());

					// Check for a database error.
					if (!$this->_db->execute())
					{
						$e = new Exception(
							Lang::txt('JLIB_DATABASE_ERROR_REORDER_UPDATE_ROW_FAILED', get_class($this), $i, $this->_db->getErrorMsg())
						);
						$this->setError($e);

						return false;
					}
				}
			}
		}

		return true;
	}
public function reorder($where = '')
	{
		// If there is no ordering field set an error and return false.
		if (!property_exists($this, 'ordering'))
		{
			$e = new Exception(Lang::txt('JLIB_DATABASE_ERROR_CLASS_DOES_NOT_SUPPORT_ORDERING', get_class($this)));
			$this->setError($e);
			return false;
		}

		// Initialise variables.
		$k = $this->_tbl_key;

		// Get the primary keys and ordering values for the selection.
		$query = $this->_db->getQuery();
		$query->select($this->_tbl_key);
		$query->select('ordering');
		$query->from($this->_tbl);
		$query->where('ordering', '>=', '0');
		$query->order('ordering', 'asc');

		// Setup the extra where and ordering clause data.
		if ($where)
		{
			$query->whereRaw($where);
		}

		$this->_db->setQuery($query->toString());
		$rows = $this->_db->loadObjectList();

		// Check for a database error.
		if ($this->_db->getErrorNum())
		{
			$e = new Exception(Lang::txt('JLIB_DATABASE_ERROR_REORDER_FAILED', get_class($this), $this->_db->getErrorMsg()));
			$this->setError($e);

			return false;
		}

		// Compact the ordering values.
		foreach ($rows as $i => $row)
		{
			// Make sure the ordering is a positive integer.
			if ($row->ordering >= 0)
			{
				// Only update rows that are necessary.
				if ($row->ordering != $i + 1)
				{
					// Update the row ordering field.
					$query = $this->_db->getQuery();
					$query->update($this->_tbl);
					$query->set(array(
						'ordering' => ($i + 1)
					));
					$query->whereEquals($this->_tbl_key, $row->$k);
					$this->_db->setQuery($query->toString());

					// Check for a database error.
					if (!$this->_db->execute())
					{
						$e = new Exception(
							Lang::txt('JLIB_DATABASE_ERROR_REORDER_UPDATE_ROW_FAILED', get_class($this), $i, $this->_db->getErrorMsg())
						);
						$this->setError($e);

						return false;
					}
				}
			}
		}

		return true;
	}
public function reorder ( $ where = '' ) { // If there is no ordering field set an error and return false. if ( ! property_exists ( $ this , 'ordering' ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_CLASS_DOES_NOT_SUPPORT_ORDERING' , get_class ( $ this ) ) ) ; $ this -> setError ( $ e ) ; return false ; } // Initialise variables. $ k = $ this -> _tbl_key ; // Get the primary keys and ordering values for the selection. $ query = $ this -> _db -> getQuery ( ) ; $ query -> select ( $ this -> _tbl_key ) ; $ query -> select ( 'ordering' ) ; $ query -> from ( $ this -> _tbl ) ; $ query -> where ( 'ordering' , '>=' , '0' ) ; $ query -> order ( 'ordering' , 'asc' ) ; // Setup the extra where and ordering clause data. if ( $ where ) { $ query -> whereRaw ( $ where ) ; } $ this -> _db -> setQuery ( $ query -> toString ( ) ) ; $ rows = $ this -> _db -> loadObjectList ( ) ; // Check for a database error. if ( $ this -> _db -> getErrorNum ( ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_REORDER_FAILED' , get_class ( $ this ) , $ this -> _db -> getErrorMsg ( ) ) ) ; $ this -> setError ( $ e ) ; return false ; } // Compact the ordering values. foreach ( $ rows as $ i => $ row ) { // Make sure the ordering is a positive integer. if ( $ row -> ordering >= 0 ) { // Only update rows that are necessary. if ( $ row -> ordering != $ i + 1 ) { // Update the row ordering field. $ query = $ this -> _db -> getQuery ( ) ; $ query -> update ( $ this -> _tbl ) ; $ query -> set ( array ( 'ordering' => ( $ i + 1 ) ) ) ; $ query -> whereEquals ( $ this -> _tbl_key , $ row -> $ k ) ; $ this -> _db -> setQuery ( $ query -> toString ( ) ) ; // Check for a database error. if ( ! $ this -> _db -> execute ( ) ) { $ e = new Exception ( Lang :: txt ( 'JLIB_DATABASE_ERROR_REORDER_UPDATE_ROW_FAILED' , get_class ( $ this ) , $ i , $ this -> _db -> getErrorMsg ( ) ) ) ; $ this -> setError ( $ e ) ; return false ; } } } } return true ; }
Method to compact the ordering values of rows in a group of rows
defined by an SQL WHERE clause.

@param   string  $where  WHERE clause to use for limiting the selection of rows to compact the ordering values.
@return  mixed   Boolean true on success.
@since   2.1.12
Method to compact the ordering values of rows in a group of rows defined by an SQL WHERE clause .