コード例 #1
0
 /**
  * Set the user type to determine which user choices will be set.
  * An exception will be thrown if this method is not called when using this field.
  *
  * @param string | Type\UserTypeInterface $type
  *
  * @return User
  */
 public function setUserType($type)
 {
     if (!is_string($type) && !$type instanceof Type\UserTypeInterface) {
         throw new \InvalidArgumentException('User type must be a string or an instance of UserTypeInterface');
     }
     $this->_type = is_string($type) ? $this->_userTypes->get($type) : $type;
     return $this;
 }
コード例 #2
0
 public function getByUserID($userID)
 {
     if (!is_numeric($userID)) {
         throw new \InvalidArgumentException('User ID must be numeric');
     }
     $result = $this->_queryBuilderFactory->getQueryBuilder()->select('type')->from(self::TYPE_TABLE)->where('user_id = ?i', [$userID])->getQuery()->run();
     $type = $result->count() ? $result->value() : 'none';
     return $this->_userTypes->get($type);
 }
コード例 #3
0
 /**
  * Get a new instance of Profile with the fields set up
  *
  * @param string | UserTypeInterface $type
  *
  * @return Profile
  */
 public function getProfile($type)
 {
     if (is_string($type)) {
         $type = $this->_userTypes->get($type);
     } elseif (!$type instanceof UserTypeInterface) {
         $varType = gettype($type) === 'object' ? get_class($type) : gettype($type);
         throw new \InvalidArgumentException('Type must be either a string or an instance of UserTypeInterface, ' . $varType . ' given');
     }
     $profile = new Profile($type);
     $factory = $this->_getFieldFactory();
     $factory->build($type);
     foreach ($factory as $name => $field) {
         $profile->{$name} = $field instanceof Field\Group && $field->isRepeatable() ? new Field\RepeatableContainer($field) : $field;
     }
     return $profile;
 }