2012-07-24 18:13:51 +02:00
|
|
|
<?php
|
2012-07-25 17:00:46 +02:00
|
|
|
class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
|
2012-07-24 18:13:51 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
public function init(){
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-07-25 18:44:37 +02:00
|
|
|
public function startForm($p_blockId)
|
2012-07-24 18:13:51 +02:00
|
|
|
{
|
|
|
|
$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",
|
|
|
|
"rating" => "Rating",
|
|
|
|
"sample_rate" => "Sample Rate",
|
|
|
|
"track_title" => "Title",
|
2012-08-01 23:10:56 +02:00
|
|
|
"track_number" => "Track Number",
|
2012-07-24 18:13:51 +02:00
|
|
|
"utime" => "Uploaded",
|
2012-08-08 18:01:10 +02:00
|
|
|
"year" => "Year"
|
2012-07-24 18:13:51 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
$criteriaTypes = array(
|
|
|
|
0 => "",
|
|
|
|
"album_title" => "s",
|
|
|
|
"artist_name" => "s",
|
|
|
|
"bit_rate" => "n",
|
2012-08-13 17:51:25 +02:00
|
|
|
"bpm" => "s",
|
2012-07-24 18:13:51 +02:00
|
|
|
"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",
|
|
|
|
"rating" => "n",
|
|
|
|
"sample_rate" => "n",
|
|
|
|
"track_title" => "s",
|
2012-08-01 23:10:56 +02:00
|
|
|
"track_number" => "n",
|
2012-07-24 18:13:51 +02:00
|
|
|
"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
|
2012-07-25 18:44:37 +02:00
|
|
|
$out = CcBlockQuery::create()->findPk($p_blockId);
|
2012-07-24 18:13:51 +02:00
|
|
|
if ($out->getDbType() == "static") {
|
2012-07-25 18:44:37 +02:00
|
|
|
$blockType = 0;
|
2012-07-24 18:13:51 +02:00
|
|
|
} else {
|
2012-07-25 18:44:37 +02:00
|
|
|
$blockType = 1;
|
2012-07-24 18:13:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
$spType = new Zend_Form_Element_Radio('sp_type');
|
2012-08-08 21:35:28 +02:00
|
|
|
$spType->setLabel('Set smart playlist type:')
|
2012-07-24 18:13:51 +02:00
|
|
|
->setDecorators(array('viewHelper'))
|
|
|
|
->setMultiOptions(array(
|
|
|
|
'static' => 'Static',
|
|
|
|
'dynamic' => 'Dynamic'
|
|
|
|
))
|
2012-07-25 18:44:37 +02:00
|
|
|
->setValue($blockType);
|
2012-07-24 18:13:51 +02:00
|
|
|
$this->addElement($spType);
|
|
|
|
|
2012-07-31 00:21:27 +02:00
|
|
|
$bl = new Application_Model_Block($p_blockId);
|
|
|
|
$storedCrit = $bl->getCriteria();
|
2012-08-14 16:02:36 +02:00
|
|
|
|
|
|
|
/* $modRoadMap stores the number of same criteria
|
|
|
|
* Ex: 3 Album titles, and 2 Track titles
|
|
|
|
* We need to know this so we display the form elements properly
|
2012-07-29 21:47:42 +02:00
|
|
|
*/
|
|
|
|
$modRowMap = array();
|
2012-07-24 18:13:51 +02:00
|
|
|
|
2012-07-25 18:44:37 +02:00
|
|
|
$openSmartBlockOption = false;
|
2012-07-24 18:13:51 +02:00
|
|
|
if (!empty($storedCrit)) {
|
2012-07-25 18:44:37 +02:00
|
|
|
$openSmartBlockOption = true;
|
2012-07-24 18:13:51 +02:00
|
|
|
}
|
|
|
|
|
2012-07-30 22:42:37 +02:00
|
|
|
$criteriaKeys = array();
|
|
|
|
if (isset($storedCrit["crit"])) {
|
|
|
|
$criteriaKeys = array_keys($storedCrit["crit"]);
|
|
|
|
}
|
2012-07-24 18:13:51 +02:00
|
|
|
$numElements = count($criteriaOptions);
|
|
|
|
for ($i = 0; $i < $numElements; $i++) {
|
|
|
|
$criteriaType = "";
|
|
|
|
|
2012-07-29 21:47:42 +02:00
|
|
|
if (isset($criteriaKeys[$i])) {
|
|
|
|
$critCount = count($storedCrit["crit"][$criteriaKeys[$i]]);
|
|
|
|
} else {
|
|
|
|
$critCount = 1;
|
2012-07-24 18:13:51 +02:00
|
|
|
}
|
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
$modRowMap[$i] = $critCount;
|
2012-07-24 18:13:51 +02:00
|
|
|
|
2012-07-29 21:47:42 +02:00
|
|
|
/* Loop through all criteria with the same field
|
|
|
|
* Ex: all criteria for 'Album'
|
|
|
|
*/
|
|
|
|
for ($j = 0; $j < $critCount; $j++) {
|
|
|
|
/****************** CRITERIA ***********/
|
2012-08-14 16:02:36 +02:00
|
|
|
if ($j > 0) {
|
|
|
|
$invisible = ' sp-invisible';
|
|
|
|
} else {
|
|
|
|
$invisible = '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$criteria = new Zend_Form_Element_Select("sp_criteria_field_".$i."_".$j);
|
|
|
|
$criteria->setAttrib('class', 'input_select sp_input_select'.$invisible)
|
|
|
|
->setValue('Select criteria')
|
|
|
|
->setDecorators(array('viewHelper'))
|
|
|
|
->setMultiOptions($criteriaOptions);
|
|
|
|
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
|
|
|
$criteria->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($criteriaKeys[$i])) {
|
|
|
|
$criteriaType = $criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
|
|
|
|
$criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]);
|
|
|
|
}
|
|
|
|
$this->addElement($criteria);
|
|
|
|
|
|
|
|
/****************** MODIFIER ***********/
|
|
|
|
$criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$i."_".$j);
|
|
|
|
$criteriaModifers->setValue('Select modifier')
|
|
|
|
->setAttrib('class', 'input_select sp_input_select')
|
|
|
|
->setDecorators(array('viewHelper'));
|
|
|
|
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
|
|
|
$criteriaModifers->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
if (isset($criteriaKeys[$i])) {
|
2012-07-29 21:47:42 +02:00
|
|
|
if($criteriaType == "s"){
|
|
|
|
$criteriaModifers->setMultiOptions($stringCriteriaOptions);
|
|
|
|
}else{
|
|
|
|
$criteriaModifers->setMultiOptions($numericCriteriaOptions);
|
|
|
|
}
|
|
|
|
$criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]);
|
2012-08-14 16:02:36 +02:00
|
|
|
}else{
|
|
|
|
$criteriaModifers->setMultiOptions(array('0' => 'Select modifier'));
|
|
|
|
}
|
|
|
|
$this->addElement($criteriaModifers);
|
|
|
|
|
|
|
|
/****************** VALUE ***********/
|
|
|
|
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$i."_".$j);
|
|
|
|
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
|
|
|
|
->setDecorators(array('viewHelper'));
|
|
|
|
if ($i != 0 && !isset($criteriaKeys[$i])){
|
|
|
|
$criteriaValue->setAttrib('disabled', 'disabled');
|
2012-07-29 21:47:42 +02:00
|
|
|
}
|
2012-08-14 16:02:36 +02:00
|
|
|
if (isset($criteriaKeys[$i])) {
|
|
|
|
$criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
|
|
|
}
|
|
|
|
$this->addElement($criteriaValue);
|
|
|
|
|
|
|
|
/****************** EXTRA ***********/
|
|
|
|
$criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$i."_".$j);
|
|
|
|
$criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')
|
|
|
|
->setDecorators(array('viewHelper'));
|
|
|
|
if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"])) {
|
|
|
|
$criteriaExtra->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]);
|
|
|
|
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
|
|
|
|
}else{
|
|
|
|
$criteriaExtra->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
$this->addElement($criteriaExtra);
|
|
|
|
|
2012-08-08 18:01:10 +02:00
|
|
|
}//for
|
2012-07-27 20:32:31 +02:00
|
|
|
|
2012-07-29 21:47:42 +02:00
|
|
|
}//for
|
2012-07-24 18:13:51 +02:00
|
|
|
|
|
|
|
$limit = new Zend_Form_Element_Select('sp_limit_options');
|
|
|
|
$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');
|
|
|
|
$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"]);
|
|
|
|
}
|
|
|
|
|
2012-07-25 18:44:37 +02:00
|
|
|
//getting block content candidate count that meets criteria
|
|
|
|
$bl = new Application_Model_Block($p_blockId);
|
|
|
|
$files = $bl->getListofFilesMeetCriteria();
|
2012-07-24 18:13:51 +02:00
|
|
|
|
|
|
|
$save = new Zend_Form_Element_Button('save_button');
|
2012-08-10 18:34:45 +02:00
|
|
|
$save->setAttrib('class', 'ui-button ui-state-default sp-save');
|
2012-08-10 16:54:13 +02:00
|
|
|
$save->setAttrib('title', 'Save playlist');
|
2012-07-24 18:13:51 +02:00
|
|
|
$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');
|
2012-08-10 16:54:13 +02:00
|
|
|
$generate->setAttrib('title', 'Generate playlist content');
|
2012-07-24 18:13:51 +02:00
|
|
|
$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');
|
2012-08-10 16:54:13 +02:00
|
|
|
$shuffle->setAttrib('title', 'Shuffle playlist content');
|
2012-07-24 18:13:51 +02:00
|
|
|
$shuffle->setIgnore(true);
|
|
|
|
$shuffle->setLabel('Shuffle');
|
|
|
|
$shuffle->setDecorators(array('viewHelper'));
|
|
|
|
$this->addElement($shuffle);
|
2012-07-27 20:32:31 +02:00
|
|
|
|
2012-07-24 18:13:51 +02:00
|
|
|
$this->setDecorators(array(
|
2012-07-25 18:44:37 +02:00
|
|
|
array('ViewScript', array('viewScript' => 'form/smart-block-criteria.phtml', "openOption"=> $openSmartBlockOption,
|
2012-07-29 21:47:42 +02:00
|
|
|
'criteriasLength' => count($criteriaOptions), 'poolCount' => $files['count'], 'modRowMap' => $modRowMap))
|
2012-07-24 18:13:51 +02:00
|
|
|
));
|
|
|
|
}
|
2012-07-27 20:32:31 +02:00
|
|
|
|
2012-07-24 18:13:51 +02:00
|
|
|
}
|