/**
  * Register user
  * 
  * @author Stoyan Rangelov
  * @param array $data
  * @return integer|array
  */
 public function registerUser(array $data)
 {
     //set default group
     $data['group'] = $this->getDefaultGroup();
     //set avatar
     if (isset($_FILES['file'])) {
         $data['avatar'] = $_FILES['file'];
     }
     //Get entity manager
     $em = $this->getEntityManager();
     //Input filters
     $inputFilter = new \User\InputFilter\User();
     $customFilter = $inputFilter->registerUser($this->getUsersRepo(), $this->getServiceLocator()->get('group.service')->getGroupsRepo());
     $inputFilter->setInputFilter($customFilter);
     $filter = $inputFilter->getInputFilter();
     $filter->setData($data);
     if ($filter->isValid()) {
         //Upload avatar
         $avatarName = $this->uploadAvatar($data);
         //Generate the password hash
         $bcrypt = new Bcrypt();
         $securePass = $bcrypt->create($data['password']);
         //Get the entity
         $user = new \User\Entity\User();
         //Populate the User's entity
         $user->setLogin($data['email'])->setHash($securePass)->setCreatedAt(new \DateTime())->setUpdatedAt(new \DateTime())->setActivationCode($this->generateActivationCode())->setGroup($this->getServiceLocator()->get('group.service')->getGroupById($data['group']));
         $em->persist($user);
         $em->flush();
         //Populate the user information
         $userInformation = new \User\Entity\UserInformation();
         $userInformation->setFirstName($data['first_name'])->setLastName($data['last_name'])->setUser($this->getUserById($user->getId()));
         $em->persist($userInformation);
         //            //Populate the user's website
         //            $userWebsite = new \User\Entity\UserWebsite();
         //            $userWebsite->setWebsite($data['website'])
         //                    ->setUser($this->getUserById($user->getId()));
         //            $em->persist($userWebsite);
         //
         //            //Populate the user's phone
         //            $userPhone = new \User\Entity\UserPhone();
         //            $userPhone->setPhone($data['phone'])
         //                    ->setUser($this->getUserById($user->getId()));
         //            $em->persist($userPhone);
         $em->flush();
         //Send email to the user
         try {
             $this->sendConfirmationEmail($user);
         } catch (Exception $e) {
         }
         $result = array();
         $result['status_code'] = 201;
         $result['user_id'] = $user->getId();
         return $result;
     } else {
         return $this->getErrorMessages($filter);
     }
 }