english/administrator/components/com_categories/models/category.php
/**
	 * Batch move categories to a new category.
	 *
	 * @param	int		$value	The new category or sub-item.
	 * @param	array	$pks	An array of row IDs.
	 *
	 * @return	booelan	True if successful, false otherwise and internal error is set.
	 * @since	1.6
	 */
Batch move categories to a new category.
@param       int             $value  The new category or sub-item.
@param       array   $pks    An array of row IDs.

@return      booelan True if successful, false otherwise and internal error is set.
Batch move categories to a new category . @param int $value The new category or sub - item . @param array $pks An array of row IDs . @return booelan True if successful false otherwise and internal error is set .
protected function batchMove($value, $pks)
	{
		$parentId	= (int) $value;
		$table	= $this->getTable();
		$db		= $this->getDbo();
		$user	= JFactory::getUser();
		$extension = JRequest::getWord('extension');
		if ($parentId) {
			if (!$table->load($parentId)) {
				if ($error = $table->getError()) {
					$this->setError($error);
					return false;
				}
				else {
					$this->setError(JText::_('JGLOBAL_BATCH_MOVE_PARENT_NOT_FOUND'));
					$parentId = 0;
				}
			}
			$canCreate = ($parentId == $table->getRootId()) ? $user->authorise('core.create', $extension) :
				$user->authorise('core.create', $extension.'.category.'.$parentId);
			if (!$canCreate) {
				$this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_CREATE'));
				return false;
			}
			foreach ($pks as $pk) {
				if (!$user->authorise('core.edit', $extension.'.category.'.$pk)) {
					$this->setError(JText::_('COM_CATEGORIES_BATCH_CANNOT_EDIT'));
					return false;
				}
			}
		}
		$children = array();
		foreach ($pks as $pk)
		{
			if (!$table->load($pk)) {
				if ($error = $table->getError()) {
					$this->setError($error);
					return false;
				}
				else {
					$this->setError(JText::sprintf('JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND', $pk));
					continue;
				}
			}
			$table->setLocation($parentId, 'last-child');
			if ($parentId != $table->parent_id) {
				$db->setQuery(
					'SELECT `id`' .
					' FROM `#__categories`' .
					' WHERE `lft` BETWEEN '.(int) $table->lft.' AND '.(int) $table->rgt
				);
				$children = array_merge($children, (array) $db->loadResultArray());
			}
			if (!$table->store()) {
				$this->setError($table->getError());
				return false;
			}
			if (!$table->rebuildPath()) {
				$this->setError($table->getError());
				return false;
			}
		}
		if (!empty($children)) {
			$children = array_unique($children);
			JArrayHelper::toInteger($children);
			if ($db->getErrorNum()) {
				$this->setError($db->getErrorMsg());
				return false;
			}
		}
		return true;
	}
protected function batchMove ( $ value , $ pks ) { $ parentId = ( int ) $ value ; $ table = $ this -> getTable ( ) ; $ db = $ this -> getDbo ( ) ; $ user = JFactory :: getUser ( ) ; $ extension = JRequest :: getWord ( 'extension' ) ; if ( $ parentId ) { if ( ! $ table -> load ( $ parentId ) ) { if ( $ error = $ table -> getError ( ) ) { $ this -> setError ( $ error ) ; return false ; } else { $ this -> setError ( JText :: _ ( 'JGLOBAL_BATCH_MOVE_PARENT_NOT_FOUND' ) ) ; $ parentId = 0 ; } } $ canCreate = ( $ parentId == $ table -> getRootId ( ) ) ? $ user -> authorise ( 'core.create' , $ extension ) : $ user -> authorise ( 'core.create' , $ extension . '.category.' . $ parentId ) ; if ( ! $ canCreate ) { $ this -> setError ( JText :: _ ( 'COM_CATEGORIES_BATCH_CANNOT_CREATE' ) ) ; return false ; } foreach ( $ pks as $ pk ) { if ( ! $ user -> authorise ( 'core.edit' , $ extension . '.category.' . $ pk ) ) { $ this -> setError ( JText :: _ ( 'COM_CATEGORIES_BATCH_CANNOT_EDIT' ) ) ; return false ; } } } $ children = array ( ) ; foreach ( $ pks as $ pk ) { if ( ! $ table -> load ( $ pk ) ) { if ( $ error = $ table -> getError ( ) ) { $ this -> setError ( $ error ) ; return false ; } else { $ this -> setError ( JText :: sprintf ( 'JGLOBAL_BATCH_MOVE_ROW_NOT_FOUND' , $ pk ) ) ; continue ; } } $ table -> setLocation ( $ parentId , 'last-child' ) ; if ( $ parentId != $ table -> parent_id ) { $ db -> setQuery ( 'SELECT `id`' . ' FROM `#__categories`' . ' WHERE `lft` BETWEEN ' . ( int ) $ table -> lft . ' AND ' . ( int ) $ table -> rgt ) ; $ children = array_merge ( $ children , ( array ) $ db -> loadResultArray ( ) ) ; } if ( ! $ table -> store ( ) ) { $ this -> setError ( $ table -> getError ( ) ) ; return false ; } if ( ! $ table -> rebuildPath ( ) ) { $ this -> setError ( $ table -> getError ( ) ) ; return false ; } } if ( ! empty ( $ children ) ) { $ children = array_unique ( $ children ) ; JArrayHelper :: toInteger ( $ children ) ; if ( $ db -> getErrorNum ( ) ) { $ this -> setError ( $ db -> getErrorMsg ( ) ) ; return false ; } } return true ; }
Batch move categories to a new category.
Batch move categories to a new category .
// Check that the parent exists. // Fatal error // Non-fatal error // Check that user has create permission for parent category // Error since user cannot create in parent category // Check that user has edit permission for every category being moved // Note that the entire batch operation fails if any category lacks edit permission // Error since user cannot edit this category // We are going to store all the children and just move the category // Parent exists so we let's proceed // Check that the row actually exists // Fatal error // Not fatal error // Set the new location in the tree for the node. // Check if we are moving to a different parent // Add the child node ids to the children array. // Store the row. // Rebuild the tree path. // Process the child rows // Remove any duplicates and sanitize ids. // Check for a database error.