public function action() { checkUnauthorizedAccess(); $tweetID = getIdFromURL(); $tweet = TweetRepository::getTweetById($tweetID); $comments = TweetCommentRepository::getTweetComments($tweetID); $main = new Main(); $body = new \templates\ViewTweet(); $body->setTweet($tweet)->setComments($comments); echo $main->setPageTitle("Tweet")->setBody($body); }
/** * Checks if user has permission to comment on tweet. * User can comment tweet only if he is friend with user that posted tweet. * @return true if user has permission to comment tweet */ function checkPermissionToCommentTweet() { $tweetid = getIdFromURL(); $tweet = \Repository\TweetRepository::getTweetById($tweetid); $fromID = $tweet['fromid']; $toid = $tweet['toid']; $currentID = \Repository\UserRepository::getIdByUsername($_SESSION['username']); checkIntValueOfId($tweetid); if ($toid != $currentID) { if (\Repository\FriendRepository::isFriend($currentID, $toid) == null || \Repository\ResctrictionRepository::isBlocked($toid, $currentID) != null) { return false; } } return true; }