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);
}
}