示例#1
0
 public function subscribeCollection(Profile $profile, Collection $collection, $options = null) : Subscribe
 {
     $subscribe = new Subscribe();
     $subscribe->setProfileId($profile->getId())->setOptions($options)->setSubscribeId($collection->getId())->setSubscribeType(Subscribe::TYPE_COLLECTION);
     $em = $this->getEntityManager();
     $em->persist($subscribe);
     $em->flush();
     return $subscribe;
 }
示例#2
0
 public function createCollection(CreateCollectionParameters $parameters, bool $disableAccess = false)
 {
     $collection = new Collection($parameters->getOwnerSID());
     if (!$disableAccess) {
         $this->getEventEmitter()->emit(self::EVENT_COLLECTION_ACCESS, [$collection]);
     }
     $collection->setTitle($parameters->getTitle())->setDescription($parameters->getDescription())->setThemeIds($parameters->getThemeIds());
     $this->collectionRepository->createCollection($collection);
     $this->avatarService->generateImage(new CollectionImageStrategy($collection, $this->images, $this->wwwImagesDir));
     $this->backdropService->backdropPreset($collection, $this->presetFactory, $this->presetFactory->getListIds()[array_rand($this->presetFactory->getListIds())]);
     $this->collectionRepository->saveCollection($collection);
     $this->getEventEmitter()->emit(self::EVENT_COLLECTION_CREATED, [$collection]);
     return $collection;
 }
 public function getLetter() : string
 {
     return substr($this->collection->getTitle(), 0, 1);
 }
 protected function isIndexable(Collection $entity) : bool
 {
     $hasTheme = count($entity->getThemeIds()) > 0;
     $notProfileCollection = !$entity->isMain();
     return $hasTheme && $notProfileCollection;
 }
示例#5
0
 public function unSubscribeCollection(Profile $profile, Collection $collection)
 {
     $criteria = ['profileId' => $profile->getId(), 'subscribeId' => $collection->getId(), 'subscribeType' => Subscribe::TYPE_COLLECTION];
     return $this->subscribeRepository->unSubscribeByCriteria($criteria);
 }
 protected function getThemeIdsWeight(Collection $entity) : array
 {
     return $this->themeWeightCalculator->calculateWeights($entity->getThemeIds());
 }
示例#7
0
 private function createPostParameters(Profile $profile, Collection $collection, array $json) : CreatePostParameters
 {
     switch ((int) $json['typeId']) {
         default:
             throw new \Exception(sprintf('Unknown type_id `%s`', $json['type_id']));
         case 0:
             // "content", simple post
             return new CreatePostParameters(DefaultPostType::CODE_INT, $profile->getId(), $collection->getId(), $json['description'], []);
         case 2:
             // youtube
             $url = $json['url'];
             $parsedURL = parse_url($url);
             if (!isset($parsedURL['host'])) {
                 $url = 'https://www.youtube.com/watch?v=yKBLCcQObdQ';
                 $v = 'yKBLCcQObdQ';
             } else {
                 if (strtolower($parsedURL['host']) === 'youtu.be' || !isset($parsedURL['query'])) {
                     $v = str_replace('/', '', $parsedURL['path']);
                 } else {
                     $params = [];
                     parse_str(parse_url($url)['query'] ?? '', $params);
                     $v = $params['v'];
                 }
             }
             $linkAttachment = new Attachment();
             $linkAttachment->setMetadata(['url' => $url, 'resource' => 'youtube', 'source' => ['source' => 'external', 'origURL' => $url], 'metadata' => ['og' => ['basic' => ['description' => '', 'title' => '', 'url' => $url], 'og' => ['basic' => ['og:url' => $url, 'og:title' => '', 'og:type' => '', 'og:description' => '', 'og:determiner' => '', 'og:locale' => '', 'og:locale:alternate' => '', 'og:site_name' => ''], 'images' => [['og:image' => '', 'og:image:url' => '', 'og:image:type' => '', 'og:image:width' => '', 'og:image:height' => '']], 'videos' => [['og:video' => '', 'og:video:url' => '', 'og:video:type' => '', 'og:video:width' => '', 'og:video:height' => '']], 'audios' => [['og:video' => '', 'og:video:url' => '', 'og:video:type' => '']]]], 'youtubeId' => $v]]);
             $this->attachmentRepository->createAttachment($linkAttachment);
             return new CreatePostParameters(DefaultPostType::CODE_INT, $profile->getId(), $collection->getId(), $json['description'] ?? '', [$linkAttachment->getId()]);
         case 3:
             // link
             $options = json_decode($json['options'], true);
             $url = $options['url'];
             $params = [];
             parse_str(parse_url($url)['query'] ?? '', $params);
             $title = $options['title'] ?? '';
             $description = $options['description'] ?? '';
             $image = $options['image'] ?? '';
             $linkAttachment = new Attachment();
             $linkAttachment->setMetadata(['url' => $url, 'resource' => 'page', 'source' => ['source' => 'external', 'origURL' => $url], 'metadata' => ['og' => ['basic' => ['description' => $description, 'title' => $title, 'url' => $url], 'og' => ['basic' => ['og:url' => $url, 'og:title' => $title, 'og:type' => '', 'og:description' => $description, 'og:determiner' => '', 'og:locale' => '', 'og:locale:alternate' => '', 'og:site_name' => ''], 'images' => [['og:image' => $image, 'og:image:url' => $image, 'og:image:type' => '', 'og:image:width' => '', 'og:image:height' => '']], 'videos' => [['og:video' => '', 'og:video:url' => '', 'og:video:type' => '', 'og:video:width' => '', 'og:video:height' => '']], 'audios' => [['og:video' => '', 'og:video:url' => '', 'og:video:type' => '']]]]]]);
             $this->attachmentRepository->createAttachment($linkAttachment);
             return new CreatePostParameters(DefaultPostType::CODE_INT, $profile->getId(), $collection->getId(), $json['description'] ?? '', [$linkAttachment->getId()]);
     }
 }