Exemple #1
0
 public function registerUser($formdata)
 {
     $entity = new \Application\Entity\User();
     $roleid = $this->em->getRepository('\\Application\\Entity\\Role')->find($formdata['User']['fkRoleid']);
     //Initialize fields
     $entity->setUsername($formdata['User']['username']);
     $entity->setFirstname($formdata['User']['basicdetails']['firstname']);
     $entity->setSurname($formdata['User']['basicdetails']['surname']);
     $entity->setOthernames($formdata['User']['basicdetails']['othernames']);
     $entity->setGender($formdata['User']['basicdetails']['gender']);
     $entity->setPassword($this->cs->_hashing($formdata['password']));
     $entity->setTitle($formdata['User']['basicdetails']['title']);
     $entity->setAccounttype("STAFF");
     $entity->setEmailaddress($formdata['User']['emailaddress']);
     $entity->setFkRoleid($roleid);
     $fkUserid = $this->saveUser($entity);
     //Save user in user table
     if ($fkUserid) {
         //Set staff entity
         $staffentity = new \Application\Entity\Staff();
         $fkDeptid = $this->em->getRepository('\\Application\\Entity\\Department')->find($formdata['Staff']['fkDeptid']);
         $staffentity->setFkDeptid($fkDeptid);
         $staffentity->setFkUserid($fkUserid);
         $staffentity->setWorkmode($formdata['Staff']['workmode']);
         //Save in staff table
         $staffid = $this->saveStaff($staffentity);
         //Assign to department as head
         if ($formdata['ishead']) {
             $departmentModel = new \Application\Model\Preferences($this->em);
             // Update is head
             $deptEntity = $fkDeptid->setFkStaffid($staffid);
             $departmentModel->saveDepartment($deptEntity);
         }
     }
     return $fkUserid;
 }
Exemple #2
0
 /**
  * Create a new user
  *
  * @param $request
  * @return \Application\Entity\User
  */
 public function register($request)
 {
     $messages = $this->validateRegisterRequest($request);
     if (empty($messages)) {
         $salt = md5(time());
         $password_md5 = md5($salt . $request['password']);
         $user = new \Application\Entity\User();
         $user->setEmail($request['email']);
         $user->setSalt($salt);
         $user->setPassword($password_md5);
         $this->em()->persist($user);
         $this->em()->flush();
         $status = true;
         $entity = $user;
     } else {
         $status = false;
         $entity = null;
     }
     return array("status" => $status, "messages" => $messages, "entity" => $entity);
 }