API16

JUser/save

From Joomla! Documentation

< API16:JUser
Revision as of 17:43, 22 March 2010 by Doxiki (talk | contribs) (New page: ===Description=== Method to save the JUser object to the database <span class="editsection" style="font-size:76%;"> <nowiki>[</nowiki>Edit Descripton<nowiki...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

The "API16" namespace is an archived namespace. This page contains information for a Joomla! version which is no longer supported. It exists only as a historical reference, it will not be improved and its content may be incomplete and/or contain broken links.

Description[edit]

Method to save the JUser object to the database

[Edit Descripton]

Template:Description:JUser/save

Syntax[edit]

save($updateOnly=false)
Parameter Name Default Value Description
$updateOnly false $updateOnly Save the object only if not a new user

Returns[edit]

boolean True on success

Defined in[edit]

libraries/joomla/user/user.php

Importing[edit]

jimport( 'joomla.user.user' );

Source Body[edit]

function save($updateOnly = false)
{
        // Create the user table object
        $table  = &$this->getTable();
        $this->params = (string)$this->_params;
        $table->bind($this->getProperties());

        // Check and store the object.
        if (!$table->check()) {
                $this->setError($table->getError());
                return false;
        }

        // If user is made a Super Admin group and user is NOT a Super Admin
        //
        // @todo ACL - this needs to be acl checked
        //
        $my = &JFactory::getUser();
//              if ($this->get('gid') == 25 && $my->get('gid') != 25)
//              {
//                      // disallow creation of Super Admin by non Super Admin users
//                      $this->setError(JText::_('WARNSUPERADMINCREATE'));
//                      return false;
//              }
//
//              // If user is made an Admin group and user is NOT a Super Admin
//              if ($this->get('gid') == 24 && !($my->get('gid') == 25 || ($this->get('id') == $my->id && $my->get('gid') == 24)))
//              {
//                      // disallow creation of Admin by non Super Admin users
//                      $this->setError(JText::_('WARNSUPERADMINCREATE'));
//                      return false;
//              }

        //are we creating a new user
        $isnew = !$this->id;

        // If we aren't allowed to create new users return
        if ($isnew && $updateOnly) {
                return true;
        }

        // Get the old user
        $old = new JUser($this->id);

        // Fire the onBeforeStoreUser event.
        JPluginHelper::importPlugin('user');
        $dispatcher = &JDispatcher::getInstance();
        $dispatcher->trigger('onBeforeStoreUser', array($old->getProperties(), $isnew, $this->getProperties()));

        //Store the user data in the database
        if (!$result = $table->store()) {
                $this->setError($table->getError());
        }

        // Set the id for the JUser object in case we created a new user.
        if (empty($this->id)) {
                $this->id = $table->get('id');
        }

        if ($my->id == $table->id)
        {
                $registry = new JParameter($table->params);
                $my->setParameters($registry);
        }
        // Fire the onAftereStoreUser event
        $dispatcher->trigger('onAfterStoreUser', array($this->getProperties(), $isnew, $result, $this->getError()));

        return $result;
}

[Edit See Also] Template:SeeAlso:JUser/save

Examples[edit]

<CodeExamplesForm />