Exemplo n.º 1
0
 public static function generateId($length)
 {
     $idExists = true;
     while ($idExists) {
         $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
         $id = '';
         for ($i = 0; $i < $length; $i++) {
             $id .= $chars[rand(0, strlen($chars) - 1)];
         }
         $idExists = ChannelPost::exists(array('id' => $id));
     }
     return $id;
 }
Exemplo n.º 2
0
 public function postMessage($messageContent)
 {
     $post = ChannelPost::create(array('id' => ChannelPost::generateId(6), 'channel_id' => $this->id, 'content' => $messageContent, 'timestamp' => Utils::tps()));
     ChannelAction::create(array('id' => ChannelAction::generateId(6), 'channel_id' => $this->id, 'recipients_ids' => ';' . implode(';', $this->getSubscribedUsersAsList()) . ';', 'type' => 'message', 'target' => $messageContent, 'complementary_id' => $post->id, 'timestamp' => Utils::tps()));
     return $post;
 }
Exemplo n.º 3
0
 public function destroy($id, $request)
 {
     if (Session::isActive()) {
         $user = Session::get();
         if (ChannelPost::exists($id)) {
             $post = ChannelPost::find($id);
             if (UserChannel::find($post->channel_id) && UserChannel::find($post->channel_id)->belongToUser($user->id)) {
                 $post->erase();
             }
         }
     }
     return new Response(200);
 }