Exemplo n.º 1
0
 /**
  * Function displayView load the playlist default template file
  * @return void
  */
 public function displayView()
 {
     $userId = !empty($this->playlistUserId) ? $this->playlistUserId : '';
     if ($userId == '') {
         $userId = get_current_user_id();
     }
     $this->playlistId = isset($_REQUEST['pid']) && $_REQUEST['pid'] != '' ? intval($_REQUEST['pid']) : '';
     if (!empty($this->playlistId) && !empty($userId)) {
         $startOffset = 0;
         $this->videoDetails = getPlaylistVideoDetails($userId, $this->playlistId, $startOffset, $this);
         $this->playlistName = getPlaylistName($userId, $this->playlistId, $this);
     } elseif (empty($this->playlistId) && !empty($userId)) {
         $startOffset = 0;
         $this->playlistDetails = getPlaylistDetails($userId, $startOffset, $this);
         $this->playlistCount = getTotalPlaylistCount($userId, $this);
     } else {
         echo 'login';
     }
     $this->displayTemplate();
 }
Exemplo n.º 2
0
 /**
  * Function createPlaylist is used to create new playlist
  * This function has userId to hold current user id
  * This function has videoId to hold video id
  * This function has playlistName to hold playlist name
  * This function has playlistLimit to hold playlist name
  * This function has playlistCount to hold total playlist count of current user
  * This function has checkPlaylist to hold playlist name to check whether playlist name exists or not
  * This function insert new playlist on playlist table
  * This function insert new video on newly created playlist
  * This function has exit statement to stop flow
  * @param int $userId user id
  * @param int $videoId video id
  * @param string $playlistName playlist name
  * @return array
  */
 public function createPlaylist($userId, $videoId, $playlistName)
 {
     global $wpdb;
     $serializedPlaylistLimit = unserialize($wpdb->get_var($wpdb->prepare('SELECT player_colors FROM ' . $this->settingsTable, '')));
     if (!empty($serializedPlaylistLimit['playlist_count'])) {
         $playlistLimit = $serializedPlaylistLimit['playlist_count'];
     } else {
         $playlistLimit = 5;
     }
     $playlistCount = getTotalPlaylistCount($userId, $this);
     if ($playlistCount >= $playlistLimit) {
         echo json_encode(array('checkResult' => false, 'status' => 'limit'));
         exitAction('');
     }
     $checkPlaylist = $wpdb->get_var($wpdb->prepare('SELECT playlist_name FROM ' . $this->userPlaylistTable . ' WHERE userid=%d AND playlist_name=%s', $userId, $playlistName));
     if (empty($checkPlaylist)) {
         $data = array('userid' => $userId, 'playlist_name' => $playlistName);
         $format = array('%d', '%s');
         $result = $wpdb->insert($this->userPlaylistTable, $data, $format);
     } else {
         echo json_encode(array('checkResult' => false, 'status' => 'exist'));
         exitAction('');
     }
     $playlistId = $wpdb->insert_id;
     if ($result) {
         $this->insertPlaylistVideo($userId, $videoId, $playlistId);
     } else {
         echo json_encode(array('checkResult' => false));
         exitAction('');
     }
 }