/**
  * Run query and use result data to build an instance of BundleProxy
  *
  * @param bool $returnAsArray      Will return an array of Bundles if set to true, will return the first value
  *                                 of the array if false
  * @return array | BundleProxy
  */
 private function _load($returnAsArray = true)
 {
     if (null === $this->_queryBuilder) {
         throw new \LogicException('No query builder set!');
     }
     $result = $this->_queryBuilder->getQuery()->run();
     $bundles = [];
     foreach ($result as $row) {
         $bundle = new BundleProxy($this->_loaders, $this->_defaultCurrency);
         $bundle->setID((int) $row->id);
         $bundle->setName($row->name);
         $bundle->setAllowCodes((bool) $row->allowCodes);
         if ($row->start) {
             $bundle->setStart(new DateTimeImmutable(date('c', $row->start)));
         }
         if ($row->end) {
             $bundle->setEnd(new DateTimeImmutable(date('c', $row->end)));
         }
         if ($row->imageID) {
             $bundle->setImageID($row->imageID);
         }
         $bundle->getAuthorship()->create(new DateTimeImmutable(date('c', $row->createdAt)), $this->_userLoader->getByID($row->createdBy));
         if ($row->updatedAt) {
             $bundle->getAuthorship()->update(new DateTimeImmutable(date('c', $row->updatedAt)), $this->_userLoader->getByID($row->updatedBy));
         }
         if ($row->deletedAt) {
             $bundle->getAuthorship()->delete(new DateTimeImmutable(date('c', $row->deletedAt)), $this->_userLoader->getByID($row->deletedAt));
         }
         $bundles[$bundle->getID()] = $bundle;
     }
     return $returnAsArray ? $bundles : array_shift($bundles);
 }
Exemplo n.º 2
0
 /**
  * Get the user assigned to the field
  *
  * @return BaseUser\User | null
  */
 public function getUser()
 {
     if (null === $this->_user) {
         if (!$this->getValue()) {
             return null;
         }
         $user = $this->_baseUserLoader->getByID($this->getValue());
         if (is_array($user)) {
             $user = array_shift($user);
         }
         if ($user) {
             $this->_user = $user;
         }
     }
     return $this->_user;
 }
 /**
  * {@inheritDoc}
  */
 public function load(ReferralProxy $referral)
 {
     $referrerID = $referral->getReferrerID();
     return $this->_userLoader->getByID($referrerID);
 }
Exemplo n.º 4
0
 /**
  * @param UserTypeInterface $type
  *
  * @return array | User\User
  */
 public function getByType(UserTypeInterface $type)
 {
     $ids = $this->_queryBuilderFactory->getQueryBuilder()->select('user_id')->from('user_type')->where('type = ?s', [$type->getName()])->run()->flatten();
     return $this->_baseLoader->getByID($ids);
 }
 /**
  * {@inheritDoc}
  */
 public function isValid(ReferralInterface $referral)
 {
     $users = $this->_userLoader->getByEmail($referral->getReferredEmail());
     return empty($users);
 }