/** * Load the tags via the query builder * * @throws \LogicException Throws exception if query builder is not set yet * * @return array */ private function _load() { if (null === $this->_queryBuilder) { throw new \LogicException('Cannot load tags, query builder not set!'); } $tags = $this->_queryBuilder->getQuery()->run()->flatten(); $this->_queryBuilder = null; return $tags; }
/** * 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); }
/** * Loads the file data out of the table and loads in into a File Object. * * @return File|false return instance of the file is loaded else false */ protected function _loadFromQuery() { if (null === $this->_queryBuilder) { throw new \LogicException('Cannot load files, query builder not set'); } $result = $this->_queryBuilder->getQuery()->run(); if (count($result)) { return $this->_loadFile($result); } $this->_queryBuilder = null; return false; }
/** * Loop through loaded data and assign to fields in profile instances as appropriate * * @param bool $returnAsArray * * @return array|mixed */ private function _load($returnAsArray = false) { if (null === $this->_queryBuilder) { throw new \LogicException('Query builder not set!'); } $result = $this->_queryBuilder->getQuery()->run(); $this->_queryBuilder = null; $profiles = []; foreach ($result->collect('group') as $groupName => $rows) { foreach ($rows as $row) { if (!array_key_exists($row->userID, $profiles)) { $profiles[$row->userID] = $this->_factory->getProfile($row->type); } $profile = $profiles[$row->userID]; if ($groupName) { $group = $profile->{$groupName}; if (!$group) { continue; } if ($group instanceof Field\RepeatableContainer) { while (!$group->get($row->sequence)) { $group->add(); } $group = $group->get($row->sequence); } try { $field = $group->{$row->field}; } catch (\OutOfBoundsException $e) { continue; } } else { $field = $profile->{$row->field}; } if (!isset($field)) { continue; } if ($field instanceof Field\MultipleValueField) { $field->setValue($row->dataName, $row->value); } elseif ($field instanceof Field\BaseField) { $field->setValue($row->value_string); } } } return $returnAsArray ? $profiles : array_shift($profiles); }