english/administrator/components/com_menus/models/item.php
/**
	 * Batch move menu items to a new menu or parent.
	 *
	 * @param	int		$value	The new menu 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 menu items to a new menu or parent.
@param       int             $value  The new menu 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 menu items to a new menu or parent . @param int $value The new menu 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)
	{
		$parts		= explode('.', $value);
		$menuType	= $parts[0];
		$parentId	= (int) JArrayHelper::getValue($parts, 1, 0);
		$table	= $this->getTable();
		$db		= $this->getDbo();
		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;
				}
			}
		}
		$user	= JFactory::getUser();
		if (!$user->authorise('core.create', 'com_menus')) {
			$this->setError(JText::_('COM_MENUS_BATCH_MENU_ITEM_CANNOT_CREATE'));
			return false;
		}
		if (!$user->authorise('core.edit', 'com_menus')) {
			$this->setError(JText::_('COM_MENUS_BATCH_MENU_ITEM_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');
			$table->parent_id = $parentId;
			if ($menuType != $table->menutype) {
				$db->setQuery(
					'SELECT `id`' .
					' FROM `#__menu`' .
					' WHERE `lft` BETWEEN '.(int) $table->lft.' AND '.(int) $table->rgt
				);
				$children = array_merge($children, (array) $db->loadResultArray());
			}
			if (!$table->check()) {
				$this->setError($table->getError());
				return false;
			}
			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);
			$db->setQuery(
				'UPDATE `#__menu`' .
				' SET `menutype` = '.$db->quote($menuType).
				' WHERE `id` IN ('.implode(',', $children).')'
				);
				$db->query();
				if ($db->getErrorNum()) {
					$this->setError($db->getErrorMsg());
					return false;
				}
		}
		$this->cleanCache();
		return true;
	}
protected function batchMove ( $ value , $ pks ) { $ parts = explode ( '.' , $ value ) ; $ menuType = $ parts [ 0 ] ; $ parentId = ( int ) JArrayHelper :: getValue ( $ parts , 1 , 0 ) ; $ table = $ this -> getTable ( ) ; $ db = $ this -> getDbo ( ) ; 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 ; } } } $ user = JFactory :: getUser ( ) ; if ( ! $ user -> authorise ( 'core.create' , 'com_menus' ) ) { $ this -> setError ( JText :: _ ( 'COM_MENUS_BATCH_MENU_ITEM_CANNOT_CREATE' ) ) ; return false ; } if ( ! $ user -> authorise ( 'core.edit' , 'com_menus' ) ) { $ this -> setError ( JText :: _ ( 'COM_MENUS_BATCH_MENU_ITEM_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' ) ; $ table -> parent_id = $ parentId ; if ( $ menuType != $ table -> menutype ) { $ db -> setQuery ( 'SELECT `id`' . ' FROM `#__menu`' . ' WHERE `lft` BETWEEN ' . ( int ) $ table -> lft . ' AND ' . ( int ) $ table -> rgt ) ; $ children = array_merge ( $ children , ( array ) $ db -> loadResultArray ( ) ) ; } if ( ! $ table -> check ( ) ) { $ this -> setError ( $ table -> getError ( ) ) ; return false ; } 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 ) ; $ db -> setQuery ( 'UPDATE `#__menu`' . ' SET `menutype` = ' . $ db -> quote ( $ menuType ) . ' WHERE `id` IN (' . implode ( ',' , $ children ) . ')' ) ; $ db -> query ( ) ; if ( $ db -> getErrorNum ( ) ) { $ this -> setError ( $ db -> getErrorMsg ( ) ) ; return false ; } } $ this -> cleanCache ( ) ; return true ; }
Batch move menu items to a new menu or parent.
Batch move menu items to a new menu or parent .
// $value comes as {menutype}.{parent_id} // Check that the parent exists. // Fatal error // Non-fatal error // Check that user has create and edit permission for menus // We are going to store all the children and just moved the menutype // 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. // Set the new Parent Id // Check if we are moving to a different menu // Add the child node ids to the children array. // Check the row. // Store the row. // Rebuild the tree path. // Process the child rows // Remove any duplicates and sanitize ids. // Update the menutype field in all nodes where necessary. // Check for a database error. // Clean the cache