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

Favorite integration #176

Merged
merged 17 commits into from
Apr 27, 2017
1 change: 1 addition & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,5 @@
['name' => 'setting#userPath', 'url' => '/userpath', 'verb' => 'POST'],
['name' => 'category#getCategory', 'url' => '/getcategory', 'verb' => 'GET'],
['name' => 'category#getCategoryItems', 'url' => '/getcategoryitems', 'verb' => 'GET'],
['name' => 'category#setFavorite', 'url' => '/setfavorite', 'verb' => 'GET'],
]]);
64 changes: 50 additions & 14 deletions controller/categorycontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use \OCP\IRequest;
use \OCP\IL10N;
use \OCP\IDb;
use \OCP\ITagManager;

/**
* Controller class for main page.
Expand All @@ -26,19 +27,24 @@ class CategoryController extends Controller {
private $userId;
private $l10n;
private $db;
private $tagger;
private $tagManager;

public function __construct(
$appName,
IRequest $request,
$userId,
IL10N $l10n,
IDb $db
IDb $db,
ITagManager $tagManager
) {
parent::__construct($appName, $request);
$this -> userId = $userId;
$this->userId = $userId;
$this->l10n = $l10n;
$this->db = $db;
}
$this->tagManager = $tagManager;
$this->tagger = null;
}

/**
* @NoAdminRequired
Expand Down Expand Up @@ -99,8 +105,8 @@ private function getCategoryforUser($category){
WHERE `user_id` = ?
ORDER BY LOWER(`name`) ASC
";
// **after v1.5.0** $aPlaylists[] = array("id"=>"X1", "name" =>$this->l10n->t('Favorites'));
$aPlaylists[] = array("id" => "X2", "name" => $this->l10n->t('Recently Added'));
$aPlaylists[] = array("id"=>"X1", "name"=>$this->l10n->t('Favorites'));
$aPlaylists[] = array("id"=>"X2", "name"=> $this->l10n->t('Recently Added'));
// **after v1.5.0** $aPlaylists[] = array("id"=>"X3", "name" =>$this->l10n->t('Recently Played'));
// **after v1.5.0** $aPlaylists[] = array("id"=>"X4", "name" =>$this->l10n->t('Most Played'));
// **after v1.5.0** $aPlaylists[] = array("id"=>"X5", "name" =>$this->l10n->t('Top Rated'));
Expand Down Expand Up @@ -225,7 +231,7 @@ public function getCategoryItems(){
private function getItemsforCatagory($category,$categoryId){

$aTracks=array();
$SQL_select = "SELECT `AT`.`id` , `AT`.`title` ,`AT`.`number` ,`AT`.`length` ,`AA`.`name` AS `artist`, `AB`.`name` AS `album`, `AT`.`file_id`, `AT`.`mimetype`, `AB`.`id` AS `cover_id`, `AB`.`cover`, LOWER(`AT`.`title`) AS `lower`";
$SQL_select = "SELECT `AT`.`id` , `AT`.`title` AS `tit`,`AT`.`number` AS `num`,`AT`.`length` AS `len`,`AA`.`name` AS `art`, `AB`.`name` AS `alb`, `AT`.`file_id` AS `fid`, `AT`.`mimetype` AS `mim`, `AB`.`id` AS `cid`, `AB`.`cover`, LOWER(`AT`.`title`) AS `lower`";
$SQL_from = " FROM `*PREFIX*audioplayer_tracks` `AT`
LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id`
LEFT JOIN `*PREFIX*audioplayer_albums` `AB` ON `AT`.`album_id` = `AB`.`id`";
Expand All @@ -249,6 +255,9 @@ private function getItemsforCatagory($category,$categoryId){
$SQL_order;
} elseif ($category === 'Playlist') {
if ($categoryId === "X1") { // Favorites
$SQL = $SQL_select . $SQL_from .
"WHERE `AT`.`id` > ? AND `AT`.`user_id` = ?" .
$SQL_order;
} elseif ($categoryId === "X2") { // Recently Added
$SQL = $SQL_select . $SQL_from .
"WHERE `AT`.`id` <> ? AND `AT`.`user_id` = ?
Expand Down Expand Up @@ -279,25 +288,36 @@ private function getItemsforCatagory($category,$categoryId){

$stmt = $this->db->prepareQuery($SQL);
$result = $stmt->execute(array($categoryId, $this->userId));

$this->tagger = $this->tagManager->load('files');
$favorites = $this->tagger->getFavorites();

while( $row = $result->fetchRow()) {
$file_not_found = false;
try {
$path = \OC\Files\Filesystem::getPath($row['file_id']);
$path = \OC\Files\Filesystem::getPath($row['fid']);
} catch (\Exception $e) {
$file_not_found = true;
}
}

if($file_not_found === false){
if($file_not_found === false){
if ($row['cover'] === null) {
$row['cover_id'] = '';
$row['cid'] = '';
}
array_splice($row, 9, 2);
$path = rtrim($path,"/");
$row['link'] = '?file='.rawurlencode($path);
$aTracks[]=$row;
}else{
$this->deleteFromDB($row['id'],$row['cover_id']);
$row['lin'] = rawurlencode($path);
if (in_array($row['fid'], $favorites)) {
$row['fav'] = "t";
} else {
$row['fav'] = "f";
}
if ($categoryId === "X1" AND in_array($row['fid'], $favorites) === false ) {
} else {
$aTracks[]=$row;
}
} else {
$this->deleteFromDB($row['id'],$row['cid']);
}
}

Expand All @@ -320,4 +340,20 @@ private function deleteFromDB($Id,$iAlbumId){
$stmt = $this->db->prepareQuery( 'DELETE FROM `*PREFIX*audioplayer_tracks` WHERE `user_id` = ? AND `id` = ?' );
$stmt->execute(array($this->userId, $Id));
}

/**
* @NoAdminRequired
*/
public function setFavorite() {
$fileId = $this->params('fileId');
$isFavorite = $this->params('isFavorite');
$this->tagger = $this->tagManager->load('files');

if ($isFavorite === "true") {
$return = $this->tagger->removeFromFavorites($fileId);
} else {
$return = $this->tagger->addToFavorites($fileId);
}
return $return;
}
}
33 changes: 16 additions & 17 deletions controller/musiccontroller.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public function getMusic(){
*/
public function loadAlbums(){

$SQL="SELECT `AA`.`id`,`AA`.`name`,`AA`.`cover`,`AA`.`artist_id`
$SQL="SELECT `AA`.`id`,`AA`.`name` AS `nam`,`AA`.`cover` AS `cov`,`AA`.`artist_id` AS `aid`
FROM `*PREFIX*audioplayer_albums` `AA`
WHERE `AA`.`user_id` = ?
ORDER BY `AA`.`name` ASC
Expand All @@ -193,14 +193,14 @@ public function loadAlbums(){
$result = $stmt->execute(array($this->userId));
$aAlbums=array();
while( $row = $result->fetchRow()) {
$row['artist'] = $this->loadArtistsToAlbum($row['id'],$row['artist_id']);
$row['art'] = $this->loadArtistsToAlbum($row['id'],$row['aid']);

if ($row['name'] === $this->l10n->t('Unknown') AND $row['artist'] === $this->l10n->t('Various Artists')) {
$row['cover'] = 'true';
}elseif ($row['cover'] === null){
$row['cover'] = '';
if ($row['nam'] === $this->l10n->t('Unknown') AND $row['art'] === $this->l10n->t('Various Artists')) {
$row['cov'] = 'true';
}elseif ($row['cov'] === null){
$row['cov'] = '';
}else{
$row['cover'] = 'true';
$row['cov'] = 'true';
}
array_splice($row, 3, 1);
$aAlbums[$row['id']] = $row;
Expand Down Expand Up @@ -241,8 +241,7 @@ private function loadArtistsToAlbum($iAlbumId, $ARtistID){
}

public function loadSongs(){
// $SQL="SELECT `AT`.`id`,`AT`.`title`,`AT`.`number`,`AT`.`album_id`,`AT`.`artist_id`,`AT`.`length`,`AT`.`file_id`,`AT`.`bitrate`,`AT`.`mimetype`,`AA`.`name` AS `artistname` FROM `*PREFIX*audioplayer_tracks` `AT`
$SQL="SELECT `AT`.`id`,`AT`.`title`,`AT`.`number`,`AT`.`album_id`,`AT`.`length`,`AT`.`file_id`,`AT`.`mimetype`,`AA`.`name` AS `artistname` FROM `*PREFIX*audioplayer_tracks` `AT`
$SQL="SELECT `AT`.`id`,`AT`.`title` AS `tit`,`AT`.`number` AS `num`,`AT`.`album_id` AS `aid`,`AT`.`length` AS `len`,`AT`.`file_id` AS `fid`,`AT`.`mimetype` AS `mim`,`AA`.`name` AS `art` FROM `*PREFIX*audioplayer_tracks` `AT`
LEFT JOIN `*PREFIX*audioplayer_artists` `AA` ON `AT`.`artist_id` = `AA`.`id`
WHERE `AT`.`user_id` = ?
ORDER BY `AT`.`album_id` ASC,`AT`.`number` ASC
Expand All @@ -255,21 +254,21 @@ public function loadSongs(){
while( $row = $result->fetchRow()) {
$file_not_found = false;
try {
$path = \OC\Files\Filesystem::getPath($row['file_id']);
$path = \OC\Files\Filesystem::getPath($row['fid']);
} catch (\Exception $e) {
$file_not_found = true;
}

if($file_not_found === false){
# Beta for Streaming testing; should not have any impact as this filetype is not used
if ($row['mimetype'] === 'audio/x-mpegurl') {
$row['link'] = rawurlencode($row['title']);
if ($row['mim'] === 'audio/x-mpegurl') {
$row['lin'] = rawurlencode($row['title']);
}else{
$row['link'] = '?file='.rawurlencode($path);
$row['lin'] = '?file='.rawurlencode($path);
}
$aSongs[$row['album_id']][] = $row;
$aSongs[$row['aid']][] = $row;
}else{
$this->deleteFromDB($row['id'],$row['album_id']);
$this->deleteFromDB($row['id'],$row['aid']);
}
}
if(empty($aSongs)){
Expand Down Expand Up @@ -408,8 +407,8 @@ private function deleteFromDB($Id,$iAlbumId){
private function sortArrayByFields($data)
{
foreach ($data as $key => $row) {
$first[$key] = $row['artist'];
$second[$key] = $row['name'];
$first[$key] = $row['art'];
$second[$key] = $row['nam'];
}
array_multisort($first, SORT_ASC, SORT_STRING|SORT_FLAG_CASE,$second , SORT_ASC, SORT_STRING|SORT_FLAG_CASE, $data);
return $data;
Expand Down
2 changes: 1 addition & 1 deletion css/bar-ui.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
.sm2-bar-ui .sm2-playlist li {
text-align: center;
font-size: 92.5%;
line-height: 1em;
line-height: 1.2em;
}

.sm2-bar-ui.compact {
Expand Down
87 changes: 63 additions & 24 deletions css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -318,15 +318,21 @@ height:auto;

}

.fileActionsMenu{
margin-top: 30px;
margin-right: 5px;
padding-bottom: 15px
}

#individual-playlist-container{
margin:0;
width:98%;
position:relative;
top:60px;
float:left;
display:none;
height:auto;
padding-left:10px;
margin:0;
width:98%;
position:relative;
top:60px;
float:left;
display:none;
height:auto;
padding-left:10px;
}
#individual-playlist{
margin-left:auto;
Expand All @@ -339,11 +345,19 @@ padding-left:10px;

}
#individual-playlist li .ioc-delete{
display:none;
display: none;
}
#individual-playlist li.dragable:hover {
background: #f8f8f8;
}
#individual-playlist li:hover {
background:#f4f4f4;

#individual-playlist li:hover .edit-song,
#individual-playlist li:hover .fav,
#individual-playlist li:focus .fav
{
opacity: 0.3;
}

#individual-playlist li:hover .ioc-delete{
display:block;
}
Expand All @@ -370,7 +384,7 @@ padding-left:10px;
position:relative;
float:left;
display:block;
min-width:30%;
min-width:35%;
}

#individual-playlist-header span.header-artist{
Expand All @@ -392,14 +406,14 @@ padding-left:10px;
display:block;
width:10%;
text-align:right;
right:65px;
right:35px;
}
#individual-playlist-header span.header-opt{
position:absolute;
float:right;
display:block;
width:20px;
right:10px;
width:30px;
right:0px;
}

#individual-playlist li .actionsSong{
Expand All @@ -409,11 +423,26 @@ padding-left:10px;
line-height:20px;
width:22px;
}
#individual-playlist li .actionsSong i.ioc{
#individual-playlist .ioc{
font-size:16px;
line-height:22px;
}

#individual-playlist .fav{
display: inline-block;
vertical-align: middle;
background-size: 16px 16px;
opacity: 0;
}

#individual-playlist .fav:hover,
#individual-playlist .fav:focus,
#individual-playlist .edit-song:hover,
#individual-playlist .edit-song:focus
{
opacity: 1 !important;
}

#individual-playlist li .number{
position:relative;
float:left;
Expand Down Expand Up @@ -463,8 +492,7 @@ padding-left:10px;
display:block;
width:10%;
text-align:right;

right:65px;
right:35px;
}

#individual-playlist li span.ioc-delete{
Expand All @@ -479,8 +507,6 @@ padding-left:10px;
line-height:24px;
color:rgba(0,0,0,0.3);
cursor:pointer;


}
#individual-playlist li span.ioc-delete:hover{
color:#A9302A;
Expand All @@ -489,14 +515,11 @@ padding-left:10px;
#individual-playlist li a.edit-song{
float:right;
position:absolute;
right:25px;
right:0px;
width:30px;
height:20px;
opacity:0;
}
#individual-playlist li:hover a.edit-song{
opacity:1;
}

#app-content{
padding-left:0px;
Expand Down Expand Up @@ -946,6 +969,22 @@ li.dropHover{
width:100%;
}

/*dialog title info*/
.infoLabel{
float:left;
width:100px;
display:block;
font-weight:bold;
line-height: 28px;
}
.infoText{
float:left;
display:block;
width: 195px;
line-height: 28px;
}


#edit_photo_dialog_img { display: block; min-width: 150px; min-height: 200px; }
#file_upload_form { width: 0; height: 0; }
#file_upload_target, #import_upload_target, #crop_target { display:none; }
Expand Down
Loading