/** * @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 ContentInterface $object * * @return bool */ public function remove(PosterInterface $poster, ContentInterface $object) { $review = $this->findReview($poster->getId(), $object->getId()); if (null != $review) { $review->delete(); } return false; }
/** * @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 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; }
/** * @param PosterInterface $item * * @return string */ public function __invoke($item) { if (!$item instanceof PosterInterface) { return ''; } if (!app()->auth()->logged()) { return ''; } if (!app()->aclService()->authorizeFor(app()->auth()->getUser(), 'is_admin')) { return ''; } if (app()->auth()->getId() == $item->getId()) { return ''; } return app()->viewHelper()->partial('platform/user/button/login-as', ['item' => $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; }
/** * Remove all like entry match `poster_id`. * TODO: How to update `comment_count` * * @param PosterInterface $poster */ public function removeAllByPoster(PosterInterface $poster) { app()->table('platform_comment')->delete()->where('poster_id=?', $poster->getId())->orWhere('user_id=?', $poster->getId())->orWhere('parent_id=?', $poster->getId())->orWhere('parent_user_id=?', $poster->getId())->execute(); }
/** * @param CatalogInterface|PosterInterface $item * @param $data */ public function updateItemAttribute($item, $data = []) { $catalogId = $item->getCatalogId(); if (!$catalogId) { return; } $form = $this->getInternalFormByCatalogId($catalogId); $form->setData($data); $atTable = $item->getAttributeValueTable(); $atTable->delete()->where('item_id=?', $item->getId())->execute(); $maps = []; foreach ($form->getElements() as $element) { if (!$element instanceof FormField) { continue; } $fieldId = $element->getFieldId(); if (!$fieldId) { continue; } $maps[$fieldId] = $element->getValue(); } foreach ($maps as $fieldId => $value) { $entry = $atTable->fetchNew(['item_id' => $item->getId(), 'field_id' => $fieldId, 'value' => $value]); $entry->save(); } }
/** * @param PosterInterface $parent * * @return \Kendo\Db\SqlSelect */ public function getSelectMembershipForParent(PosterInterface $parent) { $relationId = $parent->getId(); return app()->table('platform_relation_item')->select()->where('relation_id=?', $relationId); }
/** * @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 $parent * @param $action * @param bool|true $defaultValue * * @return bool */ public function authorizeFor(PosterInterface $parent = null, $action, $defaultValue = true) { if (!$this->_authorize($roleId = null != $parent ? $parent->getRoleId() : KENDO_GUEST_ROLE_ID, $action, $defaultValue)) { return false; } return true; }
/** * @param PosterInterface $poster * * @return \Kendo\Db\SqlSelect */ public function getConversationIdForPoster(PosterInterface $poster) { return app()->table('platform_message_recipient')->select()->where('recipient_id=?', $poster->getId()); }
/** * @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 $objectId * * @return int */ public function getLikeStatus(PosterInterface $poster = null, $objectId) { if (null == $poster || empty($objectId)) { return self::NOT_LIKE; } $result = app()->table('platform_like')->select()->where('poster_id=?', $poster->getId())->where('about_id = ?', $objectId)->fields('about_id'); if ($result) { return self::IS_LIKED; } return self::NOT_LIKE; }
/** * Send notify to members subscribed to about since item is created. * + How to store and broadcast a message to 1M members. ? * + A better way we design a schema like group chat? * + Push notification only ? * + How many notification we should send out each time? * * @param string $type * @param PosterInterface $poster * @param mixed $about * @param array $params * */ public function notify($type, $poster, $about, $params = []) { foreach ($this->getListSubscriber($about, 100, 0) as $subscribe) { if (!$subscribe instanceof NotificationSubscribe) { continue; } $receiver = $subscribe->getPoster(); if (!$receiver instanceof PosterInterface) { continue; } // do not notify to poster if ($poster->getId() == $receiver->getId()) { continue; } $this->addNotification($type, $poster, $receiver, $about, $params); } }
/** * @param PosterInterface $poster */ public function removeAllByPoster($poster) { app()->table('platform_follow')->delete()->where('parent_id=?', $poster->getId())->orWhere('poster_id=?', $poster->getId())->execute(); }
/** * @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 * @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 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; }
/** * @param \Kendo\Content\PosterInterface|\Kendo\Content\ContentInterface $item * * @return string */ public function toLink($item) { if (!$item) { return ''; } return '<a href="' . $item->toHref() . '">' . $item->getTitle() . '</a>'; }
/** * @param ContentInterface|PosterInterface $item * * @return bool */ public function isParent($item) { if (!$this->logged()) { return false; } return (bool) array_intersect([$this->getId(), $this->getUserId()], [$item->getId(), $item->getParentId(), $item->getParentUserId()]); }
/** * @param PosterInterface $parent * * @return string */ public function requestMembershipType($parent) { return sprintf('request_membership_%s', $parent->getModuleName()); }
/** * @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; }