english/administrator/components/com_users/models/user.php
/**
	 * Perform batch operations
	 *
	 * @param	array	$config		An array of variable for the batch operation
	 * @param	array	$user_ids	An array of IDs on which to operate
	 * @since	1.6
	 */
Perform batch operations
@param       array   $config         An array of variable for the batch operation
@param       array   $user_ids       An array of IDs on which to operate
@since       1.6
Perform batch operations @param array $config An array of variable for the batch operation @param array $user_ids An array of IDs on which to operate @since 1 . 6
public function batch($config, $user_ids)
	{
		if (empty($user_ids)) {
			$this->setError(JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
			return false;
		}
		else if (!empty($config)) {
			$group_id = JArrayHelper::getValue($config, 'group_id', 0, 'int');
			JArrayHelper::toInteger($user_ids);
			if ($group_id < 1) {
				$this->setError(JText::_('COM_USERS_ERROR_INVALID_GROUP'));
				return false;
			}
			$acl = JFactory::getACL();
			$oldAclMode = $acl->setCheckMode(1);
			$groupLogic	= JArrayHelper::getValue($config, 'group_logic');
			switch ($groupLogic)
			{
				case 'set':
					$doDelete		= 2;
					$doAssign		= true;
					break;
				case 'del':
					$doDelete		= true;
					$doAssign		= false;
					break;
				case 'add':
				default:
					$doDelete		= false;
					$doAssign		= true;
					break;
			}
			if ($doDelete) {
				if ($doDelete === 2) {
					$this->_db->setQuery(
						'DELETE FROM `#__user_usergroup_map`' .
						' WHERE `user_id` IN ('.implode(',', $user_ids).')'
					);
				}
				else {
					$this->_db->setQuery(
						'DELETE FROM `#__user_usergroup_map`' .
						' WHERE `user_id` IN ('.implode(',', $user_ids).')' .
						' AND `group_id` = '.$group_id
					);
				}
				if (!$this->_db->query()) {
					$this->setError($this->_db->getErrorMsg());
					return false;
				}
			}
			if ($doAssign) {
				$tuples = array();
				foreach ($user_ids as $id)
				{
					$tuples[] = '('.$id.','.$group_id.')';
				}
				$this->_db->setQuery(
					'INSERT IGNORE INTO `#__user_usergroup_map` (`user_id`, `group_id`)' .
					' VALUES '.implode(',', $tuples)
				);
				if (!$this->_db->query()) {
					$this->setError($this->_db->getErrorMsg());
					return false;
				}
			}
			$acl->setCheckMode($oldAclMode);
		}
		return true;
	}
public function batch ( $ config , $ user_ids ) { if ( empty ( $ user_ids ) ) { $ this -> setError ( JText :: _ ( 'COM_USERS_USERS_NO_ITEM_SELECTED' ) ) ; return false ; } else if ( ! empty ( $ config ) ) { $ group_id = JArrayHelper :: getValue ( $ config , 'group_id' , 0 , 'int' ) ; JArrayHelper :: toInteger ( $ user_ids ) ; if ( $ group_id < 1 ) { $ this -> setError ( JText :: _ ( 'COM_USERS_ERROR_INVALID_GROUP' ) ) ; return false ; } $ acl = JFactory :: getACL ( ) ; $ oldAclMode = $ acl -> setCheckMode ( 1 ) ; $ groupLogic = JArrayHelper :: getValue ( $ config , 'group_logic' ) ; switch ( $ groupLogic ) { case 'set' : $ doDelete = 2 ; $ doAssign = true ; break ; case 'del' : $ doDelete = true ; $ doAssign = false ; break ; case 'add' : default : $ doDelete = false ; $ doAssign = true ; break ; } if ( $ doDelete ) { if ( $ doDelete === 2 ) { $ this -> _db -> setQuery ( 'DELETE FROM `#__user_usergroup_map`' . ' WHERE `user_id` IN (' . implode ( ',' , $ user_ids ) . ')' ) ; } else { $ this -> _db -> setQuery ( 'DELETE FROM `#__user_usergroup_map`' . ' WHERE `user_id` IN (' . implode ( ',' , $ user_ids ) . ')' . ' AND `group_id` = ' . $ group_id ) ; } if ( ! $ this -> _db -> query ( ) ) { $ this -> setError ( $ this -> _db -> getErrorMsg ( ) ) ; return false ; } } if ( $ doAssign ) { $ tuples = array ( ) ; foreach ( $ user_ids as $ id ) { $ tuples [ ] = '(' . $ id . ',' . $ group_id . ')' ; } $ this -> _db -> setQuery ( 'INSERT IGNORE INTO `#__user_usergroup_map` (`user_id`, `group_id`)' . ' VALUES ' . implode ( ',' , $ tuples ) ) ; if ( ! $ this -> _db -> query ( ) ) { $ this -> setError ( $ this -> _db -> getErrorMsg ( ) ) ; return false ; } } $ acl -> setCheckMode ( $ oldAclMode ) ; } return true ; }
Perform batch operations
 @param       array   $config         An array of variable for the batch operation
 @param       array   $user_ids       An array of IDs on which to operate
 @since       1.6
Perform batch operations @param array $config An array of variable for the batch operation @param array $user_ids An array of IDs on which to operate @since 1 . 6
// Ensure there are selected users to operate on. // Only run operations if a config array is present. // Ensure there is a valid group. // Get the system ACL object and set the mode to database driven. // Remove the users from the group(s) if requested. // Purge operation, remove the users from all groups. // Remove the users from the group. // Check for database errors. // Assign the users to the group if requested. // Build the tuples array for the assignment query. // Check for database errors. // Set the ACL mode back to it's previous state.