/** * @param ContentInterface $content * @param int $limit * * @return array */ public function loadPeople(ContentInterface $content, $limit = null) { $select = app()->table('platform_tag_people')->select()->where('content_id=?', $content->getId()); if ($limit) { $select->limit($limit, 0); } $pairs = $select->toPairs('poster_id', 'poster_type'); $idList = []; foreach ($pairs as $id => $type) { $idList[$type][] = $id; } foreach ($idList as $type => $list) { foreach (app()->table($type)->findByIdList($list) as $item) { if ($item instanceof PosterInterface) { $id = $item->getId(); $pairs[$id] = $item; } } } foreach ($pairs as $id => $item) { if (is_string($item)) { unset($pairs[$id]); } } return $pairs; }
/** * @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; }
/** * 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 ContentInterface $about * @param PosterInterface $viewer * * @return string */ public function getPrivacyLabel(ContentInterface $about, PosterInterface $viewer = null) { $isOwner = false; /** * Is poster of content */ if ($about->viewerIsParent()) { $isOwner = true; } $relationType = $about->getPrivacyType(); $parentType = $about->getParentType(); if ($relationType < RELATION_TYPE_CUSTOM) { switch ($relationType) { case RELATION_TYPE_ANYONE: $msgId = 'relation.privacy_label_public'; break; case RELATION_TYPE_OWNER: $msgId = 'relation.' . $parentType . '_privacy_label_owner'; break; case RELATION_TYPE_MEMBER_OF_MEMBER: $msgId = 'relation.' . $parentType . '_privacy_label_member_of_members'; break; case RELATION_TYPE_ADMIN: $msgId = 'relation.' . $parentType . '_privacy_label_admin'; break; case RELATION_TYPE_EDITOR: $msgId = 'relation.' . $parentType . '_privacy_label_editor'; break; case RELATION_TYPE_MEMBER: $msgId = 'relation.' . $parentType . '_privacy_label_member'; break; case RELATION_TYPE_REGISTERED: $msgId = 'relation.' . $parentType . '_privacy_label_registered'; break; default: $msgId = 'relation.' . $parentType . '_privacy_label_custom'; } } if (empty($msgId)) { $relationId = $about->getPrivacyValue(); $item = $this->findById($relationId); if ($item) { $msgId = $item->getRelationTitle(); } } if (empty($msgId)) { $msgId = 'relation.' . $about->getParentType() . '_privacy_label_custom'; } /** * */ $parent = $about->getParent(); if ($isOwner) { return app()->text($msgId, ['$parent\'s' => 'Your', '$parent' => 'You']); } $label = $parent->getTitle(); return app()->text($msgId, ['$parent' => $label]); }
/** * @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>'; }
/** * Check privacy control * * @param ContentInterface $content * @param string $action etc: activity.comment, blog.view, activity.like, activity.follow * * @return bool */ public function check(ContentInterface $content, $action) { $viewerId = app()->auth()->getId(); $parentId = $content->getParentId(); $isRegistered = $viewerId > 0; list($type, $value) = $content->getPrivacy($action); if ($this->debug) { echo sprintf('[%s,%s,%s]', $action, $type, $value); } if (!$isRegistered) { return $type == RELATION_TYPE_ANYONE; } /** * always */ if (in_array($type, [RELATION_TYPE_ANYONE, RELATION_TYPE_REGISTERED])) { return true; } /** * Check match user id */ if ($content->viewerIsPoster()) { return true; } /** * load relation between theme. */ $list = app()->relation()->getListRelationIdBetween($parentId, $viewerId); /** * check membership of viewer & content */ if (!empty($list[$value])) { return true; } /** * check membership member of members. it's hard to check theme. */ if (RELATION_TYPE_MEMBER_OF_MEMBER == $type) { return app()->relation()->isMemberOfMember($parentId, $viewerId); } return false; }
/** * @param ContentInterface $about * @param int $limit * @param int $offset * * @return array */ public function getListSubscriber($about, $limit = 100, $offset = 0) { return app()->table('platform_notification_subscribe')->select()->where('about_id=?', $about->getId())->limit($limit, $offset)->order('created_at', 1)->all(); }
/** * @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; }
/** * @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 ContentInterface $about * * @return array */ public function loadAboutBundles(ContentInterface $about) { $limitCommentCount = 3; $remainCommentCount = 0; $poster = app()->auth()->getViewer(); $commentService = app()->commentService(); $likeService = app()->likeService(); if ($about instanceof ContentInterface) { if ($about->getCommentCount() > $limitCommentCount) { $remainCommentCount = $about->getCommentCount() - $limitCommentCount; } } $place = null; $story = null; $people = null; $shareCount = null; $story = $about->getStory(); $people = $this->decorateTagPeople($about->getPeople()); $place = $about->getPlace(); $shareCount = $about->getShareCount(); return ['place' => $place, 'hasStory' => !empty($story), 'story' => $story, 'people' => $people, 'hasAttachment' => !$about instanceof FeedStatus, 'attachmentId' => $about->getId(), 'about' => $about, 'shareCount' => $shareCount, 'poster' => $about->getPoster(), 'commentList' => $commentService->getCommentList($about, 0, 0, $limitCommentCount), 'limitCommentCount' => $limitCommentCount, 'remainCommentCount' => $remainCommentCount, 'like' => $likeService->getLikeResult($poster, $about, 2)]; }