コード例 #1
0
ファイル: UserManager.php プロジェクト: jarick/bx
 /**
  * Add user
  *
  * @param array $user
  * @return boolean
  */
 public function add(array $user)
 {
     $entity = new UserEntity();
     $entity->setData($user);
     $repo = $this->store()->getRepository('user');
     $event = $this->store()->getEvent();
     if ($this->string()->length($event) > 0) {
         $event_after = 'OnBefore' . $this->string()->ucwords($event) . 'Add';
         Event::on($event_after, function ($user) {
             $filter = array('LOGIC' => 'OR', UserEntity::C_LOGIN => $user[UserEntity::C_LOGIN], UserEntity::C_EMAIL => $user[UserEntity::C_EMAIL]);
             $copy = $this->finder()->filter($filter)->get();
             if ($copy !== false) {
                 $error = new MessageBag();
                 if ($copy->getValue(UserEntity::C_LOGIN) === $user[UserEntity::C_LOGIN]) {
                     $error->add(UserEntity::C_LOGIN, $this->trans('user.manager.add.dublicate_login'));
                     throw new ValidateException($error);
                 }
                 if ($copy->getValue(UserEntity::C_EMAIL) === $user[UserEntity::C_EMAIL]) {
                     $error->add(UserEntity::C_EMAIL, $this->trans('user.manager.add.dublicate_email'));
                     throw new ValidateException($error);
                 }
                 $error->add(UserEntity::C_LOGIN, $this->trans('user.manager.add.dublicate_login_or_email'));
                 $error->add(UserEntity::C_EMAIL, $this->trans('user.manager.add.dublicate_login_or_email'));
                 throw new ValidateException($error);
             }
         });
     }
     if ($this->string()->length($event) > 0) {
         $event_after = 'OnAfter' . $this->string()->ucwords($event) . 'Add';
         Event::on($event_after, function () {
             Cache::clearByTags('user');
         });
     }
     return $this->store()->add($repo, $entity);
 }
コード例 #2
0
ファイル: TableUserStore.php プロジェクト: jarick/bx
 /**
  * Return finder
  *
  * @return \BX\DB\Filter\SqlBuilder
  */
 public function getFinder()
 {
     return static::finder(UserEntity::getClass());
 }