CC-84: Smart Playlists

-divided criteria into sub form to handle multiple sets
This commit is contained in:
denise 2012-07-23 10:40:53 -04:00
parent 9bdb4a40e0
commit c99e1b892c
5 changed files with 329 additions and 42 deletions

View File

@ -76,9 +76,13 @@ class PlaylistController extends Zend_Controller_Action
$formatter = new LengthFormatter($pl->getLength());
$this->view->length = $formatter->format();
$form = new Application_Form_SmartPlaylistCriteria();
$form = new Application_Form_SmartPlaylist();
$form->removeDecorator('DtDdWrapper');
$form->startForm($pl->getId());
$subform = new Application_Form_SmartPlaylistCriteriaSubForm();
$form->removeDecorator('DtDdWrapper');
$form->addSubForm($subform, 'sp_set_1');
$this->view->form = $form;
$this->view->pl = $pl;
@ -171,7 +175,7 @@ class PlaylistController extends Zend_Controller_Action
if($isAdminOrPM || $pl->getCreatorId() == $userInfo->id){
$this->view->pl = $pl;
$form = new Application_Form_SmartPlaylistCriteria();
$form = new Application_Form_SmartPlaylist();
$form->startForm($this->pl_sess->id);
$this->view->form = $form;
}
@ -203,7 +207,7 @@ class PlaylistController extends Zend_Controller_Action
{
$id = $this->_getParam('id', null);
Logging::log("editing playlist {$id}");
//$form = new Application_Form_SmartPlaylistCriteria();
//$form = new Application_Form_SmartPlaylist();
if (!is_null($id)) {

View File

@ -1,11 +1,12 @@
<?php
class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
class Application_Form_SmartPlaylist extends Zend_Form
{
public function init(){
}
public function startForm($p_playlistId)
{
/*
$criteriaOptions = array(
0 => "Select criteria",
"album_title" => "Album",
@ -91,6 +92,8 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
"items" => "items"
);
*/
// load type
$out = CcPlaylistQuery::create()->findPk($p_playlistId);
if ($out->getDbType() == "static") {
@ -109,9 +112,10 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
->setValue($playlistType);
$this->addElement($spType);
/*
// load criteria from db
$out = CcPlaylistcriteriaQuery::create()->findByDbPlaylistId($p_playlistId);
*/
$storedCrit = array();
foreach ($out as $crit) {
$criteria = $crit->getDbCriteria();
@ -125,12 +129,11 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
$storedCrit["crit"][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra);
}
}
$openSmartPlaylistOption = false;
if (!empty($storedCrit)) {
$openSmartPlaylistOption = true;
}
/*
$numElements = count($criteriaOptions);
for ($i = 0; $i < $numElements; $i++) {
$criteriaType = "";
@ -207,6 +210,7 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
if (isset($storedCrit["limit"])) {
$limitValue->setValue($storedCrit["limit"]["value"]);
}
*/
$save = new Zend_Form_Element_Button('save_button');
$save->setAttrib('class', 'ui-button ui-state-default sp-button');
@ -232,13 +236,20 @@ class Application_Form_SmartPlaylistCriteria extends Zend_Form_SubForm
$shuffle->setDecorators(array('viewHelper'));
$this->addElement($shuffle);
$numOfSubForm = 3;
for ($i=0;$i<$numOfSubForm;$i++) {
$subform = new Application_Form_SmartPlaylistCriteriaSubForm();
$subform->setCriteriaSetNumber($i);
$subform->startForm($p_playlistId);
$this->addSubForm($subform, 'sp_set_'.$i);
}
//getting playlist content candidate count that meets criteria
$pl = new Application_Model_Playlist($p_playlistId);
$files = $pl->getListofFilesMeetCriteria();
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/smart-playlist-criteria.phtml', "openOption"=> $openSmartPlaylistOption,
'criteriasLength' => count($criteriaOptions), 'poolCount' => $files['count']))
array('ViewScript', array('viewScript' => 'form/smart-playlist.phtml', "openOption"=> $openSmartPlaylistOption, "parent_form"=>$this, "numOfSubForm"=>$numOfSubForm))
));
}
}

View File

@ -0,0 +1,261 @@
<?php
class Application_Form_SmartPlaylistCriteriaSubForm extends Zend_Form_SubForm
{
private $setNumber;
public function init(){
}
public function setCriteriaSetNumber($p_num)
{
$this->setNumber = $p_num;
}
public function startForm($p_playlistId)
{
$criteriaOptions = array(
0 => "Select criteria",
"album_title" => "Album",
"bit_rate" => "Bit Rate",
"bpm" => "Bpm",
"comments" => "Comments",
"composer" => "Composer",
"conductor" => "Conductor",
"artist_name" => "Creator",
"disc_number" => "Disc Number",
"genre" => "Genre",
"isrc_number" => "ISRC",
"label" => "Label",
"language" => "Language",
"mtime" => "Last Modified",
"lptime" => "Last Played",
"length" => "Length",
"lyricist" => "Lyricist",
"mood" => "Mood",
"name" => "Name",
"orchestra" => "Orchestra",
"radio_station_name" => "Radio Station Name",
"rating" => "Rating",
"sample_rate" => "Sample Rate",
"track_title" => "Title",
"track_num" => "Track Number",
"utime" => "Uploaded",
"year" => "Year"
);
$criteriaTypes = array(
0 => "",
"album_title" => "s",
"artist_name" => "s",
"bit_rate" => "n",
"bpm" => "n",
"comments" => "s",
"composer" => "s",
"conductor" => "s",
"utime" => "n",
"mtime" => "n",
"lptime" => "n",
"disc_number" => "n",
"genre" => "s",
"isrc_number" => "s",
"label" => "s",
"language" => "s",
"length" => "n",
"lyricist" => "s",
"mood" => "s",
"name" => "s",
"orchestra" => "s",
"radio_station_name" => "s",
"rating" => "n",
"sample_rate" => "n",
"track_title" => "s",
"track_num" => "n",
"year" => "n"
);
$stringCriteriaOptions = array(
"0" => "Select modifier",
"contains" => "contains",
"does not contain" => "does not contain",
"is" => "is",
"is not" => "is not",
"starts with" => "starts with",
"ends with" => "ends with"
);
$numericCriteriaOptions = array(
"0" => "Select modifier",
"is" => "is",
"is not" => "is not",
"is greater than" => "is greater than",
"is less than" => "is less than",
"is in the range" => "is in the range"
);
$limitOptions = array(
"hours" => "hours",
"minutes" => "minutes",
"items" => "items"
);
/*
// load type
$out = CcPlaylistQuery::create()->findPk($p_playlistId);
if ($out->getDbType() == "static") {
$playlistType = 0;
} else {
$playlistType = 1;
}
$spType = new Zend_Form_Element_Radio('sp_type');
$spType->setLabel('Set smart playlist type:')
->setDecorators(array('viewHelper'))
->setMultiOptions(array(
'static' => 'Static',
'dynamic' => 'Dynamic'
))
->setValue($playlistType);
$this->addElement($spType);
*/
// load criteria from db
$out = CcPlaylistcriteriaQuery::create()->findByDbPlaylistId($p_playlistId);
$storedCrit = array();
foreach ($out as $crit) {
$criteria = $crit->getDbCriteria();
$modifier = $crit->getDbModifier();
$value = $crit->getDbValue();
$extra = $crit->getDbExtra();
if($criteria == "limit"){
$storedCrit["limit"] = array("value"=>$value, "modifier"=>$modifier);
}else{
$storedCrit["crit"][] = array("criteria"=>$criteria, "value"=>$value, "modifier"=>$modifier, "extra"=>$extra);
}
}
$openSmartPlaylistOption = false;
if (!empty($storedCrit)) {
$openSmartPlaylistOption = true;
}
$numElements = count($criteriaOptions);
for ($i = 0; $i < $numElements; $i++) {
$criteriaType = "";
$criteria = new Zend_Form_Element_Select("sp_criteria_field_".$this->setNumber."_".$i);
$criteria->setAttrib('class', 'input_select sp_input_select')
->setValue('Select criteria')
->setDecorators(array('viewHelper'))
->setMultiOptions($criteriaOptions);
if ($i != 0 && !isset($storedCrit["crit"][$i])){
$criteria->setAttrib('disabled', 'disabled');
}
if (isset($storedCrit["crit"][$i])) {
$criteriaType = $criteriaTypes[$storedCrit["crit"][$i]["criteria"]];
$criteria->setValue($storedCrit["crit"][$i]["criteria"]);
}
$this->addElement($criteria);
$criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$this->setNumber."_".$i);
$criteriaModifers->setValue('Select modifier')
->setAttrib('class', 'input_select sp_input_select')
->setDecorators(array('viewHelper'));
if ($i != 0 && !isset($storedCrit["crit"][$i])){
$criteriaModifers->setAttrib('disabled', 'disabled');
}
if (isset($storedCrit["crit"][$i])) {
if($criteriaType == "s"){
$criteriaModifers->setMultiOptions($stringCriteriaOptions);
}else{
$criteriaModifers->setMultiOptions($numericCriteriaOptions);
}
$criteriaModifers->setValue($storedCrit["crit"][$i]["modifier"]);
}else{
$criteriaModifers->setMultiOptions(array('0' => 'Select modifier'));
}
$this->addElement($criteriaModifers);
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$this->setNumber."_".$i);
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
->setDecorators(array('viewHelper'));
if ($i != 0 && !isset($storedCrit["crit"][$i])){
$criteriaValue->setAttrib('disabled', 'disabled');
}
if (isset($storedCrit["crit"][$i])) {
$criteriaValue->setValue($storedCrit["crit"][$i]["value"]);
}
$this->addElement($criteriaValue);
$criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$this->setNumber."_".$i);
$criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')
->setDecorators(array('viewHelper'));
if (isset($storedCrit["crit"][$i]["extra"])) {
$criteriaExtra->setValue($storedCrit["crit"][$i]["extra"]);
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
}else{
$criteriaExtra->setAttrib('disabled', 'disabled');
}
$this->addElement($criteriaExtra);
}
$limit = new Zend_Form_Element_Select('sp_limit_options_'.$this->setNumber);
$limit->setAttrib('class', 'sp_input_select')
->setDecorators(array('viewHelper'))
->setMultiOptions($limitOptions);
if (isset($storedCrit["limit"])) {
$limit->setValue($storedCrit["limit"]["modifier"]);
}
$this->addElement($limit);
$limitValue = new Zend_Form_Element_Text('sp_limit_value_'.$this->setNumber);
$limitValue->setAttrib('class', 'sp_input_text_limit')
->setLabel('Limit to')
->setDecorators(array('viewHelper'));
$this->addElement($limitValue);
if (isset($storedCrit["limit"])) {
$limitValue->setValue($storedCrit["limit"]["value"]);
}
/*
$save = new Zend_Form_Element_Button('save_button');
$save->setAttrib('class', 'ui-button ui-state-default sp-button');
$save->setAttrib('title', 'Save criteria only');
$save->setIgnore(true);
$save->setLabel('Save');
$save->setDecorators(array('viewHelper'));
$this->addElement($save);
$generate = new Zend_Form_Element_Button('generate_button');
$generate->setAttrib('class', 'ui-button ui-state-default sp-button');
$generate->setAttrib('title', 'Save criteria and generate playlist content');
$generate->setIgnore(true);
$generate->setLabel('Generate');
$generate->setDecorators(array('viewHelper'));
$this->addElement($generate);
$shuffle = new Zend_Form_Element_Button('shuffle_button');
$shuffle->setAttrib('class', 'ui-button ui-state-default sp-button');
$shuffle->setAttrib('title', 'Shuffle playlist content');
$shuffle->setIgnore(true);
$shuffle->setLabel('Shuffle');
$shuffle->setDecorators(array('viewHelper'));
$this->addElement($shuffle);
*/
//getting playlist content candidate count that meets criteria
$pl = new Application_Model_Playlist($p_playlistId);
$files = $pl->getListofFilesMeetCriteria();
Logging::log($this->getElements());
Logging::log(count($this->getElements()));
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/smart-playlist-criteria.phtml', "openOption"=> $openSmartPlaylistOption,
'criteriasLength' => count($criteriaOptions), 'poolCount' => $files['count'], 'setNumber' => $this->setNumber))
));
}
}

View File

@ -1,38 +1,18 @@
<form id="smart-playlist-form" method="post" action="">
<fieldset class='toggle <?php echo $this->openOption ? "" : "closed"?>' id='smart_playlist_options'>
<legend style='cursor: pointer;'><span class='ui-icon ui-icon-triangle-2-n-s'></span>Smart Playlist Options</legend>
<h2 class="collapsible-header close"><span class="arrow-icon"></span>Set <?php echo $this->setNumber?></h2>
<fieldset class='toggle <?php echo $this->openOption ? "" : "closed"?>' id='sp_set_<?php echo $this->setNumber?>'>
<dl class='zend_form'>
<div id='sp-success' class='success' style='display:none'></div>
<dd id='sp_type-element'>
<label class='sp-label'>
<?php echo $this->element->getElement('sp_type')->getLabel() ?>
<span class='playlist_type_help_icon'></span>
</label>
<?php $i=0;
$value = $this->element->getElement('sp_type')->getValue();
foreach ($this->element->getElement('sp_type')->getMultiOptions() as $radio) : ?>
<label class='sp-label' for='sp_type-<?php echo $i?>'>
<input type="radio" value="<?php echo $i ?>" id="sp_type-<?php echo $i ?>" name="sp_type" <?php if($i == $value){echo 'checked="checked"';}?> ><?php echo $radio ?>
</label>
<?php $i = $i + 1; ?>
<?php endforeach; ?>
<?php echo $this->element->getElement('save_button') ?>
<?php echo $this->element->getElement('generate_button') ?>
<?php echo $this->element->getElement('shuffle_button') ?>
</dd>
<dd id='sp_criteria-element'>
<?php for ($i = 0; $i < $this->criteriasLength; $i++) {?>
<div <?php if (($i > 0) && ($this->element->getElement('sp_criteria_field_'.$i)->getAttrib('disabled') == 'disabled')) {
<div <?php if (($i > 0) && ($this->element->getElement("sp_criteria_field_".$this->setNumber."_".$i)->getAttrib('disabled') == 'disabled')) {
echo 'style=display:none';
} ?>>
<?php echo $this->element->getElement('sp_criteria_field_'.$i) ?>
<?php echo $this->element->getElement('sp_criteria_modifier_'.$i) ?>
<?php echo $this->element->getElement('sp_criteria_value_'.$i) ?>
<span class='sp_text_font' id="extra_criteria" <?php echo $this->element->getElement('sp_criteria_extra_'.$i)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>> to <?php echo $this->element->getElement('sp_criteria_extra_'.$i) ?></span>
<a class='ui-button sp-ui-button-icon-only' id='criteria_remove_<?php echo $i ?>'>
<?php echo $this->element->getElement("sp_criteria_field_".$this->setNumber."_".$i) ?>
<?php echo $this->element->getElement("sp_criteria_modifier_".$this->setNumber."_".$i) ?>
<?php echo $this->element->getElement("sp_criteria_value_".$this->setNumber."_".$i) ?>
<span class='sp_text_font' id="extra_criteria" <?php echo $this->element->getElement("sp_criteria_extra_".$this->setNumber."_".$i)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>> to <?php echo $this->element->getElement('sp_criteria_extra_'.$this->setNumber.'_'.$i) ?></span>
<a class='ui-button sp-ui-button-icon-only' id='criteria_remove_<?php echo $this->setNumber ?>_<?php echo $i ?>'>
<span class='ui-icon ui-icon-closethick'></span>
</a>
<br />
@ -43,9 +23,9 @@
</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')?>
<?php echo $this->element->getElement('sp_limit_options') ?>
<span class='sp_text_font'><?php echo $this->element->getElement('sp_limit_value_'.$this->setNumber)->getLabel() ?></span>
<?php echo $this->element->getElement('sp_limit_value_'.$this->setNumber)?>
<?php echo $this->element->getElement('sp_limit_options_'.$this->setNumber) ?>
<br /><br />
</dd>
<div class='sp_text_font sp_text_font_bold'>
@ -76,5 +56,4 @@
</div>
</dl>
</fieldset>
</form>
</fieldset>

View File

@ -0,0 +1,32 @@
<form id="smart-playlist-form" method="post" action="">
<fieldset class='toggle <?php echo $this->openOption ? "" : "closed"?>' id='smart_playlist_options'>
<legend style='cursor: pointer;'><span class='ui-icon ui-icon-triangle-2-n-s'></span>Smart Playlist Options</legend>
<dl class='zend_form'>
<div id='sp-success' class='success' style='display:none'></div>
<dd id='sp_type-element'>
<label class='sp-label'>
<?php echo $this->element->getElement('sp_type')->getLabel() ?>
<span class='playlist_type_help_icon'></span>
</label>
<?php $i=0;
$value = $this->element->getElement('sp_type')->getValue();
foreach ($this->element->getElement('sp_type')->getMultiOptions() as $radio) : ?>
<label class='sp-label' for='sp_type-<?php echo $i?>'>
<input type="radio" value="<?php echo $i ?>" id="sp_type-<?php echo $i ?>" name="sp_type" <?php if($i == $value){echo 'checked="checked"';}?> ><?php echo $radio ?>
</label>
<?php $i = $i + 1; ?>
<?php endforeach; ?>
<?php echo $this->element->getElement('save_button') ?>
<?php echo $this->element->getElement('generate_button') ?>
<?php echo $this->element->getElement('shuffle_button') ?>
</dd>
</dl>
<?php
for($i=0;$i<$this->numOfSubForm;$i++){
echo $this->parent_form->getSubform('sp_set_'.$i);
}
?>
</fieldset>
</form>