/** * This function is used to perform the add new user in database. It's necessary * because the createAdmin function does not need to test if user is allowed * * @return User_Model_User * @throws Exception */ private function _add() { $this->_user->setSalt(Agana_Util_Crypt::calcRndTimeSalt($this->_user->getPwd(), $this->_user->getName())); $this->_user->setPwd(md5($this->_user->getPwd() . $this->_user->getSalt())); $this->_user->setCreated(time()); try { $u = new User_Persist_Dao_User(); $u->beginTransaction(); // save a new person if needed $person = $this->_user->getPerson(); if (!isset($person) || !$person->getId()) { if ($person) { $personName = $person->getName() ? $person->getName() : $this->_user->getName(); } else { $personName = $this->_user->getName(); $this->_user->setPerson(new Persons_Model_Person()); } $personToSave = $this->_user->getPerson(); $personToSave->setName($personName); $personToSave->setGender(' '); $personDomain = new Persons_Domain_Person($personToSave); // do not need to use trasaction so false is passed $personResultId = $personDomain->create(false); $person = $personDomain->getById($personResultId); $this->_user->setPerson($person); } $app = $this->_user->getAppAccount(); if (!isset($app) || !$app->getId()) { throw new Agana_Exception('An App Account must be provided to include a new user'); } $u->setUseTransaction(false); $res = $u->save($this->_user); $u->commit(); return $res; } catch (Exception $e) { $u->rollback(); throw $e; } }