Merge pull request #818 from Robbt/sort-by-play-date

Smartblock sort tracks by last play date
This commit is contained in:
Kyle Robbertze 2019-05-09 17:05:56 +02:00 committed by GitHub
commit eb122f52fb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 11 deletions

View File

@ -171,7 +171,9 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
$this->sortOptions = array( $this->sortOptions = array(
"random" => _("Randomly"), "random" => _("Randomly"),
"newest" => _("Newest"), "newest" => _("Newest"),
"oldest" => _("Oldest") "oldest" => _("Oldest"),
"mostrecentplay" => ("Most recently played"),
"leastrecentplay" => ("Least recently played")
); );
} }
return $this->sortOptions; return $this->sortOptions;

View File

@ -1202,7 +1202,6 @@ SQL;
// that might contradict itself we group them based upon their original position on the form // that might contradict itself we group them based upon their original position on the form
$criteriaGroup = $i; $criteriaGroup = $i;
foreach ($p_criteriaData['criteria'][$critKeys[$i]] as $d) { foreach ($p_criteriaData['criteria'][$critKeys[$i]] as $d) {
Logging::info($d);
$field = $d['sp_criteria_field']; $field = $d['sp_criteria_field'];
$value = $d['sp_criteria_value']; $value = $d['sp_criteria_value'];
$modifier = $d['sp_criteria_modifier']; $modifier = $d['sp_criteria_modifier'];
@ -1586,7 +1585,6 @@ SQL;
$storedCrit = array(); $storedCrit = array();
foreach ($out as $crit) { foreach ($out as $crit) {
Logging::info($crit);
$criteria = $crit->getDbCriteria(); $criteria = $crit->getDbCriteria();
$modifier = $crit->getDbModifier(); $modifier = $crit->getDbModifier();
$value = $crit->getDbValue(); $value = $crit->getDbValue();
@ -1614,8 +1612,6 @@ SQL;
"display_modifier"=>$modifierOptions[$modifier]); "display_modifier"=>$modifierOptions[$modifier]);
} }
} }
Logging::info($storedCrit);
return $storedCrit; return $storedCrit;
} }
@ -1730,14 +1726,9 @@ SQL;
if ($spCriteria == "owner_id") { if ($spCriteria == "owner_id") {
$spCriteria = "subj.login"; $spCriteria = "subj.login";
} }
Logging::info($i);
Logging::info($group);
Logging::info($prevgroup);
if ($i > 0 && $prevgroup == $group) { if ($i > 0 && $prevgroup == $group) {
Logging::info('adding or');
$qry->addOr($spCriteria, $spCriteriaValue, $spCriteriaModifier); $qry->addOr($spCriteria, $spCriteriaValue, $spCriteriaModifier);
} else { } else {
Logging::info('adding and');
$qry->addAnd($spCriteria, $spCriteriaValue, $spCriteriaModifier); $qry->addAnd($spCriteria, $spCriteriaValue, $spCriteriaModifier);
} }
// only add this NOT LIKE null if you aren't also matching on another criteria // only add this NOT LIKE null if you aren't also matching on another criteria
@ -1758,6 +1749,7 @@ SQL;
// check if file exists // check if file exists
$qry->add("file_exists", "true", Criteria::EQUAL); $qry->add("file_exists", "true", Criteria::EQUAL);
$qry->add("hidden", "false", Criteria::EQUAL); $qry->add("hidden", "false", Criteria::EQUAL);
$sortTracks = 'random'; $sortTracks = 'random';
if (isset($storedCrit['sort'])) { if (isset($storedCrit['sort'])) {
$sortTracks = $storedCrit['sort']['value']; $sortTracks = $storedCrit['sort']['value'];
@ -1768,6 +1760,13 @@ SQL;
else if ($sortTracks == 'oldest') { else if ($sortTracks == 'oldest') {
$qry->addAscendingOrderByColumn('utime'); $qry->addAscendingOrderByColumn('utime');
} }
// these sort additions are needed to override the default postgres NULL sort behavior
else if ($sortTracks == 'mostrecentplay') {
$qry->addDescendingOrderByColumn('(lptime IS NULL), lptime');
}
else if ($sortTracks == 'leastrecentplay') {
$qry->addAscendingOrderByColumn('(lptime IS NOT NULL), lptime');
}
else if ($sortTracks == 'random') { else if ($sortTracks == 'random') {
$qry->addAscendingOrderByColumn('random()'); $qry->addAscendingOrderByColumn('random()');
} else { } else {
@ -1812,7 +1811,6 @@ SQL;
try { try {
$out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find(); $out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
return array("files"=>$out, "limit"=>$limits, "repeat_tracks"=> $repeatTracks, "overflow_tracks"=> $overflowTracks, "count"=>$out->count()); return array("files"=>$out, "limit"=>$limits, "repeat_tracks"=> $repeatTracks, "overflow_tracks"=> $overflowTracks, "count"=>$out->count());
} catch (Exception $e) { } catch (Exception $e) {
Logging::info($e); Logging::info($e);