Ejemplo n.º 1
0
 protected function getBackdropAwareEntity(ServerRequestInterface $request) : BackdropEntityAware
 {
     if (!$this->entity) {
         $this->entity = $this->profileService->getProfileById($request->getAttribute('profileId'));
     }
     return $this->entity;
 }
Ejemplo n.º 2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $profileId = (int) $input->getArgument('id');
     try {
         $profile = $this->profileService->getProfileById($profileId);
         $output->writeln(["Profile(#{$profile->getId()}): ", "-----", "AccountID: {$profile->getAccount()->getId()}", "Greetings: {$profile->getGreetings()->toJSON()}", "-----"]);
     } catch (ProfileNotFoundException $e) {
         $output->writeln(sprintf("Profile with id `%d` not found", $profileId));
     }
 }
Ejemplo n.º 3
0
 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;
 }
Ejemplo n.º 4
0
 public function createFeedback(CreateFeedbackParameters $createFeedbackParameters) : Feedback
 {
     $feedback = new Feedback($this->feedbackTypeFactory->createFromIntCode($createFeedbackParameters->getType()), $createFeedbackParameters->getDescription(), $createFeedbackParameters->hasProfile() ? $this->profileService->getProfileById($createFeedbackParameters->getProfileId()) : null);
     if (!$createFeedbackParameters->hasProfile()) {
         if ($createFeedbackParameters->hasEmail()) {
             $feedback->setEmail($createFeedbackParameters->getEmail());
         }
     }
     $this->feedbackRepository->createFeedback($feedback);
     return $feedback;
 }
Ejemplo n.º 5
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()];
         }
     });
     $cursor = $collection->find($filter, $options)->toArray();
     if (count($cursor)) {
         $this->profileService->loadProfilesByIds(array_map(function (BSONDocument $document) {
             return (int) $document['id'];
         }, $cursor));
         return $this->cleanResults(array_map(function (BSONDocument $document) {
             try {
                 $profile = $this->profileService->getProfileById((int) $document['id']);
                 return array_merge(['_id' => (string) $document['_id']], $profile->toJSON());
             } catch (ProfileNotFoundException $e) {
                 return null;
             }
         }, $cursor));
     } else {
         return [];
     }
 }
Ejemplo n.º 6
0
 public function format(Post $post) : array
 {
     $postTypeObject = $this->postTypeFactory->createPostTypeByIntCode($post->getPostTypeCode());
     return array_merge_recursive($post->toJSON(), ['post_type' => $postTypeObject->toJSON(), 'profile' => $this->profileService->getProfileById($post->getAuthorProfile()->getId())->toJSON(), 'attachments' => $this->formatAttachments($post)]);
 }