public function add($storyId) { $reqData = $this->getDataFromRequestWithJsonFormat(); if (!isset($reqData['UserId']) || intval($reqData['UserId']) <= 0) { $this->sendResponse(array('success' => false, 'message' => 'Invalid user!')); } $userId = intval($reqData['UserId']); if (!isset($reqData['Body']) || empty($reqData['Body'])) { $this->sendResponse(array('success' => false, 'message' => 'Invalid comment content!')); } $body = htmlspecialchars($reqData['Body']); $comment = array('UserId' => $userId, 'StoryId' => $storyId, 'Deep' => 0, 'CreatedDate' => date('Y-m-d H:i:s'), 'Body' => $body); if (isset($reqData['ParentId'])) { $comment['ParentId'] = intval($reqData['ParentId']); $parent = CommentRepository::findCommentById($comment['ParentId']); if ($parent) { $comment['Deep'] = $parent['Deep'] + 1; } } $newId = CommentRepository::save($comment); if ($newId) { $story = StoryRepository::findStoryById($storyId); $activity = array('SenderId' => $userId, 'ReceiverId' => $story['UserId'], 'Type' => ActivityType::CommentStory, 'StoryId' => $storyId, 'CommentId' => $newId, 'CreatedDate' => date('Y-m-d H:i:s')); ActivityRepository::save($activity); $comment['CommentId'] = $newId; $this->sendResponse(array('success' => true, 'comment' => $comment)); } else { $this->sendOperationFailedResult('Comment'); } }
public function followUser($userId) { $reqData = $this->getDataFromRequestWithJsonFormat(); if (!isset($reqData['ReceiverId']) || intval($reqData['ReceiverId']) <= 0) { $this->sendResponse(array('success' => false, 'message' => 'Invalid receiver!')); } $receiverId = intval($reqData['ReceiverId']); $follow = array('SenderId' => $userId, 'ReceiverId' => $receiverId, 'CreatedDate' => date('Y-m-d H:i:s')); $newId = FollowRepository::save($follow); if ($newId) { $activity = array('SenderId' => $userId, 'ReceiverId' => $receiverId, 'Type' => ActivityType::Follow, 'CreatedDate' => date('Y-m-d H:i:s')); ActivityRepository::save($activity); $follow['FollowId'] = $newId; $this->sendResponse(array('success' => true, 'follow' => $follow)); } else { $this->sendOperationFailedResult('Follow'); } }
public function addStoryLike($userId) { $reqData = $this->getDataFromRequestWithJsonFormat(); if (!isset($reqData['StoryId']) || intval($reqData['StoryId']) <= 0) { $this->sendInvalidFieldResult('StoryLike', 'StoryId', 'missing_field'); } $storyId = intval($reqData['StoryId']); $story = StoryRepository::findStoryById($storyId); if (!$story) { $this->sendInvalidFieldResult('StoryLike', 'StoryId', 'missing_field'); } $isLike = intval($reqData['IsLike']); if ($isLike > 0) { $storyLike = StoryLikeRepository::findByUserAndStoryId($userId, $storyId); if ($storyLike) { $this->sendResponse(array('success' => true)); } $storyLikeData = array('UserId' => $userId, 'StoryId' => $storyId, 'CreatedDate' => date('Y-m-d H:i:s')); $newId = StoryLikeRepository::save($storyLikeData); if ($newId) { $activity = array('SenderId' => $userId, 'ReceiverId' => $story['UserId'], 'Type' => ActivityType::LikeStory, 'StoryId' => $storyId, 'CreatedDate' => date('Y-m-d H:i:s')); ActivityRepository::save($activity); $storyLikeData['StoryLikeId'] = $newId; $this->sendResponse(array('success' => true)); } else { $this->sendOperationFailedResult('StoryLike'); } } else { $this->sendResponse(array('success' => StoryLikeRepository::remove($userId, $storyId))); } }