Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recently/Most played #177

Merged
merged 4 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion appinfo/database.xml
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,48 @@
</index>
</declaration>
</table>

<table>
<name>*dbprefix*audioplayer_statistics</name>
<declaration>
<field>
<name>id</name>
<type>integer</type>
<notnull>true</notnull>
<autoincrement>true</autoincrement>
<unsigned>true</unsigned>
<primary>true</primary>
</field>
<field>
<name>user_id</name>
<type>text</type>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>track_id</name>
<type>integer</type>
<notnull>true</notnull>
</field>
<field>
<name>playtime</name>
<type>integer</type>
<notnull>false</notnull>
</field>
<field>
<name>playcount</name>
<type>integer</type>
<notnull>false</notnull>
</field>
<index>
<name>aa_statistics_file_user_id_idx</name>
<unique>true</unique>
<field>
<name>track_id</name>
</field>
<field>
<name>user_id</name>
</field>
</index>
</declaration>
</table>
</database>
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@
['name' => 'category#getCategory', 'url' => '/getcategory', 'verb' => 'GET'],
['name' => 'category#getCategoryItems', 'url' => '/getcategoryitems', 'verb' => 'GET'],
['name' => 'category#setFavorite', 'url' => '/setfavorite', 'verb' => 'GET'],
['name' => 'category#setStatistics', 'url' => '/setstatistics', 'verb' => 'GET'],
]]);
24 changes: 24 additions & 0 deletions controller/categorycontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -356,4 +356,28 @@ public function setFavorite() {
}
return $return;
}
/**
* @NoAdminRequired
*/
public function setStatistics() {
$track_id = $this->params('track_id');
$date = new \DateTime();
$playtime = $date->getTimestamp();

$SQL='SELECT id, playcount FROM *PREFIX*audioplayer_statistics WHERE `user_id`= ? AND `track_id`= ?';
$stmt = $this->db->prepareQuery($SQL);
$result = $stmt->execute(array($this->userId, $track_id));
$row = $result->fetchRow();
if (isset($row['id'])) {
$playcount = $row['id'] + 1;
$stmt = $this->db->prepareQuery( 'UPDATE `*PREFIX*audioplayer_statistics` SET `playcount`= ?, `playtime`= ? WHERE `id` = ?');
$stmt->execute(array($playcount, $playtime, $row['id']));
return 'update';
} else {
$stmt = $this->db->prepareQuery( 'INSERT INTO `*PREFIX*audioplayer_statistics` (`user_id`,`track_id`,`playtime`,`playcount`) VALUES(?,?,?,?)' );
$result = $stmt->execute(array($this->userId, $track_id, $playtime, 1));
$insertid = $this->db->getInsertId('*PREFIX*audioplayer_statistics');
return $insertid;
}
}
}
19 changes: 18 additions & 1 deletion js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,13 @@ Audios.prototype.PlaylistSongs = function(){
if(!$(this).closest('li').hasClass('isActive')){
$(this).closest('li').addClass('isActive');
$this.AudioPlayer.actions.play($(this).closest('li').index());
$this.set_statistics();
}else{
if($('.sm2-bar-ui').hasClass('playing')){
$this.AudioPlayer.actions.stop();
}else{
$this.AudioPlayer.actions.play();
$this.set_statistics();
}
}
return false;
Expand Down Expand Up @@ -458,6 +460,7 @@ Audios.prototype.loadAlbums = function(){
$(this).parent().parent().find('.albumSelect li:first-child').addClass('isActive');
$this.AudioPlayer.actions.play(0);
}
$this.set_statistics();
var myCover=$('.album.is-active .albumcover');
if(myCover.css('background-image') == 'none'){
$('.sm2-playlist-cover').text(myCover.text()).css({'background-color':myCover.css('background-color'),'color':myCover.css('color'),'background-image':'none'});
Expand Down Expand Up @@ -539,7 +542,7 @@ Audios.prototype.loadSongsRow = function(elem){
var can_play = soundManager.html5;

var li = $('<li/>').attr({
'data-id' : elem.id,
'data-trackid' : elem.id,
'data-fileid' : elem.fid,
'data-title' : elem.tit,
'data-artist' : elem.art,
Expand Down Expand Up @@ -808,11 +811,13 @@ Audios.prototype.loadIndividualCategory = function(evt) {
$('#individual-playlist li i.fav').show();
activeLi.addClass('isActive');
$this.AudioPlayer.actions.play(activeLi.index());
$this.set_statistics();
}else{
if($('.sm2-bar-ui').hasClass('playing')){
$this.AudioPlayer.actions.stop();
}else{
$this.AudioPlayer.actions.play();
$this.set_statistics();
}
}
}
Expand Down Expand Up @@ -1711,6 +1716,17 @@ Audios.prototype.get_cover = function(user_type, callback) {
});
};

Audios.prototype.set_statistics = function() {
var track_id = $('#activePlaylist li.selected').data('trackid');
$.ajax({
type : 'GET',
url : OC.generateUrl('apps/audioplayer/setstatistics'),
data : {'track_id': track_id},
success : function(ajax_data) {
}
});
};

Audios.prototype.sort_playlist = function(evt) {
var column = $(evt.target).attr('class').split('-')[1];
var order = $(evt.target).data('order');
Expand Down Expand Up @@ -1759,6 +1775,7 @@ Audios.prototype.soundmanager_callback = function(SMaction) {
}

$('.sm2-playlist-cover').attr({'style':addCss}).text(addDescr);
$this.set_statistics();
}
};

Expand Down