null, ]; $options += $defaults; $this->pdo = ($options['Settings'] instanceof Settings ? $options['Settings'] : new Settings()); } /** * When a user wants to add a show to "my shows" insert it into the user series table. * * @param int $uID ID of user. * @param int $videoId Video ID of tv show. * @param array $catID List of category ID's * * @return bool|int */ public function addShow($uID, $videoId, $catID = []) { return $this->pdo->queryInsert( sprintf( "INSERT INTO userseries (userid, videos_id, categoryid, createddate) VALUES (%d, %d, %s, NOW())", $uID, $videoId, (!empty($catID) ? $this->pdo->escapeString(implode('|', $catID)) : "NULL") ) ); } /** * Get all the user's "my shows". * * @param int $uID ID of user. * * @return array */ public function getShows($uID) { return $this->pdo->query( sprintf(" SELECT us.*, v.title FROM userseries us INNER JOIN videos v ON v.id = us.videos_id WHERE userid = %d ORDER BY v.title ASC", $uID ) ); } /** * Delete a tv show from the user's "my shows". * * @param int $uID ID of user. * @param int $videoId ID of tv show. */ public function delShow($uID, $videoId) { $this->pdo->queryExec( sprintf( "DELETE FROM userseries WHERE userid = %d AND videos_id = %d", $uID, $videoId ) ); } /** * Get tv show information for a user. * * @param int $uID ID of the user. * @param int $videoId ID of the TV show. * * @return array|bool */ public function getShow($uID, $videoId) { return $this->pdo->queryOneRow( sprintf(" SELECT us.*, v.title FROM userseries us LEFT OUTER JOIN videos v ON v.id = us.videos_id WHERE us.userid = %d AND us.videos_id = %d", $uID, $videoId ) ); } /** * Delete all shows from the user's "my shows". * * @param int $uID ID of the user. */ public function delShowForUser($uID) { $this->pdo->queryExec( sprintf( "DELETE FROM userseries WHERE userid = %d", $uID ) ); } /** * Delete TV shows from all user's "my shows" that match a TV id. * * @param int $videoId The ID of the TV show. */ public function delShowForSeries($videoId) { $this->pdo->queryExec( sprintf( "DELETE FROM userseries WHERE videos_id = %d", $videoId ) ); } /** * Update a TV show category ID for a user's "my show" TV show. * * @param int $uID ID of the user. * @param int $videoId ID of the TV show. * @param array $catID List of category ID's. */ public function updateShow($uID, $videoId, $catID = []) { $this->pdo->queryExec( sprintf( "UPDATE userseries SET categoryid = %s WHERE userid = %d AND videos_id = %d", (!empty($catID) ? $this->pdo->escapeString(implode('|', $catID)) : "NULL"), $uID, $videoId ) ); } }