english/libraries/joomla/database/table/user.php
/**
	 * Method to store a row in the database from the JTable instance properties.
	 * If a primary key value is set the row with that primary key value will be
	 * updated with the instance property values.  If no primary key value is set
	 * a new row will be inserted into the database with the properties from the
	 * JTable instance.
	 *
	 * @param   boolean  $updateNulls  True to update fields even if they are null.
	 *
	 * @return  boolean  True on success.
	 *
	 * @link    http://docs.joomla.org/JTable/store
	 * @since   11.1
	 */
Method to store a row in the database from the JTable instance properties.
If a primary key value is set the row with that primary key value will be
updated with the instance property values.  If no primary key value is set
a new row will be inserted into the database with the properties from the
JTable instance.

@param   boolean  $updateNulls  True to update fields even if they are null.

@return  boolean  True on success.


Method to store a row in the database from the JTable instance properties . If a primary key value is set the row with that primary key value will be updated with the instance property values . If no primary key value is set a new row will be inserted into the database with the properties from the JTable instance . @param boolean $updateNulls True to update fields even if they are null . @return boolean True on success .
function store($updateNulls = false)
	{
		$k = $this->_tbl_key;
		$key =  $this->$k;
		$groups = $this->groups;
		unset($this->groups);
		if ($key) {
			$return = $this->_db->updateObject($this->_tbl, $this, $this->_tbl_key, $updateNulls);
		}
		else {
			$return = $this->_db->insertObject($this->_tbl, $this, $this->_tbl_key);
		}
		if (!$return)
		{
			$this->setError(JText::sprintf('JLIB_DATABASE_ERROR_STORE_FAILED', strtolower(get_class($this)), $this->_db->getErrorMsg()));
			return false;
		}
		$this->groups = $groups;
		unset($groups);
		if ($return && is_array($this->groups) && count($this->groups))
		{
			$this->_db->setQuery(
				'DELETE FROM '.$this->_db->quoteName('#__user_usergroup_map') .
				' WHERE '.$this->_db->quoteName('user_id').' = '.(int) $this->id
			);
			$this->_db->query();
			if ($this->_db->getErrorNum()) {
				$this->setError($this->_db->getErrorMsg());
				return false;
			}
			$this->_db->setQuery(
				'INSERT INTO '.$this->_db->quoteName('#__user_usergroup_map').' ('.$this->_db->quoteName('user_id').', '.$this->_db->quoteName('group_id').')' .
				' VALUES ('.$this->id.', '.implode('), ('.$this->id.', ', $this->groups).')'
			);
			$this->_db->query();
			if ($this->_db->getErrorNum()) {
				$this->setError($this->_db->getErrorMsg());
				return false;
			}
		}
		return true;
	}
function store ( $ updateNulls = false ) { $ k = $ this -> _tbl_key ; $ key = $ this -> $ k ; $ groups = $ this -> groups ; unset ( $ this -> groups ) ; if ( $ key ) { $ return = $ this -> _db -> updateObject ( $ this -> _tbl , $ this , $ this -> _tbl_key , $ updateNulls ) ; } else { $ return = $ this -> _db -> insertObject ( $ this -> _tbl , $ this , $ this -> _tbl_key ) ; } if ( ! $ return ) { $ this -> setError ( JText :: sprintf ( 'JLIB_DATABASE_ERROR_STORE_FAILED' , strtolower ( get_class ( $ this ) ) , $ this -> _db -> getErrorMsg ( ) ) ) ; return false ; } $ this -> groups = $ groups ; unset ( $ groups ) ; if ( $ return && is_array ( $ this -> groups ) && count ( $ this -> groups ) ) { $ this -> _db -> setQuery ( 'DELETE FROM ' . $ this -> _db -> quoteName ( '#__user_usergroup_map' ) . ' WHERE ' . $ this -> _db -> quoteName ( 'user_id' ) . ' = ' . ( int ) $ this -> id ) ; $ this -> _db -> query ( ) ; if ( $ this -> _db -> getErrorNum ( ) ) { $ this -> setError ( $ this -> _db -> getErrorMsg ( ) ) ; return false ; } $ this -> _db -> setQuery ( 'INSERT INTO ' . $ this -> _db -> quoteName ( '#__user_usergroup_map' ) . ' (' . $ this -> _db -> quoteName ( 'user_id' ) . ', ' . $ this -> _db -> quoteName ( 'group_id' ) . ')' . ' VALUES (' . $ this -> id . ', ' . implode ( '), (' . $ this -> id . ', ' , $ this -> groups ) . ')' ) ; $ this -> _db -> query ( ) ; if ( $ this -> _db -> getErrorNum ( ) ) { $ this -> setError ( $ this -> _db -> getErrorMsg ( ) ) ; return false ; } } return true ; }
Method to store a row in the database from the JTable instance properties.
Method to store a row in the database from the JTable instance properties .
// Get the table key and key value. // TODO: This is a dumb way to handle the groups. // Store groups locally so as to not update directly. // Insert or update the object based on presence of a key value. // Already have a table key, update the row. // Don't have a table key, insert the row. // Handle error if it exists. // Reset groups to the local object. // Store the group data if the user data was saved. // Delete the old user group maps. // Check for a database error. // Set the new user group maps. // Check for a database error.