Ejemplo n.º 1
0
 protected function getBackdropAwareEntity(ServerRequestInterface $request) : BackdropEntityAware
 {
     if (!$this->entity) {
         $this->entity = $this->profileService->getProfileById($request->getAttribute('profileId'));
     }
     return $this->entity;
 }
 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());
     });
 }
Ejemplo n.º 3
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.º 4
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.º 5
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.º 6
0
 public function createAccount($email, $password = null) : Account
 {
     $account = new Account();
     $account->setEmail($email)->setPassword($this->passwordVerifyService->generatePassword($password));
     while ($this->checkAPIKeyCollision($account->getAPIKey())) {
         $account->regenerateAPIKey();
     }
     $this->accountRepository->createAccount($account);
     $this->getEventEmitter()->emit(self::EVENT_ACCOUNT_CREATED, [$account]);
     $this->profileService->createProfileForAccount($account);
     $this->accountRepository->saveAccount($account);
     return $account;
 }
Ejemplo n.º 7
0
 private function createAccountFromJSON(array $json) : Account
 {
     if ($this->accountService->hasAccountWithEmail($json['email'])) {
         return $this->accountService->getByEmail($json['email']);
     } else {
         $account = $this->accountService->createAccount($json['email'], GenerateRandomString::gen(12));
         $profile = $account->getCurrentProfile();
         $profile->setGender(Gender::createFromIntCode((int) $json['gender']));
         $parameters = new EditPersonalParameters('fl', false, $json['username'] ?? '', $json['surname'] ?? '', $json['patronymic'] ?? '', $json['nickname'] ?? '');
         $this->profileService->updatePersonalData($profile->getId(), $parameters);
         $this->profileService->setInterestingInThemes($profile->getId(), $json['interests']);
         if ($json['birthday']) {
             $this->profileService->setBirthday($profile->getId(), \DateTime::createFromFormat('Y-m-d', $json['birthday']));
         }
         $avatarPath = sprintf("%s/%s", self::AVATAR_DIR, $json['avatar']);
         if (file_exists($avatarPath)) {
             list($width, $height) = getimagesize($avatarPath);
             if (!is_null($width) && !is_null($height)) {
                 $size = min($width, $height);
                 $parameters = new UploadImageParameters($avatarPath, new Point(0, 0), new Point($size, $size));
                 $this->profileService->uploadImage($profile->getId(), $parameters);
             }
         }
         return $account;
     }
 }
Ejemplo n.º 8
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.º 9
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)]);
 }