public static function sendNew($sender, $conversation, $content, $timeOffset = 0) { $id = Message::generateId(6); $timestamp = Utils::tps() + $timeOffset; $message = Message::create(array('id' => $id, 'sender_id' => $sender, 'conversation_id' => $conversation, 'content' => $content, 'timestamp' => $timestamp)); $recep = array(); $members = explode(';', trim(Conversation::find($conversation)->members_ids, ';')); foreach ($members as $id) { if ($id != $sender) { $recep[] = trim(UserChannel::find($id)->admins_ids, ';'); } } $recep = ';' . implode(';', $recep) . ';'; $recep = ChannelAction::filterReceiver($recep, "pm"); ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => userChannel::find($sender)->id, 'recipients_ids' => $recep, 'type' => 'pm', 'target' => $conversation, 'timestamp' => $timestamp)); return $message; }
public static function postNew($authorId, $videoId, $commentContent, $parent) { $timestamp = Utils::tps(); $poster_channel = UserChannel::find(Video::find($videoId)->poster_id); $admins_ids = $poster_channel->admins_ids; $admins_ids = ChannelAction::filterReceiver($admins_ids, "comment"); $admin_ids_array = $poster_channel->getArrayAdminsIds($admins_ids); foreach ($admin_ids_array as $k => $value) { if ($value == Session::get()->id) { unset($admin_ids_array[$k]); break; } } $recipients_ids = ';' . trim(implode(';', $admin_ids_array), ';') . ';'; $comment = Comment::create(array('id' => Comment::generateId(6), 'poster_id' => $authorId, 'video_id' => $videoId, 'comment' => $commentContent, 'likes' => 0, 'dislikes' => 0, 'timestamp' => $timestamp, 'parent' => $parent)); ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $authorId, 'recipients_ids' => $recipients_ids, 'type' => 'comment', 'target' => $videoId, 'complementary_id' => $comment->id, 'timestamp' => $timestamp)); return $comment; }
public static function sendUploadNotification($videoId, $channelId) { ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $channelId, 'recipients_ids' => ChannelAction::filterReceiver(';' . implode(';', Subscription::getSubscribersFromChannelAsList($channelId)) . ';', "upload"), 'type' => 'upload', 'target' => $videoId, 'timestamp' => Utils::tps())); }
public function update($id, $request) { $req = $request->getParameters(); if (!Session::isActive()) { return Utils::getUnauthorizedResponse(); } if ($video = Video::find($id)) { if (isset($req['video-edit-submit'], $req['video-title'], $req['video-description'], $req['video-tags'])) { $data = array(); $data['currentPageTitle'] = $video->title . ' - Modification'; if (UserChannel::find(Video::find($id)->poster_id)->belongToUser(Session::get()->id) || Session::get()->isModerator() || Session::get()->isAdmin()) { $data['video'] = $video; $title = $req['video-title']; $description = $req['video-description']; $tags = $req['video-tags']; $visibility = $req['video-visibility']; if (Utils::validateVideoInfo($title, $description, $tags) && in_array($visibility, array(0, 1, 2))) { $video->updateInfo($title, $description, $tags, $req['_FILES_']['tumbnail'], $visibility); $data['video'] = $video; $response = new ViewResponse('video/edit', $data); $response->addMessage(ViewMessage::success('Votre video a bien été modifiée !')); return $response; } else { $response = new ViewResponse('video/edit', $data); $response->addMessage(ViewMessage::error('Les informations ne sont pas valides.')); return $response; } } } else { if (isset($req['flag']) && !empty($req['flag'])) { $flag = $req['flag']; if ($flag == 'false' && (Session::get()->isModerator() || Session::get()->isAdmin())) { $video->unFlag(Session::get()->id); return new Response(200); } else { if ($flag == 'true') { $video->flag(Session::get()->id); return new Response(200); } } } else { if (isset($req['suspend']) && !empty($req['suspend']) && (Session::get()->isModerator() || Session::get()->isAdmin())) { $suspend = $req['suspend']; if ($suspend == 'false') { $video->unSuspend(Session::get()->id); return new Response(200); } else { if ($suspend == 'true') { $video->suspend(Session::get()->id); return new Response(200); } } } else { if (isset($req['like'])) { $userId = Session::get()->id; if (!$video->isLikedByUser($userId)) { if ($video->isDislikedByUser($userId)) { $video->removeDislike($userId); } $video->like($userId); return new Response(200); } } else { if (isset($req['dislike'])) { $userId = Session::get()->id; if (!$video->isDislikedByUser($userId)) { if ($video->isLikedByUser($userId)) { $video->removeLike($userId); } $video->dislike($userId); return new Response(200); } } else { if (isset($req['unlike'])) { $userId = Session::get()->id; if ($video->isLikedByUser($userId)) { $video->removeLike($userId); return new Response(200); } } else { if (isset($req['undislike'])) { $userId = Session::get()->id; if ($video->isDislikedByUser($userId)) { $video->removeDislike($userId); return new Response(200); } } else { if (isset($req['discover']) && (Session::get()->isModerator() || Session::get()->isAdmin())) { $video->discover = Utils::tps(); $video->save(); $author = $video->getAuthor(); $receiver = ChannelAction::filterReceiver($author->admins_ids, "staff_select"); ChannelAction::create(['id' => ChannelAction::generateId(6), 'channel_id' => $author->id, 'recipients_ids' => $receiver, 'type' => 'staff_select', 'target' => $video->id, 'timestamp' => Utils::tps()]); return new Response(200); } } } } } } } } } return new Response(500); }
public function unsubscribe($subscriber) { Subscription::unsubscribeUserFromChannel($subscriber, $this); $unsubscriberUser = User::find_by_id($subscriber); $unsubscribingChannel = $this; $channel_id = $this->id; ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $unsubscriberUser->getMainChannel()->id, 'recipients_ids' => ChannelAction::filterReceiver($unsubscribingChannel->admins_ids, "unsubscription"), 'type' => 'unsubscription', 'target' => $channel_id, 'timestamp' => Utils::tps())); }