/** * Creates a new user based on a person register and associate them * * @param int $id The person id with user wil be associated */ public function createForPerson($id) { $pd = new Persons_Domain_Person(); $person = $pd->getById($id); if ($person && $person->getId()) { $user = new User_Model_User(); $user->setAppaccount_id(Zend_Auth::getInstance()->getIdentity()->appaccount_id); $user->setPerson_id($id); $user->setStatus(1); $name = split(' ', $person->getName()); $name = array_shift($name); $name .= $id; $f = new Agana_Filter_Transliterate(); $name = $f->filter($name); $user->setName($name); $user->setPwd($name); $user->setEmail($person->getEmail() ? $person->getEmail() : $name . '@no.validemail.com'); $this->setUser($user); if ($this->existUser()) { throw new Exception('There is already a user in database with one of the key fields: email, name'); } else { return $this->add(); } } else { throw new Exception('There is no person with this id'); } }