Gc\User\Model::save PHP Method

save() public method

Save user
public save ( ) : integer
return integer
    public function save()
    {
        $this->events()->trigger(__CLASS__, 'before.save', $this);
        $arraySave = array('firstname' => $this->getFirstname(), 'lastname' => $this->getLastname(), 'email' => $this->getEmail(), 'login' => $this->getLogin(), 'updated_at' => new Expression('NOW()'), 'user_acl_role_id' => $this->getUserAclRoleId(), 'retrieve_password_key' => $this->getRetrievePasswordKey(), 'retrieve_updated_at' => $this->getRetrieveUpdatedAt());
        $password = $this->getPassword();
        if (!empty($password)) {
            $arraySave['password'] = $password;
        }
        if ($this->getDriverName() == 'pdo_pgsql') {
            $arraySave['active'] = $this->getActive() ? 'true' : 'false';
        } else {
            $arraySave['active'] = $this->getActive() ? 1 : 0;
        }
        try {
            $id = $this->getId();
            if (empty($id)) {
                $arraySave['created_at'] = new Expression('NOW()');
                $this->insert($arraySave);
                $this->setId($this->getLastInsertId());
            } else {
                $this->update($arraySave, array('id' => $this->getId()));
            }
            $this->events()->trigger(__CLASS__, 'after.save', $this);
            return $this->getId();
        } catch (\Exception $e) {
            $this->events()->trigger(__CLASS__, 'after.save.failed', $this);
            throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
        }
    }

Usage Example

Example #1
0
 /**
  * Sets up the fixture, for example, opens a network connection.
  * This method is called before a test is executed.
  *
  * @return void
  */
 protected function setUp()
 {
     $this->user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1));
     $this->user->setPassword('test');
     $this->user->save();
     $this->object = new Acl($this->user);
 }
All Usage Examples Of Gc\User\Model::save