Merge pull request #78 from Robbt/realtime-smart-blocks
Added sort tracks by upload time to smart blocks criteria
This commit is contained in:
commit
0c3395289d
|
@ -4,6 +4,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
private $criteriaOptions;
|
||||
private $stringCriteriaOptions;
|
||||
private $numericCriteriaOptions;
|
||||
private $sortOptions;
|
||||
private $limitOptions;
|
||||
|
||||
/* We need to know if the criteria value will be a string
|
||||
|
@ -122,6 +123,17 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
}
|
||||
return $this->limitOptions;
|
||||
}
|
||||
private function getSortOptions()
|
||||
{
|
||||
if (!isset($this->sortOptions)) {
|
||||
$this->sortOptions = array(
|
||||
"random" => _("random"),
|
||||
"newest" => _("newest"),
|
||||
"oldest" => _("oldest")
|
||||
);
|
||||
}
|
||||
return $this->sortOptions;
|
||||
}
|
||||
|
||||
|
||||
public function init()
|
||||
|
@ -288,6 +300,15 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
}
|
||||
$this->addElement($repeatTracks);
|
||||
|
||||
$sort = new Zend_Form_Element_Select('sp_sort_options');
|
||||
$sort->setAttrib('class', 'sp_input_select')
|
||||
->setDecorators(array('viewHelper'))
|
||||
->setMultiOptions($this->getSortOptions());
|
||||
if (isset($storedCrit["sort"])) {
|
||||
$sort->setValue($storedCrit["sort"]["value"]);
|
||||
}
|
||||
$this->addElement($sort);
|
||||
|
||||
$limit = new Zend_Form_Element_Select('sp_limit_options');
|
||||
$limit->setAttrib('class', 'sp_input_select')
|
||||
->setDecorators(array('viewHelper'))
|
||||
|
@ -344,7 +365,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
|||
|
||||
public function preValidation($params)
|
||||
{
|
||||
$data = Application_Model_Block::organizeSmartPlyalistCriteria($params['data']);
|
||||
$data = Application_Model_Block::organizeSmartPlaylistCriteria($params['data']);
|
||||
// add elelments that needs to be added
|
||||
// set multioption for modifier according to criteria_field
|
||||
$modRowMap = array();
|
||||
|
|
|
@ -1156,7 +1156,7 @@ SQL;
|
|||
*/
|
||||
public function saveSmartBlockCriteria($p_criteria)
|
||||
{
|
||||
$data = $this->organizeSmartPlyalistCriteria($p_criteria);
|
||||
$data = $this->organizeSmartPlaylistCriteria($p_criteria);
|
||||
// saving dynamic/static flag
|
||||
$blockType = $data['etc']['sp_type'] == 0 ? 'static':'dynamic';
|
||||
$this->saveType($blockType);
|
||||
|
@ -1224,6 +1224,16 @@ SQL;
|
|||
}
|
||||
}
|
||||
|
||||
// insert sort info
|
||||
$qry = new CcBlockcriteria();
|
||||
$qry->setDbCriteria("sort")
|
||||
->setDbModifier("N/A")
|
||||
->setDbValue($p_criteriaData['etc']['sp_sort_options'])
|
||||
->setDbBlockId($this->id)
|
||||
->save();
|
||||
|
||||
|
||||
|
||||
// insert limit info
|
||||
$qry = new CcBlockcriteria();
|
||||
$qry->setDbCriteria("limit")
|
||||
|
@ -1231,7 +1241,8 @@ SQL;
|
|||
->setDbValue($p_criteriaData['etc']['sp_limit_value'])
|
||||
->setDbBlockId($this->id)
|
||||
->save();
|
||||
|
||||
|
||||
|
||||
// insert repeate track option
|
||||
$qry = new CcBlockcriteria();
|
||||
$qry->setDbCriteria("repeat_tracks")
|
||||
|
@ -1352,6 +1363,7 @@ SQL;
|
|||
"isrc_number" => _("ISRC"),
|
||||
"label" => _("Label"),
|
||||
"language" => _("Language"),
|
||||
"utime" => _("Upload Time"),
|
||||
"mtime" => _("Last Modified"),
|
||||
"lptime" => _("Last Played"),
|
||||
"length" => _("Length"),
|
||||
|
@ -1399,6 +1411,8 @@ SQL;
|
|||
"display_modifier"=>_($modifier));
|
||||
} else if($criteria == "repeat_tracks") {
|
||||
$storedCrit["repeat_tracks"] = array("value"=>$value);
|
||||
} else if($criteria == "sort") {
|
||||
$storedCrit["sort"] = array("value"=>$value);
|
||||
} else {
|
||||
$storedCrit["crit"][$criteria][] = array(
|
||||
"criteria"=>$criteria,
|
||||
|
@ -1507,8 +1521,20 @@ SQL;
|
|||
// check if file exists
|
||||
$qry->add("file_exists", "true", Criteria::EQUAL);
|
||||
$qry->add("hidden", "false", Criteria::EQUAL);
|
||||
if (isset($storedCrit['sort'])) {
|
||||
$sortTracks = $storedCrit['sort']['value'];
|
||||
}
|
||||
if ($sortTracks == 'newest') {
|
||||
$qry->addDescendingOrderByColumn('utime');
|
||||
}
|
||||
else if ($sortTracks == 'oldest') {
|
||||
$qry->addAscendingOrderByColumn('utime');
|
||||
}
|
||||
else {
|
||||
$qry->addAscendingOrderByColumn('random()');
|
||||
}
|
||||
|
||||
}
|
||||
// construct limit restriction
|
||||
$limits = array();
|
||||
|
||||
|
@ -1537,9 +1563,8 @@ SQL;
|
|||
Logging::info($e);
|
||||
}
|
||||
}
|
||||
|
||||
public static function organizeSmartPlyalistCriteria($p_criteria)
|
||||
{
|
||||
public static function organizeSmartPlaylistCriteria($p_criteria)
|
||||
{
|
||||
$fieldNames = array('sp_criteria_field', 'sp_criteria_modifier', 'sp_criteria_value', 'sp_criteria_extra');
|
||||
$output = array();
|
||||
foreach ($p_criteria as $ele) {
|
||||
|
|
|
@ -95,7 +95,18 @@
|
|||
<?php endif; ?>
|
||||
<br />
|
||||
</dd>
|
||||
|
||||
<dd id='sp_sort-element'>
|
||||
<span class='sp_text_font'>Sort tracks by</span>
|
||||
<?php echo $this->element->getElement('sp_sort_options') ?>
|
||||
<?php if($this->element->getElement("sp_sort_options")->hasErrors()) : ?>
|
||||
<?php foreach($this->element->getElement("sp_sort_options")->getMessages() as $error): ?>
|
||||
<span class='errors sp-errors'>
|
||||
<?php echo $error; ?>
|
||||
</span>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
<br />
|
||||
</dd>
|
||||
<dd id='sp_limit-element'>
|
||||
<span class='sp_text_font'><?php echo $this->element->getElement('sp_limit_value')->getLabel() ?></span>
|
||||
<?php echo $this->element->getElement('sp_limit_value')?>
|
||||
|
|
Loading…
Reference in New Issue