/**
  * 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);
 }