protected function request_get(array $args = array()) { $mainQuestionList = array_map('array_shift', $this->repositoryFactory->getMainQuestionRepository()->query()->addSortField('id', Query::SORT_DESC)->addFilterField('active', true)->get(10)); $fileRepository = $this->repositoryFactory->getFileRepository(); $this->addResponseData('mainQuestionList', array_map(function ($mq) use($fileRepository) { $images = $fileRepository->query()->addFilterField('parentType', FileParentType::MAIN_QUESTION)->addFilterField('parentId', $mq->id)->addFilterField('type', FileData::TYPE_IMAGE)->getEntity(); $mq->images = array_map(function ($image) { return ImageDocument::packImage($image); }, $images); return $mq; }, $mainQuestionList)); $this->setTemplate('page_main.tpl'); }
protected function request_get(array $args = array()) { $questionId = (int) $this->resId[0]; $mainQuestion = $this->repositoryFactory->getMainQuestionRepository()->getById($questionId); if ($mainQuestion) { $images = $this->repositoryFactory->getFileRepository()->query()->addFilterField('parentType', FileParentType::MAIN_QUESTION)->addFilterField('parentId', $mainQuestion->id)->addFilterField('type', FileData::TYPE_IMAGE)->getEntity(); $mainQuestion->images = array_map(function ($image) { return ImageDocument::packImage($image); }, $images); $this->addResponseData('mainQuestion', $mainQuestion); $this->setTemplate("page_question.tpl"); } }
protected function request_get(array $args = array()) { $categoryId = (int) $this->resId[0]; $categoryCurrent = $this->repositoryFactory->getCategoryRepository()->getById($categoryId); if ($categoryCurrent) { $this->addResponseData('categoryCurrent', $categoryCurrent); $mainQuestionList = $this->repositoryFactory->getMainQuestionRepository()->query()->addFilterField('categoryId', $categoryId)->addSortField('id', Query::SORT_DESC)->addFilterField('active', true)->getEntity(10); $fileRepository = $this->repositoryFactory->getFileRepository(); $this->addResponseData('mainQuestionList', array_map(function ($mq) use($fileRepository) { $images = $fileRepository->query()->addFilterField('parentType', FileParentType::MAIN_QUESTION)->addFilterField('parentId', $mq->id)->addFilterField('type', FileData::TYPE_IMAGE)->getEntity(); $mq->images = array_map(function ($image) { return ImageDocument::packImage($image); }, $images); return $mq; }, $mainQuestionList)); $this->setTemplate("page_category.tpl"); } }
/** * @param int $parentId Id сущности, к которой привязаны изображения * @param int $parentType тип сущности, к которой привязаны изображения. Если не задано - определяется по классу объекта $this * @return array[][] Метаданные изображений в виде массива. Первый индекс - изображение, второй ассоциативный - поле изображения */ protected function getPackedImages($parentId, $parentType = 0) { if (empty($parentType)) { switch (true) { case $this instanceof \Maradik\Hinter\Api\SecondQuestionCollection: case $this instanceof \Maradik\Hinter\Api\SecondQuestionDocument: $parentType = FileParentType::SECOND_QUESTION; break; case $this instanceof \Maradik\Hinter\Api\SecondAnswerCollection: case $this instanceof \Maradik\Hinter\Api\SecondAnswerDocument: $parentType = FileParentType::SECOND_ANSWER; break; case $this instanceof \Maradik\Hinter\Api\MainQuestionCollection: case $this instanceof \Maradik\Hinter\Api\MainQuestionDocument: case $this instanceof \Maradik\Hinter\Api\MainQuestionController: $parentType = FileParentType::MAIN_QUESTION; break; case $this instanceof \Maradik\Hinter\Api\MainAnswerCollection: case $this instanceof \Maradik\Hinter\Api\MainAnswerDocument: $parentType = FileParentType::MAIN_ANSWER; break; } } if (empty($parentType)) { return array(); } $images = $this->repositoryFactory->getFileRepository()->query()->addFilterField('parentType', $parentType)->addFilterField('parentId', $parentId)->addFilterField('type', FileData::TYPE_IMAGE)->getEntity(); return array_map(function ($image) { return ImageDocument::packImage($image); }, $images); }
/** * @param BaseData $entity * @return array */ protected function packEntity(BaseData $entity) { if (!$entity instanceof \Maradik\Testing\FileData) { throw new \InvalidArgumentException('Неверный тип параметра $entity: ожидается \\Maradik\\Testing\\FileData, получен ' . get_class($entity)); } return ImageDocument::packImage($entity); }