public function getAllUsers($onlyActive = false, $withOutGroups = false, $filterId = array(), $fields = array())
 {
     if (count($fields) == 0) {
         $fields = array('id as id', 'username as name', 'role as role', 'isActive as active');
     }
     /**
      * @var $entity User
      */
     $usersAndLinks = $this->getUsersAndLinks($onlyActive, $withOutGroups, $filterId, $fields);
     $usersSelected = $usersAndLinks['users'];
     $links = $usersAndLinks['links'];
     foreach ($usersSelected as $key => $userSelected) {
         if (isset($userSelected['role'])) {
             $usersSelected[$key]['role'] = User::getRoleList()[$userSelected['role']];
         }
         $usersSelected[$key]['groups'] = array();
     }
     if (!$withOutGroups) {
         foreach ($links as $link) {
             if ($withOutGroups && count($link['uId']) > 0) {
                 continue;
             }
             foreach ($usersSelected as $key => $value) {
                 if ($link['uId'] == $value['id']) {
                     $usersSelected[$key]['groups'][] = $link['gId'];
                 }
             }
         }
     }
     return $usersSelected;
 }
 public function getUserEditForm($action, UserRepository $userRepository, $userId = 0)
 {
     $form = new Form('user_edit_form', $action);
     $currentYear = date('Y', time());
     $form->addField((new FieldText('username', 'Логин'))->addRule(new NotEmpty())->addRule(new IsUniqueInMethod($userRepository, 'isUniqueUser', array('username', $userId))))->addField((new FieldText('password', 'Пароль', array('class' => 'password')))->addRule(new NotEmpty())->addRule(new Length(6, 50)))->addField((new FieldText('email', 'E-mail'))->addRule(new IsEmail())->addRule(new IsUniqueInMethod($userRepository, 'isUniqueUser', array('email', $userId))))->addField(new FieldDropDawnList('role', 'Роль', User::getRoleList()))->addField(new FieldCheckBox('isActive', 'Активен', array(), true))->addField(new FieldText('firstName', 'Фамилия'))->addField(new FieldText('name', 'Имя'))->addField(new FieldText('secondName', 'Отчество'))->addField(new FieldText('name', 'Имя'))->addField(new FieldDateTimeLists('dateBorn', 'Дата рождения', $currentYear - 115, $currentYear - 15, true))->addField((new FieldText('phone', 'Телефон', array(), '80000000000'))->addRule(new IsMatch('/d?/', 'Поле телефон должно содержать только цифры')))->addField(new FieldText('workPosition', 'Должность'))->addField(new FieldText('workPlace', 'Место работы'))->addField(new FieldSubmit('submit', 'submit'));
     return $form;
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /**
      * @var UserRepository $repository
      */
     $username = $input->getArgument('username');
     $password = $input->getArgument('password');
     $email = $input->getArgument('email');
     $role = $input->getArgument('role');
     $em = (new OrmProvider())->getEntityManager();
     $user = new User();
     $repository = $em->getRepository(get_class($user));
     if (!$repository->isUniqueUser('username', 0, $username)) {
         throw new \Exception("Value of parameter username {$username} it nof unique");
     }
     if (!$repository->isUniqueUser('email', 0, $email)) {
         throw new \Exception("Value of parameter email {$email} it nof unique");
     }
     if (!in_array($role, User::getRoleListForAssert())) {
         throw new \Exception("Value {$role} it must be included in list  User::getRoleListForAssert()");
     }
     $user->setUsername($username);
     $user->setPassword($password);
     $user->setEmail($email);
     $user->setRole($role);
     $user->setPhone('98888887');
     $user->setWasChecked(true);
     $user->setIsActive(true);
     $user->setCreatedAt(new \DateTime());
     $user->setUpdatedAt($user->getCreatedAt());
     $em->persist($user);
     $em->flush();
     $output->writeln(sprintf('Added %s user with password %s in role %s', $username, $password, $role));
 }
 public function addReport(User $user, $taskId, TaskReport $report)
 {
     $roles = $this->dataRepository->getRolesInTask($taskId, $user->getId());
     if (count($roles) > 0) {
         $this->accessOpened = true;
     }
     if ($this->accessHasOpened()) {
         $this->task = $this->dataRepository->find($taskId);
         $report->setTask($this->task);
         $report->setUser($user);
         $this->dataRepository->persist($report);
         $this->wasChanged = true;
     }
     return;
 }
 private function generateUser($username, $email, $pass, $role, $fName, $name, $sName, $wPosition)
 {
     $user = new User();
     $user->setUsername($username);
     $user->setEmail($email);
     $user->setPassword($pass);
     $user->setRole($role);
     $user->setFirstName($fName);
     $user->setName($name);
     $user->setSecondName($sName);
     $user->setWorkPosition($wPosition);
     $user->setPhone(800000000000);
     $user->setWasChecked(true);
     $user->setIsActive(true);
     return $user;
 }