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; }
public function unSubscribeCollection(Profile $profile, Collection $collection) { $criteria = ['profileId' => $profile->getId(), 'subscribeId' => $collection->getId(), 'subscribeType' => Subscribe::TYPE_COLLECTION]; return $this->subscribeRepository->unSubscribeByCriteria($criteria); }
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()]); } }