/** * Saves a user into the database. * * @param \MicroCMS\Domain\User $user The user to save */ public function save(User $user) { $userData = array('usr_name' => $user->getUsername(), 'usr_salt' => $user->getSalt(), 'usr_password' => $user->getPassword(), 'usr_role' => $user->getRole(), 'usr_mail' => $user->getMail(), 'usr_tel' => $user->getTelephone(), 'usr_adr' => $user->getAdresse(), 'usr_ville' => $user->getVille()); if ($user->getId()) { // The user has already been saved : update it $this->getDb()->update('t_user', $userData, array('usr_id' => $user->getId())); } else { // The user has never been saved : insert it $this->getDb()->insert('t_user', $userData); // Get the id of the newly created user and set it on the entity. $id = $this->getDb()->lastInsertId(); $user->setId($id); } }