/** * Follow something [collection, member, goup] * * @param integer $id ID of the thing being followed * @param string $what What's being followed * @param integer $follower_id ID of the follower * @param string $follower_type Type of the follower [member, group] * @return boolean */ public function follow($id, $what = 'collection', $follower_id = 0, $follower_type = 'member') { $follow = new Following($id, $what, $follower_id, $follower_type); if (!$follow->exists()) { $follow->bind(array('following_id' => $id, 'following_type' => $what, 'follower_id' => $follower_id, 'follower_type' => $follower_type)); if (!$follow->store(true)) { $this->setError($follow->getError()); return false; } } return true; }
/** * Unfollow this collection * * @param integer $follower_id ID of the follower * @param string $follower_type Type of the follower [member, group] * @return boolean */ public function unfollow($follower_id = null, $follower_type = 'member') { $follow = new Following($this->get('id'), 'collection', $follower_id, $follower_type); if (!$follow->exists()) { $this->setError(Lang::txt('Item is not being followed')); return false; } if (!$follow->delete()) { $this->setError($follow->getError()); return false; } return true; }