summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-11-24 21:48:22 +0000
committerKarl 'vollmerk' Vollmer <vollmer@ampache.org>2007-11-24 21:48:22 +0000
commit6e299a7f63b5b5f056667dee6788fe4c5626be5f (patch)
treea4e9b70bd393d7dc260b32b347aaec74f2da9409
parent27ba8110cab5b09220a110f0e2f3af026582c9fc (diff)
downloadampache-6e299a7f63b5b5f056667dee6788fe4c5626be5f.tar.gz
ampache-6e299a7f63b5b5f056667dee6788fe4c5626be5f.tar.bz2
ampache-6e299a7f63b5b5f056667dee6788fe4c5626be5f.zip
fixed voting up/down and removal of songs from democratic playlist after playback
-rw-r--r--images/icon_thumb_down.pngbin0 -> 601 bytes
-rw-r--r--images/icon_thumb_up.pngbin0 -> 619 bytes
-rw-r--r--lib/class/democratic.class.php38
-rw-r--r--lib/class/stream.class.php4
-rw-r--r--lib/class/tmpplaylist.class.php31
-rw-r--r--play/index.php7
-rw-r--r--server/democratic.ajax.php23
-rw-r--r--templates/show_democratic_playlist.inc.php4
8 files changed, 63 insertions, 44 deletions
diff --git a/images/icon_thumb_down.png b/images/icon_thumb_down.png
new file mode 100644
index 00000000..3c832d4c
--- /dev/null
+++ b/images/icon_thumb_down.png
Binary files differ
diff --git a/images/icon_thumb_up.png b/images/icon_thumb_up.png
new file mode 100644
index 00000000..2bd16ccf
--- /dev/null
+++ b/images/icon_thumb_up.png
Binary files differ
diff --git a/lib/class/democratic.class.php b/lib/class/democratic.class.php
index 0944dcae..aa908a65 100644
--- a/lib/class/democratic.class.php
+++ b/lib/class/democratic.class.php
@@ -157,6 +157,26 @@ class Democratic extends tmpPlaylist {
} // get_next_object
/**
+ * get_uid_from_object_id
+ * This takes an object_id and an object type and returns the ID for the row
+ */
+ public function get_uid_from_object_id($object_id,$object_type='') {
+
+ $object_id = Dba::escape($object_id);
+ $object_type = $object_type ? Dba::escape($object_type) : 'song';
+ $tmp_id = Dba::escape($this->id);
+
+ $sql = "SELECT `tmp_playlist_data`.`id` FROM `tmp_playlist_data` WHERE `object_type`='$object_type' AND " .
+ "`tmp_playlist`='$tmp_id' AND `object_id`='$object_id'";
+ $db_results = Dba::query($sql);
+
+ $row = Dba::fetch_assoc($db_results);
+
+ return $row['id'];
+
+ } // get_uid_from_object_id
+
+ /**
* vote
* This function is called by users to vote on a system wide playlist
* This adds the specified objects to the tmp_playlist and adds a 'vote'
@@ -167,8 +187,10 @@ class Democratic extends tmpPlaylist {
/* Itterate through the objects if no vote, add to playlist and vote */
foreach ($items as $type=>$object_id) {
+ //FIXME: This is a hack until we fix everything else
+ if (intval($type)) { $type = 'song'; }
if (!$this->has_vote($object_id,$type)) {
- $this->add_vote($object_id,$this->id,$type);
+ $this->add_vote($object_id,$type);
}
} // end foreach
@@ -186,7 +208,7 @@ class Democratic extends tmpPlaylist {
$user_id = Dba::escape($GLOBALS['user']->id);
/* Query vote table */
- $sql = "SELECT tmp_playlist_data.id FROM `user_vote` " .
+ $sql = "SELECT tmp_playlist_data.object_id FROM `user_vote` " .
"INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " .
"WHERE user_vote.user='$user_id' AND tmp_playlist_data.object_type='$type' " .
"AND tmp_playlist_data.object_id='$object_id' " .
@@ -206,10 +228,10 @@ class Democratic extends tmpPlaylist {
* add_vote
* This takes a object id and user and actually inserts the row
*/
- public function add_vote($object_id,$tmp_playlist,$object_type='') {
+ public function add_vote($object_id,$object_type='') {
$object_id = Dba::escape($object_id);
- $tmp_playlist = Dba::escape($tmp_playlist);
+ $tmp_playlist = Dba::escape($this->id);
$object_type = $object_type ? Dba::escape($object_type) : 'song';
/* If it's on the playlist just vote */
@@ -241,14 +263,12 @@ class Democratic extends tmpPlaylist {
* As that's what we'll have most the time, no need to check if they've got an existing
* vote for this, just remove anything that is there
*/
- public function remove_vote($object_id) {
+ public function remove_vote($row_id) {
- $object_id = Dba::escape($object_id);
+ $object_id = Dba::escape($row_id);
$user_id = Dba::escape($GLOBALS['user']->id);
- $sql = "DELETE FROM user_vote USING user_vote INNER JOIN tmp_playlist_data ON tmp_playlist_data.id=user_vote.object_id " .
- "WHERE user='$user_id' AND tmp_playlist_data.object_id='$object_id' " .
- "AND tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "'";
+ $sql = "DELETE FROM `user_vote` WHERE `object_id`='$object_id'";
$db_results = Dba::query($sql);
/* Clean up anything that has no votes */
diff --git a/lib/class/stream.class.php b/lib/class/stream.class.php
index 9aa1f76a..09f3cf8a 100644
--- a/lib/class/stream.class.php
+++ b/lib/class/stream.class.php
@@ -471,8 +471,8 @@ class Stream {
*/
public function create_democratic() {
- $tmp_playlist = Democratic::get_current_playlist();
- $tmp_playlist->vote($this->songs);
+ $democratic = Democratic::get_current_playlist();
+ $democratic->vote($this->songs);
} // create_democratic
diff --git a/lib/class/tmpplaylist.class.php b/lib/class/tmpplaylist.class.php
index 781067dd..9e0c5a3a 100644
--- a/lib/class/tmpplaylist.class.php
+++ b/lib/class/tmpplaylist.class.php
@@ -130,8 +130,8 @@ class tmpPlaylist {
$order = 'ORDER BY id ASC';
/* Select all objects from this playlist */
- $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id $vote_select " .
- "FROM tmp_playlist_data $vote_join " .
+ $sql = "SELECT tmp_playlist_data.object_type, tmp_playlist_data.id, tmp_playlist_data.object_id " .
+ "FROM tmp_playlist_data " .
"WHERE tmp_playlist_data.tmp_playlist='" . Dba::escape($this->id) . "' $order";
$db_results = Dba::query($sql);
@@ -158,37 +158,12 @@ class tmpPlaylist {
$tmp_id = Dba::escape($this->id);
$order = " ORDER BY tmp_playlist_data.id DESC";
- /* Check for an item on the playlist, account for voting */
- if ($this->type == 'vote') {
- /* Add conditions for voting */
- $vote_select = ", COUNT(user_vote.user) AS `count`";
- $order = " GROUP BY tmp_playlist_data.id ORDER BY `count` DESC, user_vote.date ASC";
- $vote_join = "INNER JOIN user_vote ON user_vote.object_id=tmp_playlist_data.id";
- }
-
- $sql = "SELECT tmp_playlist_data.object_id $vote_select FROM tmp_playlist_data $vote_join " .
+ $sql = "SELECT tmp_playlist_data.object_id FROM tmp_playlist_data " .
"WHERE tmp_playlist_data.tmp_playlist = '$tmp_id' $order LIMIT 1";
$db_results = Dba::query($sql);
$results = Dba::fetch_assoc($db_results);
- /* If nothing was found and this is a voting playlist then get from base_playlist */
- if ($this->type == 'vote' AND !$results) {
-
- /* Check for a playlist */
- if ($this->base_playlist != '0') {
- /* We need to pull a random one from the base_playlist */
- $base_playlist = new playlist($this->base_playlist);
- $data = $base_playlist->get_random_songs(1);
- $results['object_id'] = $data['0'];
- }
- else {
- $sql = "SELECT id as `object_id` FROM song WHERE enabled='1' ORDER BY RAND() LIMIT 1";
- $db_results = Dba::query($sql);
- $results = Dba::fetch_assoc($db_results);
- }
- }
-
return $results['object_id'];
} // get_next_object
diff --git a/play/index.php b/play/index.php
index 55bce5ac..204b0021 100644
--- a/play/index.php
+++ b/play/index.php
@@ -296,10 +296,9 @@ if ($bytesStreamed > $minBytesStreamed) {
$user->update_stats($song->id);
/* If this is a voting tmp playlist remove the entry */
- if (is_object($tmp_playlist)) {
- if ($tmp_playlist->type == 'vote') {
- $tmp_playlist->delete_track($song_id);
- }
+ if (is_object($democratic)) {
+ $row_id = $democratic->get_uid_from_object_id($song_id,'song');
+ $democratic->delete_votes($row_id);
} // if tmp_playlist
/* Set the Song as Played if it isn't already */
diff --git a/server/democratic.ajax.php b/server/democratic.ajax.php
index 1bf2cdcb..90897a79 100644
--- a/server/democratic.ajax.php
+++ b/server/democratic.ajax.php
@@ -25,6 +25,29 @@
if (AJAX_INCLUDE != '1') { exit; }
switch ($_REQUEST['action']) {
+ case 'delete_vote':
+ $democratic = Democratic::get_current_playlist();
+ $democratic->remove_vote($_REQUEST['row_id']);
+
+ ob_start();
+ $objects = $democratic->get_items();
+ require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php';
+ $results['democratic_playlist'] = ob_get_contents();
+ ob_end_clean();
+
+ break;
+ case 'add_vote':
+
+ $democratic = Democratic::get_current_playlist();
+ $democratic->add_vote($_REQUEST['object_id'],$_REQUEST['type']);
+
+ ob_start();
+ $objects = $democratic->get_items();
+ require_once Config::get('prefix') . '/templates/show_democratic_playlist.inc.php';
+ $results['democratic_playlist'] = ob_get_contents();
+ ob_end_clean();
+
+ break;
case 'delete':
if (!$GLOBALS['user']->has_access('75')) {
exit;
diff --git a/templates/show_democratic_playlist.inc.php b/templates/show_democratic_playlist.inc.php
index 5798d522..cff55b41 100644
--- a/templates/show_democratic_playlist.inc.php
+++ b/templates/show_democratic_playlist.inc.php
@@ -63,8 +63,10 @@ foreach($objects as $row_id=>$object_data) {
?>
<tr class="<?php echo flip_class(); ?>">
<td class="cel_action">
- <?php if ($democratic->has_vote($song_id)) { ?>
+ <?php if ($democratic->has_vote($song->id)) { ?>
+ <?php echo Ajax::button('?page=democratic&action=delete_vote&row_id=' . $row_id,'thumb_down',_('Remove Vote'),'remove_vote_' . $row_id); ?>
<?php } else { ?>
+ <?php echo Ajax::button('?page=democratic&action=add_vote&object_id=' . $song->id . '&type=' . scrub_out($object_data['1']),'thumb_up',_('Add Vote'),'remove_vote_' . $row_id); ?>
<?php } ?>
</td>
<td class="cel_votes"><?php echo scrub_out($democratic->get_vote($row_id)); ?></td>