/** * @param string $story * @param PosterInterface $poster * @param PosterInterface $parent * @param $origin * @param int $privacyType * @param int $privacyValue * @param array $params * * @return Feed */ public function add($story = '', PosterInterface $poster, PosterInterface $parent = null, $origin, $privacyType = 1, $privacyValue = 1, $params = []) { $about = null; $content = null; $parentShareId = 0; $feedId = 0; if (null == $parent) { $parent = $poster; } if ($origin instanceof Feed) { $content = $origin->getAbout(); $feedId = $origin->getId(); } else { $content = $origin; } if (empty($about)) { $about = $content; } if ($about instanceof Share) { $parentShareId = $content->getId(); $about = $about->getAbout(); } $share = new Share(['user_id' => $poster->getUserId(), 'feed_id' => 0, 'story' => $story, 'poster_id' => $poster->getId(), 'parent_share_id' => (int) $parentShareId, 'poster_type' => $poster->getType(), 'parent_user_id' => $parent->getUserId(), 'parent_id' => $parent->getId(), 'parent_type' => $parent->getType(), 'about_id' => $about->getId(), 'about_type' => $about->getType(), 'params_text' => json_encode($params), 'privacy_type' => $privacyType, 'privacy_value' => $privacyValue, 'privacy_text' => json_encode(['view' => ['type' => $privacyType, 'value' => $privacyValue]])]); $share->save(); $feed = app()->feedService()->addItemFeed('share', $share); $share->setFeedId($feed->getId()); $share->save(); return $feed; }
/** * @param PosterInterface $poster * @param AtomInterface $about * @param $content * @param array $params * * @return \Platform\Comment\Model\Comment */ public function add(PosterInterface $poster, AtomInterface $about, $content, $params = []) { $parent = $about->getParent(); $params = array_merge(['about_id' => $about->getId(), 'poster_id' => $poster->getId(), 'user_id' => $poster->getUserId(), 'about_type' => $about->getType(), 'poster_type' => $poster->getType(), 'parent_id' => $parent->getId(), 'parent_user_id' => $parent->getUserId(), 'parent_type' => $parent->getType(), 'content' => strip_tags(html_entity_decode($content)), 'created_at' => KENDO_DATE_TIME, 'modified_at' => KENDO_DATE_TIME], $params); $comment = new Comment($params); $comment->save(); return $comment; }
/** * @param PosterInterface $parent * @param array $values */ private function saveValues(PosterInterface $parent, $values) { if (empty($values)) { $values = []; } $this->objects[$parent->getId()] = $values; $item = app()->table('core.value')->findById($parent->getId()); if (!$item) { $item = new Value(['parent_id' => $parent->getId(), 'parent_type' => $parent->getType()]); } $item->__set('values_text', json_encode($values)); $item->save(); }
/** * @param PosterInterface $poster * @param ContentInterface $object * @param $score * @param $content * @param array $params * * @return bool */ public function add(PosterInterface $poster, ContentInterface $object, $score, $content, $params = []) { $score = (int) $score; if ($score < self::MIN_SCORE || $score > self::MAX_SCORE) { throw new \InvalidArgumentException(strtr('invalid score value :score (min: :min, max: :max)', [':score' => $score, ':min' => self::MIN_SCORE, ':max' => self::MAX_SCORE])); } $reivew = $this->findReview($poster->getId(), $object->getId()); if (null == $reivew) { $params = array_merge(['object_id' => $object->getId(), 'poster_id' => $poster->getId(), 'object_type' => $object->getType(), 'poster_type' => $poster->getType(), 'score' => $score, 'content' => $content, 'created_at' => KENDO_DATE_TIME, 'modified_at' => KENDO_DATE_TIME], $params); $reivew = new Review($params); $reivew->save(); return true; } return false; }
/** * @param PosterInterface $poster * @param PosterInterface $object * * @return Block * @throws \InvalidArgumentException */ public function add(PosterInterface $poster, PosterInterface $object) { /** * block the same content */ if ($object->getId() == $poster->getId() && $object->getType() == $poster->getType()) { throw new \InvalidArgumentException("Could not block your self"); } $block = $this->findBlock($poster, $object); if (null == $block) { $block = new Block(['object_id' => $object->getId(), 'poster_id' => $poster->getId(), 'object_type' => $object->getType(), 'poster_type' => $poster->getType(), 'created_at' => KENDO_DATE_TIME]); $block->save(); } return $block; }
/** * Send new notification to receiver(parent) from poster(sender) * * @param string $type * @param PosterInterface $poster * @param PosterInterface $parent * @param ContentInterface|PosterInterface $about * @param $params * * @return Platform\Notification */ public function addNotification($type, PosterInterface $poster, PosterInterface $parent, $about = null, $params = []) { if (!$about) { $about = $poster; } $data = ['type_id' => $type, 'poster_id' => $poster->getId(), 'user_id' => $poster->getUserId(), 'parent_id' => $parent->getId(), 'parent_user_id' => $parent->getUserId(), 'poster_type' => $poster->getType(), 'parent_type' => $parent->getType(), 'about_type' => $about->getType(), 'about_id' => $about->getId(), 'params' => json_encode($params), 'created_at' => KENDO_DATE_TIME]; if (null != $about) { $data = array_merge($data, ['about_id' => $about->getId(), 'about_type' => $about->getType()]); } $item = new Notification($data); $item->save(); return $item; }
/** * @param \Kendo\Content\PosterInterface $poster * @param \Kendo\Content\ContentInterface|\Kendo\Content\PosterInterface $about * @param array $data * * @return Report */ public function addReport($poster, $about, $data = []) { $data = array_merge(['poster_id' => $poster->getId(), 'poster_type' => $poster->getType(), 'about_type' => $about->getType(), 'about_id' => $about->getId(), 'created_at' => KENDO_DATE_TIME], $data); /** * */ $item = new Report($data); $item->save(); return $item; }
/** * @return string */ public function getType() { return null != $this->viewer ? $this->viewer->getType() : ''; }
/** * @param PosterInterface $poster * @param PosterInterface $parent * @param string $status * * @return \Platform\Relation\Model\RelationRequest */ private function addMembershipRequest(PosterInterface $poster, PosterInterface $parent, $status = 'sent') { $request = new RelationRequest(['parent_id' => $parent->getId(), 'poster_id' => $poster->getId(), 'poster_type' => $poster->getType(), 'parent_type' => $parent->getType(), 'relation_type' => RELATION_TYPE_MEMBER, 'status' => $status, 'created_at' => KENDO_DATE_TIME]); $request->save(); return $request; }
/** * Reply an existing message. * * @param string $replyMsgId * @param PosterInterface $poster * @param string $subject * @param string $content * * @return \Platform\Message\Model\Message * @throws \InvalidArgumentException */ public function replyMessage($replyMsgId, PosterInterface $poster, $subject, $content) { $replyMsg = $this->findMessage($replyMsgId); if (!$replyMsg instanceof Message) { throw new \InvalidArgumentException("Invalid arguments [replyMsgId]"); } $conv = $this->findConversation($replyMsg->getConversationId()); if (!$conv instanceof Conversation) { throw new \InvalidArgumentException("Invalid argument [replyMsgId]"); } $msg = new Message(['conversation_id' => $conv->getId(), 'reply_message_id' => $replyMsg->getId(), 'poster_id' => $poster->getId(), 'poster_type' => $poster->getType(), 'type_id' => self::TYPE_MESSAGE, 'subject' => (string) $subject, 'content' => (string) $content, 'created_at' => KENDO_DATE_TIME]); $msg->save(); $this->sendMessageToRecipients($conv, $msg); return $msg; }
/** * @param Feed $feed * @param PosterInterface $profile * * @return FeedStream */ private function putFeedToProfile(Feed $feed, PosterInterface $profile) { $stream = new FeedStream(['feed_id' => $feed->getId(), 'feed_type' => $feed->getFeedType(), 'poster_id' => $feed->getPosterId(), 'about_id' => $feed->getAboutId(), 'parent_id' => $feed->getParentId(), 'privacy_value' => $feed->getPrivacyValue(), 'privacy_type' => $feed->getPrivacyType(), 'profile_id' => $profile->getId(), 'profile_type' => $profile->getType()]); $stream->save(); return $stream; }
/** * @param $params * @param PosterInterface $poster * @param PosterInterface $parent * @param int $privacyType * @param int $privacyValue * * @return \Platform\Link\Model\Link */ public function addLink($params, PosterInterface $poster, PosterInterface $parent, $privacyType, $privacyValue) { if (null === $privacyType || null == $privacyValue) { $privacyType = RELATION_TYPE_ANYONE; $privacyValue = RELATION_TYPE_ANYONE; } $data = array_merge(['poster_id' => $poster->getId(), 'parent_id' => $parent->getId(), 'poster_type' => $poster->getType(), 'parent_type' => $parent->getType(), 'user_id' => $poster->getUserId(), 'privacy_type' => $privacyType, 'privacy_value' => $privacyValue, 'created_at' => KENDO_DATE_TIME, 'modified_at' => KENDO_DATE_TIME, 'privacy_text' => json_encode(['view' => ['type' => $privacyType, 'value' => $privacyType]])], $params); $link = new Link($data); $link->save(); return $link; }
/** * @param PosterInterface $poster * @param AtomInterface $about * * @return bool */ public function add(PosterInterface $poster, AtomInterface $about) { if ($about instanceof Feed) { $about = $about->getAbout(); } $like = new Like(['about_id' => $about->getId(), 'poster_id' => $poster->getId(), 'about_type' => $about->getType(), 'poster_type' => $poster->getType(), 'created_at' => KENDO_DATE_TIME]); $like->save(); }
/** * @param PosterInterface $poster * @param PosterInterface $parent * @param array $params * @param int $privacyType * @param int $privacyValue * * @return Video */ public function addVideo(PosterInterface $poster, PosterInterface $parent, $params = [], $privacyType = null, $privacyValue = null) { if (null === $privacyType || null === $privacyValue) { $privacyType = RELATION_TYPE_ANYONE; $privacyValue = RELATION_TYPE_ANYONE; } $data = array_merge(['user_id' => $poster->getUserId(), 'poster_id' => $poster->getId(), 'poster_type' => $poster->getType(), 'parent_id' => $parent->getId(), 'parent_type' => $parent->getType(), 'parent_user_id' => $parent->getUserId(), 'module_id' => 'video', 'privacy_type' => $privacyType, 'privacy_value' => $privacyValue, 'created_at' => KENDO_DATE_TIME, 'modified_at' => KENDO_DATE_TIME], $params); $video = new Video($data); $video->save(); return $video; }
/** * @param array $fileId * @param PosterInterface $poster * @param PosterInterface $parent * @param \Platform\Photo\Model\PhotoAlbum $album * @param array $params * * @return \Platform\Photo\Model\Photo */ public function addPhoto($fileId, PosterInterface $poster, PosterInterface $parent = null, PhotoAlbum $album = null, $params = []) { if (null == $parent) { $parent = $poster; } if (null == $album) { $album = $this->getSingletonAlbum($parent); } $photo = new Photo(['album_id' => $album->getId(), 'collection_id' => 0, 'user_id' => $poster->getUserId(), 'poster_id' => $poster->getId(), 'poster_type' => $poster->getType(), 'parent_id' => $parent->getId(), 'parent_type' => $parent->getType(), 'parent_user_id' => $parent->getUserId(), 'photo_file_id' => (int) $fileId, 'title' => '', 'content' => '', 'created_at' => KENDO_DATE_TIME, 'modified_at' => KENDO_DATE_TIME]); $photo->setFromArray($params); $photo->save(); $album->setPhotoCount($album->getPhotoCount() + 1); if ($album->getPhotoFileId() == 0) { $album->setPhotoFileId($photo->getPhotoFileId()); } $album->save(); return $photo; }
/** * @param PosterInterface $poster * @param PosterInterface $parent * @param array $params * * @return Group */ public function addGroup(PosterInterface $poster, PosterInterface $parent, $params = []) { $group = new Group(['user_id' => $poster->getUserId(), 'poster_id' => $poster->getId(), 'poster_type' => $poster->getType(), 'parent_id' => $parent->getId(), 'parent_type' => $parent->getType(), 'parent_user_id' => $parent->getUserId(), 'created_at' => KENDO_DATE_TIME, 'modified_at' => KENDO_DATE_TIME]); $group->setFromArray($params); $group->save(); return $group; }
/** * @param PosterInterface $poster * @param PosterInterface $parent * @param array $data * * @return \Platform\Blog\Model\BlogPost */ public function addPost(PosterInterface $poster, PosterInterface $parent, $data = []) { if (empty($data['title']) or empty($data['content'])) { throw new \InvalidArgumentException("Missing parameters [title, content]"); } // truncate description if (empty($data['description'])) { $data['description'] = mb_substr(strip_tags($data['content']), 0, 500); } $data = array_merge(['user_id' => $poster->getUserId(), 'poster_id' => $poster->getId(), 'poster_type' => $poster->getType(), 'parent_id' => $parent->getId(), 'parent_type' => $parent->getType(), 'parent_user_id' => $parent->getUserId(), 'created_at' => KENDO_DATE_TIME, 'modified_at' => KENDO_DATE_TIME, 'module_id' => 'blog'], $data); $post = new BlogPost($data); $post->save(); return $post; }
/** * Add request from poster to parent * * @param string $type * @param PosterInterface $poster * @param PosterInterface $parent * @param ContentInterface $object * * @return \Platform\Invitation\Model\Invitation */ public function addRequest($type, PosterInterface $poster, PosterInterface $parent, ContentInterface $object = null) { $data = ['type_id' => $type, 'poster_id' => $poster->getId(), 'user_id' => $poster->getUserId(), 'parent_id' => $parent->getId(), 'parent_user_id' => $parent->getUserId(), 'poster_type' => $poster->getType(), 'parent_type' => $parent->getType(), 'created_at' => KENDO_DATE_TIME]; if (null != $object) { $data = array_merge($data, ['object_id' => $object->getId(), 'object_type' => $object->getType()]); } $request = new Invitation($data); $request->save(); return $request; }
/** * @param PosterInterface $profile * @param array $names * * @return array */ public function loadValuesForRender(PosterInterface $profile, $names = null) { $fields = $this->getProfileFields($profile->getType()); /** * reduce number of fields to limit how to access point to this values */ if (!empty($names)) { } $storages = []; /** * load macheds contents */ foreach ($fields as $field) { $storages[$field['storage']][] = $field['field_name']; } // has all name by profile type $response = []; foreach ($storages as $storage => $names) { $rows = app()->table($storage)->loadContentValues($profile->getId(), $names); foreach ($rows as $row) { $name = $row->__get('name'); $field = $fields[$name]; if ($field['is_multiple']) { $response[$name][] = ['html' => $row->toHtml(), 'value' => $row->getValue()]; } else { $response[$name] = ['html' => $row->toHtml(), 'value' => $row->getValue()]; } } } return $response; }