/**
  * @param ContentInterface $content
  * @param array            $people
  *
  * @return int total number of people tagedContentInterface
  * @throws \Exception
  */
 public function tagPeople(ContentInterface $content, $people)
 {
     $idList = [];
     foreach ($people as $poster) {
         if (is_string($poster)) {
             list($id, $type) = explode('@', $poster);
             $idList[$type][] = $id;
         }
     }
     $table = app()->table('platform_tag_people');
     //delete all tags.
     $table->delete()->where('content_id=?', $content->getId())->execute();
     if (empty($idList)) {
         return 0;
     }
     $peopleCount = 0;
     foreach ($idList as $type => $list) {
         try {
             foreach (app()->table($type)->findByIdList($list) as $poster) {
                 if ($poster instanceof PosterInterface) {
                     $people = new TagPeople(['content_id' => $content->getId(), 'content_type' => $content->getType(), 'poster_id' => $poster->getId(), 'poster_type' => $poster->getType()]);
                     $people->save();
                     ++$peopleCount;
                 }
             }
         } catch (\Exception $e) {
             throw $e;
         }
     }
     return $peopleCount;
 }
 /**
  * @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;
 }
 /**
  * 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 \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 string           $feedType
  * @param ContentInterface $about
  * @param array            $params
  *
  * @return Feed
  * @throws \InvalidArgumentException
  */
 public function addItemFeed($feedType, ContentInterface $about, $params = [])
 {
     list($privacyType, $privacyValue) = $about->getPrivacy('view');
     $poster = app()->find($about->getPosterType(), $about->getPosterId());
     $parent = app()->find($about->getParentType(), $about->getParentId());
     $story = null;
     $hashtag = null;
     $peopletag = null;
     $story = $about->getStory();
     $peopletag = $about->getPeople();
     if (!empty($story)) {
         $hashtag = $this->getHashTagsInStory($story);
     }
     // parse story content to load hash tags.
     $feed = new Feed(['feed_type' => $feedType, 'poster_id' => $about->getPosterId(), 'poster_type' => $about->getPosterType(), 'parent_id' => $about->getParentId(), 'parent_type' => $about->getParentType(), 'about_id' => $about->getId(), 'about_type' => $about->getType(), 'privacy_type' => (int) $privacyType, 'privacy_value' => (int) $privacyValue, 'created_at' => KENDO_DATE_TIME, 'params_text' => json_encode($params)]);
     $feed->save();
     $feed->validate(true, false);
     /**
      * add feed to hashtag list
      */
     if (!empty($hashtag)) {
         foreach ($hashtag as $tag) {
             $this->addHashTag($feed, $tag);
         }
     }
     $this->putFeedToStream($feed, $poster, $parent, $peopletag);
     app()->notificationService()->subscribe($poster, $about);
     return $feed;
 }