Beispiel #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 = Playlist::exists(array('id' => $id));
     }
     return $id;
 }
 public static function checkOwner($user, $rule)
 {
     $rule = false;
     $playList = new Playlist();
     $userId = $user->id;
     if (!isset($_GET['id'])) {
         return $rule;
     }
     $playListId = $_GET['id'];
     if ($playList->exists("id={$playListId} AND uid={$userId}")) {
         $rule = true;
     }
     return $rule;
 }
 public function watch($parameters, $request)
 {
     $playlist_id = $parameters[1];
     if (Playlist::exists($playlist_id)) {
         $playlist = Playlist::find($playlist_id);
         if (isset($parameters[3])) {
             $video_id = $parameters[3];
         } else {
             $video_id = json_decode($playlist->videos_ids);
             if (isset($video_id[0])) {
                 $video_id = $video_id[0];
             } else {
                 $data = array();
                 $data['playlist'] = $playlist;
                 return new ViewResponse('playlists/error_empty', $data);
             }
         }
         if (in_array($video_id, json_decode($playlist->videos_ids))) {
             $resp = new VideoController();
             return $resp->get($video_id, $request, $playlist);
         } else {
             return new Response(500);
         }
     } else {
         return new Response(500);
     }
 }