summaryrefslogtreecommitdiffstats
path: root/lib/class/playlist.class.php
diff options
context:
space:
mode:
authorPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-03-14 20:14:52 +0000
committerPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-03-14 20:14:52 +0000
commit1cb0983ed04c65e06d502ae2ac9ed6d5e31d70dc (patch)
tree54655ff3e692a71a17f1d37cd97374b263557ca1 /lib/class/playlist.class.php
parentef48bf3fbdca2a4d25f5d025f4c6ad23905e5369 (diff)
downloadampache-1cb0983ed04c65e06d502ae2ac9ed6d5e31d70dc.tar.gz
ampache-1cb0983ed04c65e06d502ae2ac9ed6d5e31d70dc.tar.bz2
ampache-1cb0983ed04c65e06d502ae2ac9ed6d5e31d70dc.zip
Cosmetics: remove trailing whitespace
Diffstat (limited to 'lib/class/playlist.class.php')
-rw-r--r--lib/class/playlist.class.php240
1 files changed, 120 insertions, 120 deletions
diff --git a/lib/class/playlist.class.php b/lib/class/playlist.class.php
index 8c4eb7f9..042716b2 100644
--- a/lib/class/playlist.class.php
+++ b/lib/class/playlist.class.php
@@ -24,50 +24,50 @@
* Playlist Class
* This class handles playlists in ampache. it references the playlist* tables
*/
-class Playlist extends database_object {
+class Playlist extends database_object {
/* Variables from the Datbase */
public $id;
public $name;
public $user;
public $type;
- public $genre;
+ public $genre;
public $date;
/* Generated Elements */
public $items = array();
/**
- * Constructor
+ * Constructor
* This takes a playlist_id as an optional argument and gathers the information
- * if not playlist_id is passed returns false (or if it isn't found
+ * if not playlist_id is passed returns false (or if it isn't found
*/
- public function __construct($id) {
+ public function __construct($id) {
$info = $this->get_info($id);
- foreach ($info as $key=>$value) {
- $this->$key = $value;
- }
-
+ foreach ($info as $key=>$value) {
+ $this->$key = $value;
+ }
+
} // Playlist
/**
* build_cache
* This is what builds the cache from the objects
*/
- public static function build_cache($ids) {
-
- if (!count($ids)) { return false; }
+ public static function build_cache($ids) {
- $idlist = '(' . implode(',',$ids) . ')';
+ if (!count($ids)) { return false; }
- $sql = "SELECT * FROM `playlist` WHERE `id` IN $idlist";
- $db_results = Dba::read($sql);
+ $idlist = '(' . implode(',',$ids) . ')';
+
+ $sql = "SELECT * FROM `playlist` WHERE `id` IN $idlist";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- parent::add_to_cache('playlist',$row['id'],$row);
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ parent::add_to_cache('playlist',$row['id'],$row);
+ }
} // build_cache
@@ -76,16 +76,16 @@ class Playlist extends database_object {
* This takes the current playlist object and gussies it up a little
* bit so it is presentable to the users
*/
- public function format() {
+ public function format() {
$this->f_name = truncate_with_ellipsis($this->name,Config::get('ellipse_threshold_title'));
- $this->f_link = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&amp;playlist_id=' . $this->id . '">' . $this->f_name . '</a>';
+ $this->f_link = '<a href="' . Config::get('web_path') . '/playlist.php?action=show_playlist&amp;playlist_id=' . $this->id . '">' . $this->f_name . '</a>';
- $this->f_type = ($this->type == 'private') ? get_user_icon('lock',_('Private')) : '';
+ $this->f_type = ($this->type == 'private') ? get_user_icon('lock',_('Private')) : '';
- $client = new User($this->user);
+ $client = new User($this->user);
- $this->f_user = $client->fullname;
+ $this->f_user = $client->fullname;
} // format
@@ -94,19 +94,19 @@ class Playlist extends database_object {
* This function returns true or false if the current user
* has access to this playlist
*/
- public function has_access() {
-
- if (!Access::check('interface','25')) {
- return false;
- }
- if ($this->user == $GLOBALS['user']->id) {
- return true;
- }
+ public function has_access() {
+
+ if (!Access::check('interface','25')) {
+ return false;
+ }
+ if ($this->user == $GLOBALS['user']->id) {
+ return true;
+ }
else {
- return Access::check('interface','100');
- }
+ return Access::check('interface','100');
+ }
- return false;
+ return false;
} // has_access
@@ -115,17 +115,17 @@ class Playlist extends database_object {
* Returns the single item on the playlist and all of it's information, restrict
* it to this Playlist
*/
- public function get_track($track_id) {
+ public function get_track($track_id) {
- $track_id = Dba::escape($track_id);
- $playlist_id = Dba::escape($this->id);
+ $track_id = Dba::escape($track_id);
+ $playlist_id = Dba::escape($this->id);
$sql = "SELECT * FROM `playlist_data` WHERE `id`='$track_id' AND `playlist`='$playlist_id'";
$db_results = Dba::read($sql);
$row = Dba::fetch_assoc($db_results);
- return $row;
+ return $row;
} // get_track
@@ -134,15 +134,15 @@ class Playlist extends database_object {
* This returns an array of playlist songs that are in this playlist. Because the same
* song can be on the same playlist twice they are key'd by the uid from playlist_data
*/
- public function get_items() {
+ public function get_items() {
- $results = array();
+ $results = array();
$sql = "SELECT `id`,`object_id`,`object_type`,`track` FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`";
$db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id'],'track'=>$row['track'],'track_id'=>$row['id']);
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id'],'track'=>$row['track'],'track_id'=>$row['id']);
} // end while
return $results;
@@ -153,17 +153,17 @@ class Playlist extends database_object {
* get_random_items
* This is the same as before but we randomize the buggers!
*/
- public function get_random_items($limit='') {
+ public function get_random_items($limit='') {
- $results = array();
+ $results = array();
- $limit_sql = $limit ? 'LIMIT ' . intval($limit) : '';
+ $limit_sql = $limit ? 'LIMIT ' . intval($limit) : '';
- $sql = "SELECT `object_id`,`object_type` FROM `playlist_data` " .
- "WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY RAND() $limit_sql";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `object_id`,`object_type` FROM `playlist_data` " .
+ "WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY RAND() $limit_sql";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
+ while ($row = Dba::fetch_assoc($db_results)) {
$results[] = array('type'=>$row['object_type'],'object_id'=>$row['object_id']);
} // end while
@@ -177,21 +177,21 @@ class Playlist extends database_object {
* This is called by the batch script, because we can't pass in Dynamic objects they pulled once and then their
* target song.id is pushed into the array
*/
- function get_songs() {
+ function get_songs() {
$results = array();
$sql = "SELECT * FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track`";
$db_results = Dba::read($sql);
- while ($r = Dba::fetch_assoc($db_results)) {
- if ($r['dyn_song']) {
+ while ($r = Dba::fetch_assoc($db_results)) {
+ if ($r['dyn_song']) {
$array = $this->get_dyn_songs($r['dyn_song']);
$results = array_merge($array,$results);
}
- else {
+ else {
$results[] = $r['object_id'];
- }
+ }
} // end while
@@ -204,7 +204,7 @@ class Playlist extends database_object {
* This simply returns a int of how many song elements exist in this playlist
* For now let's consider a dyn_song a single entry
*/
- public function get_song_count() {
+ public function get_song_count() {
$sql = "SELECT COUNT(`id`) FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "'";
$db_results = Dba::read($sql);
@@ -220,19 +220,19 @@ class Playlist extends database_object {
* This returns the specified users playlists as an array of
* playlist ids
*/
- public static function get_users($user_id) {
+ public static function get_users($user_id) {
- $user_id = Dba::escape($user_id);
- $results = array();
+ $user_id = Dba::escape($user_id);
+ $results = array();
- $sql = "SELECT `id` FROM `playlist` WHERE `user`='$user_id' ORDER BY `name`";
- $db_results = Dba::read($sql);
+ $sql = "SELECT `id` FROM `playlist` WHERE `user`='$user_id' ORDER BY `name`";
+ $db_results = Dba::read($sql);
- while ($row = Dba::fetch_assoc($db_results)) {
- $results[] = $row['id'];
- }
+ while ($row = Dba::fetch_assoc($db_results)) {
+ $results[] = $row['id'];
+ }
- return $results;
+ return $results;
} // get_users
@@ -240,24 +240,24 @@ class Playlist extends database_object {
* update
* This function takes a key'd array of data and runs updates
*/
- public function update($data) {
+ public function update($data) {
- if ($data['name'] != $this->name) {
- $this->update_name($data['name']);
- }
- if ($data['pl_type'] != $this->type) {
- $this->update_type($data['pl_type']);
- }
+ if ($data['name'] != $this->name) {
+ $this->update_name($data['name']);
+ }
+ if ($data['pl_type'] != $this->type) {
+ $this->update_type($data['pl_type']);
+ }
} // update
/**
* update_type
- * This updates the playlist type, it calls the generic update_item function
+ * This updates the playlist type, it calls the generic update_item function
*/
- private function update_type($new_type) {
+ private function update_type($new_type) {
- if ($this->_update_item('type',$new_type,'50')) {
+ if ($this->_update_item('type',$new_type,'50')) {
$this->type = $new_type;
}
@@ -267,9 +267,9 @@ class Playlist extends database_object {
* update_name
* This updates the playlist name, it calls the generic update_item function
*/
- private function update_name($new_name) {
+ private function update_name($new_name) {
- if ($this->_update_item('name',$new_name,'50')) {
+ if ($this->_update_item('name',$new_name,'50')) {
$this->name = $new_name;
}
@@ -279,10 +279,10 @@ class Playlist extends database_object {
* _update_item
* This is the generic update function, it does the escaping and error checking
*/
- private function _update_item($field,$value,$level) {
+ private function _update_item($field,$value,$level) {
- if ($GLOBALS['user']->id != $this->user AND !Access::check('interface',$level)) {
- return false;
+ if ($GLOBALS['user']->id != $this->user AND !Access::check('interface',$level)) {
+ return false;
}
$value = Dba::escape($value);
@@ -298,14 +298,14 @@ class Playlist extends database_object {
* update_track_number
* This takes a playlist_data.id and a track (int) and updates the track value
*/
- public function update_track_number($track_id,$track) {
+ public function update_track_number($track_id,$track) {
- $playlist_id = Dba::escape($this->id);
- $track_id = Dba::escape($track_id);
- $track = Dba::escape($track);
+ $playlist_id = Dba::escape($this->id);
+ $track_id = Dba::escape($track_id);
+ $track = Dba::escape($track);
- $sql = "UPDATE `playlist_data` SET `track`='$track' WHERE `id`='$track_id' AND `playlist`='$playlist_id'";
- $db_results = Dba::write($sql);
+ $sql = "UPDATE `playlist_data` SET `track`='$track' WHERE `id`='$track_id' AND `playlist`='$playlist_id'";
+ $db_results = Dba::write($sql);
} // update_track_number
@@ -315,10 +315,10 @@ class Playlist extends database_object {
* if you want to add a dyn_song you need to use the one shot function
* add_dyn_song
*/
- public function add_songs($song_ids=array(),$ordered=false) {
+ public function add_songs($song_ids=array(),$ordered=false) {
/* We need to pull the current 'end' track and then use that to
- * append, rather then integrate take end track # and add it to
+ * append, rather then integrate take end track # and add it to
* $song->track add one to make sure it really is 'next'
*/
$sql = "SELECT `track` FROM `playlist_data` WHERE `playlist`='" . $this->id . "' ORDER BY `track` DESC LIMIT 1";
@@ -327,24 +327,24 @@ class Playlist extends database_object {
$base_track = $data['track'];
debug_event('add_songs', 'Track number: '.$base_track, '5');
- foreach ($song_ids as $song_id) {
+ foreach ($song_ids as $song_id) {
/* We need the songs track */
$song = new Song($song_id);
-
+
// Based on the ordered prop we use track + base or just $i++
- if (!$ordered) {
+ if (!$ordered) {
$track = Dba::escape($song->track+$base_track);
- }
- else {
- $i++;
- $track = Dba::escape($base_track+$i);
- }
+ }
+ else {
+ $i++;
+ $track = Dba::escape($base_track+$i);
+ }
$id = Dba::escape($song->id);
$pl_id = Dba::escape($this->id);
/* Don't insert dead songs */
- if ($id) {
- $sql = "INSERT INTO `playlist_data` (`playlist`,`object_id`,`object_type`,`track`) " .
+ if ($id) {
+ $sql = "INSERT INTO `playlist_data` (`playlist`,`object_id`,`object_type`,`track`) " .
" VALUES ('$pl_id','$id','song','$track')";
$db_results = Dba::write($sql);
} // if valid id
@@ -358,14 +358,14 @@ class Playlist extends database_object {
* This function creates an empty playlist, gives it a name and type
* Assumes $GLOBALS['user']->id as the user
*/
- public static function create($name,$type) {
+ public static function create($name,$type) {
$name = Dba::escape($name);
$type = Dba::escape($type);
$user = Dba::escape($GLOBALS['user']->id);
$date = time();
- $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`date`) " .
+ $sql = "INSERT INTO `playlist` (`name`,`user`,`type`,`date`) " .
" VALUES ('$name','$user','$type','$date')";
$db_results = Dba::write($sql);
@@ -379,7 +379,7 @@ class Playlist extends database_object {
* set_items
* This calles the get_items function and sets it to $this->items which is an array in this object
*/
- function set_items() {
+ function set_items() {
$this->items = $this->get_items();
@@ -391,7 +391,7 @@ class Playlist extends database_object {
* and numbers them in a liner fashion, not allowing for
* the same track # twice, this is an optional funcition
*/
- public function normalize_tracks() {
+ public function normalize_tracks() {
/* First get all of the songs in order of their tracks */
$sql = "SELECT `id` FROM `playlist_data` WHERE `playlist`='" . Dba::escape($this->id) . "' ORDER BY `track` ASC";
@@ -400,7 +400,7 @@ class Playlist extends database_object {
$i = 1;
$results = array();
- while ($r = Dba::fetch_assoc($db_results)) {
+ while ($r = Dba::fetch_assoc($db_results)) {
$new_data = array();
$new_data['id'] = $r['id'];
$new_data['track'] = $i;
@@ -408,8 +408,8 @@ class Playlist extends database_object {
$i++;
} // end while results
- foreach($results as $data) {
- $sql = "UPDATE `playlist_data` SET `track`='" . $data['track'] . "' WHERE" .
+ foreach($results as $data) {
+ $sql = "UPDATE `playlist_data` SET `track`='" . $data['track'] . "' WHERE" .
" `id`='" . $data['id'] . "'";
$db_results = Dba::write($sql);
} // foreach re-ordered results
@@ -417,42 +417,42 @@ class Playlist extends database_object {
return true;
} // normalize_tracks
-
+
/**
* delete_track
* this deletes a single track, you specify the playlist_data.id here
*/
- public function delete_track($id) {
+ public function delete_track($id) {
- $this_id = Dba::escape($this->id);
- $id = Dba::escape($id);
-
- $sql = "DELETE FROM `playlist_data` WHERE `playlist_data`.`playlist`='$this_id' AND `playlist_data`.`id`='$id' LIMIT 1";
- $db_results = Dba::write($sql);
+ $this_id = Dba::escape($this->id);
+ $id = Dba::escape($id);
- return true;
+ $sql = "DELETE FROM `playlist_data` WHERE `playlist_data`.`playlist`='$this_id' AND `playlist_data`.`id`='$id' LIMIT 1";
+ $db_results = Dba::write($sql);
+
+ return true;
- } // delete_track
+ } // delete_track
/**
* delete
* This deletes the current playlist and all assoicated data
*/
- public function delete() {
+ public function delete() {
+
+ $id = Dba::escape($this->id);
- $id = Dba::escape($this->id);
-
$sql = "DELETE FROM `playlist_data` WHERE `playlist` = '$id'";
$db_results = Dba::write($sql);
$sql = "DELETE FROM `playlist` WHERE `id`='$id'";
$db_results = Dba::write($sql);
- $sql = "DELETE FROM `object_count` WHERE `object_type`='playlist' AND `object_id`='$id'";
- $db_results = Dba::write($sql);
-
+ $sql = "DELETE FROM `object_count` WHERE `object_type`='playlist' AND `object_id`='$id'";
+ $db_results = Dba::write($sql);
+
return true;
-
+
} // delete
} // class Playlist