protected function getBackdropAwareEntity(ServerRequestInterface $request) : BackdropEntityAware { if (!$this->entity) { $this->entity = $this->collectionService->getCollectionById($request->getAttribute('collectionId')); } return $this->entity; }
private function createPostFromParameters(CreatePostParameters $createPostParameters) : Post { $postType = $this->postTypeFactory->createPostTypeByIntCode($createPostParameters->getPostTypeCode()); $collection = $this->collectionService->getCollectionById($createPostParameters->getCollectionId()); $profile = $this->profileService->getProfileById($createPostParameters->getProfileId()); $post = new Post($postType, $profile, $collection, $createPostParameters->getContent()); $post->setAttachmentIds($createPostParameters->getAttachmentIds()); $post->setThemeIds($collection->getThemeIds()); $this->postRepository->createPost($post); return $post; }
private function formatCollections(CollectionTree $tree) : array { return array_map(function (CollectionItem $item) { $json = $this->collectionService->getCollectionById($item->getCollectionId())->toJSON(); if ($item->hasChildren()) { $json['children'] = $this->formatCollections($item->sub()); } else { $json['children'] = []; } return $json; }, $tree->getItems()); }
public function fetch(CriteriaManager $criteriaManager, Collection $collection) : array { $order = 1; $filter = []; $options = ['limit' => self::DEFAULT_LIMIT]; $criteriaManager->doWith(SortCriteria::class, function (SortCriteria $criteria) use(&$options, &$order) { $order = strtolower($criteria->getOrder()) === 'asc' ? 1 : -1; $options['sort'] = []; $options['sort'][$criteria->getField()] = $order; }); $criteriaManager->doWith(SeekCriteria::class, function (SeekCriteria $criteria) use(&$options, &$filter, $order) { $options['limit'] = $criteria->getLimit(); $options['skip'] = 0; if ($criteria->getLastId()) { $lastId = new ObjectID($criteria->getLastId()); if ($order === 1) { $filter['_id'] = ['$gt' => $lastId]; } else { $filter['_id'] = ['$lt' => $lastId]; } } }); $criteriaManager->doWith(ThemeIdCriteria::class, function (ThemeIdCriteria $criteria) use(&$filter) { $filter[sprintf('theme_ids.%s', (string) $criteria->getThemeId())] = ['$exists' => true]; }); $criteriaManager->doWith(QueryStringCriteria::class, function (QueryStringCriteria $criteria) use(&$filter) { if ($criteria->isAvailable()) { $filter['$text'] = ['$search' => $criteria->getQuery()]; } }); $result = $collection->find($filter, $options)->toArray(); $this->collectionService->loadCollectionsByIds(array_map(function (BSONDocument $document) { return (int) $document['id']; }, $result)); return $this->cleanResults(array_map(function (BSONDocument $document) { try { return array_merge(['_id' => (string) $document['_id']], $this->collectionService->getCollectionById((int) $document['id'])->toJSON()); } catch (CollectionNotFoundException $e) { return null; } }, $result)); }
private function upFeedFixture() { $this->output->writeln(['', '[FEED FIXTURE]', '']); usort($this->jsonFeed, function ($a, $b) { return \DateTime::createFromFormat('Y-m-d H:i:s', $a['createdOn']) > \DateTime::createFromFormat('Y-m-d H:i:s', $b['createdOn']); }); foreach ($this->jsonFeed as $json) { $profile = $this->profilesMap[$json['author_id']] ?? false; if ($profile) { $this->output->writeln(sprintf(' [*] Post (date: %s, origID: %d)', $json['createdOn'], $json['id'])); $item = $profile->getCollections()->getItems()[0]; /** @var CollectionItem $item */ $collection = $this->collectionService->getCollectionById($item->getCollectionId()); $this->createPost($profile, $collection, $json); } } }