コード例 #1
0
 public function up(EventEmitterInterface $globalEmitter)
 {
     $this->profileService->getEventEmitter()->on(ProfileService::EVENT_PROFILE_CREATED, function (Profile $profile) {
         $collection = $this->collectionService->createCollection(new CreateCollectionParameters(sprintf('profile:%d', $profile->getId()), 'Профиль', ''), true);
         $this->collectionService->mainCollection($collection->getId());
     });
 }
コード例 #2
0
 protected function getBackdropAwareEntity(ServerRequestInterface $request) : BackdropEntityAware
 {
     if (!$this->entity) {
         $this->entity = $this->collectionService->getCollectionById($request->getAttribute('collectionId'));
     }
     return $this->entity;
 }
コード例 #3
0
ファイル: PostService.php プロジェクト: cass-project/cass
 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;
 }
コード例 #4
0
 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());
 }
コード例 #5
0
ファイル: DemoFixture.php プロジェクト: cass-project/cass
 private function createPost(Profile $profile, Collection $collection, array $json) : Post
 {
     $this->output->writeln(sprintf(' [*] - Create post (id: %s)', $json['id']));
     $parameters = $this->createPostParameters($profile, $collection, $json);
     $this->collectionService->editThemeIds($collection->getId(), $json['themeIds']);
     $post = $this->postService->createPost($parameters);
     $post = $this->postService->replaceDateCreatedOn($post->getId(), \DateTime::createFromFormat('Y-m-d H:i:s', $json['createdOn']));
     $this->collectionService->editThemeIds($collection->getId(), []);
     return $post;
 }
コード例 #6
0
 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));
 }