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
|
|
|
{
|
2012-08-29 05:04:55 +02:00
|
|
|
private $criteriaOptions = array(
|
2012-08-29 18:57:56 +02:00
|
|
|
0 => "Select criteria",
|
|
|
|
"album_title" => "Album",
|
|
|
|
"bit_rate" => "Bit Rate (Kbps)",
|
|
|
|
"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 (kHz)",
|
|
|
|
"track_title" => "Title",
|
2012-08-29 05:04:55 +02:00
|
|
|
"track_number" => "Track Number",
|
2012-08-29 18:57:56 +02:00
|
|
|
"utime" => "Uploaded",
|
|
|
|
"year" => "Year"
|
2012-08-15 22:22:56 +02:00
|
|
|
);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
|
|
|
private $criteriaTypes = array(
|
2012-08-29 18:57:56 +02:00
|
|
|
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",
|
|
|
|
"rating" => "n",
|
|
|
|
"sample_rate" => "n",
|
|
|
|
"track_title" => "s",
|
2012-08-29 05:04:55 +02:00
|
|
|
"track_number" => "n",
|
2012-08-29 18:57:56 +02:00
|
|
|
"year" => "n"
|
2012-08-29 05:04:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
private $stringCriteriaOptions = array(
|
2012-08-29 18:57:56 +02:00
|
|
|
"0" => "Select modifier",
|
|
|
|
"contains" => "contains",
|
2012-08-29 05:04:55 +02:00
|
|
|
"does not contain" => "does not contain",
|
2012-08-29 18:57:56 +02:00
|
|
|
"is" => "is",
|
|
|
|
"is not" => "is not",
|
|
|
|
"starts with" => "starts with",
|
|
|
|
"ends with" => "ends with"
|
2012-08-29 05:04:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
private $numericCriteriaOptions = array(
|
2012-08-29 18:57:56 +02:00
|
|
|
"0" => "Select modifier",
|
|
|
|
"is" => "is",
|
|
|
|
"is not" => "is not",
|
2012-08-29 05:04:55 +02:00
|
|
|
"is greater than" => "is greater than",
|
2012-08-29 18:57:56 +02:00
|
|
|
"is less than" => "is less than",
|
2012-08-29 05:04:55 +02:00
|
|
|
"is in the range" => "is in the range"
|
|
|
|
);
|
|
|
|
|
|
|
|
private $limitOptions = array(
|
2012-08-29 18:57:56 +02:00
|
|
|
"hours" => "hours",
|
2012-08-29 05:04:55 +02:00
|
|
|
"minutes" => "minutes",
|
2012-08-29 18:57:56 +02:00
|
|
|
"items" => "items"
|
2012-08-29 05:04:55 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2012-07-24 18:13:51 +02:00
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-28 18:13:58 +02:00
|
|
|
public function startForm($p_blockId, $p_isValid = false)
|
2012-07-24 18:13:51 +02:00
|
|
|
{
|
|
|
|
// 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
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-07-24 18:13:51 +02:00
|
|
|
$spType = new Zend_Form_Element_Radio('sp_type');
|
2012-08-20 23:17:48 +02:00
|
|
|
$spType->setLabel('Set smart block 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-08-29 05:04:55 +02:00
|
|
|
|
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-08-29 05:04:55 +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-08-29 05:04:55 +02:00
|
|
|
|
2012-07-30 22:42:37 +02:00
|
|
|
$criteriaKeys = array();
|
|
|
|
if (isset($storedCrit["crit"])) {
|
|
|
|
$criteriaKeys = array_keys($storedCrit["crit"]);
|
|
|
|
}
|
2012-08-15 22:22:56 +02:00
|
|
|
$numElements = count($this->criteriaOptions);
|
2012-07-24 18:13:51 +02:00
|
|
|
for ($i = 0; $i < $numElements; $i++) {
|
|
|
|
$criteriaType = "";
|
2012-08-29 05:04:55 +02:00
|
|
|
|
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-29 05:04:55 +02:00
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
$modRowMap[$i] = $critCount;
|
2012-08-29 05:04:55 +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 = '';
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
$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'))
|
2012-08-15 22:22:56 +02:00
|
|
|
->setMultiOptions($this->criteriaOptions);
|
2012-08-14 16:02:36 +02:00
|
|
|
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
|
|
|
$criteria->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
if (isset($criteriaKeys[$i])) {
|
2012-08-15 22:22:56 +02:00
|
|
|
$criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
|
2012-08-14 16:02:36 +02:00
|
|
|
$criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]);
|
|
|
|
}
|
|
|
|
$this->addElement($criteria);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
/****************** 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-08-29 05:04:55 +02:00
|
|
|
if ($criteriaType == "s") {
|
2012-08-15 22:22:56 +02:00
|
|
|
$criteriaModifers->setMultiOptions($this->stringCriteriaOptions);
|
2012-08-29 05:04:55 +02:00
|
|
|
} else {
|
2012-08-15 22:22:56 +02:00
|
|
|
$criteriaModifers->setMultiOptions($this->numericCriteriaOptions);
|
2012-07-29 21:47:42 +02:00
|
|
|
}
|
|
|
|
$criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]);
|
2012-08-29 05:04:55 +02:00
|
|
|
} else {
|
2012-08-14 16:02:36 +02:00
|
|
|
$criteriaModifers->setMultiOptions(array('0' => 'Select modifier'));
|
|
|
|
}
|
|
|
|
$this->addElement($criteriaModifers);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
/****************** VALUE ***********/
|
|
|
|
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$i."_".$j);
|
|
|
|
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
|
|
|
|
->setDecorators(array('viewHelper'));
|
2012-08-29 05:04:55 +02:00
|
|
|
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
2012-08-14 16:02:36 +02:00
|
|
|
$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);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
/****************** 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');
|
2012-08-29 05:04:55 +02:00
|
|
|
} else {
|
2012-08-14 16:02:36 +02:00
|
|
|
$criteriaExtra->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
$this->addElement($criteriaExtra);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-08 18:01:10 +02:00
|
|
|
}//for
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-07-29 21:47:42 +02:00
|
|
|
}//for
|
2012-08-29 05:04:55 +02:00
|
|
|
|
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'))
|
2012-08-15 22:22:56 +02:00
|
|
|
->setMultiOptions($this->limitOptions);
|
2012-07-24 18:13:51 +02:00
|
|
|
if (isset($storedCrit["limit"])) {
|
|
|
|
$limit->setValue($storedCrit["limit"]["modifier"]);
|
|
|
|
}
|
|
|
|
$this->addElement($limit);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-07-24 18:13:51 +02:00
|
|
|
$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-08-20 23:17:48 +02:00
|
|
|
} else {
|
|
|
|
// setting default to 1 hour
|
|
|
|
$limitValue->setValue(1);
|
2012-07-24 18:13:51 +02:00
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-07-25 18:44:37 +02:00
|
|
|
//getting block content candidate count that meets criteria
|
|
|
|
$bl = new Application_Model_Block($p_blockId);
|
2012-08-28 18:13:58 +02:00
|
|
|
if ($p_isValid) {
|
|
|
|
$files = $bl->getListofFilesMeetCriteria();
|
|
|
|
$showPoolCount = true;
|
|
|
|
} else {
|
|
|
|
$files = null;
|
|
|
|
$showPoolCount = false;
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-07-24 18:13:51 +02:00
|
|
|
$generate = new Zend_Form_Element_Button('generate_button');
|
|
|
|
$generate->setAttrib('class', 'ui-button ui-state-default sp-button');
|
2012-08-21 16:46:25 +02:00
|
|
|
$generate->setAttrib('title', 'Generate playlist content and save criteria');
|
2012-07-24 18:13:51 +02:00
|
|
|
$generate->setIgnore(true);
|
|
|
|
$generate->setLabel('Generate');
|
|
|
|
$generate->setDecorators(array('viewHelper'));
|
|
|
|
$this->addElement($generate);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-07-24 18:13:51 +02:00
|
|
|
$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-08-28 18:13:58 +02:00
|
|
|
'criteriasLength' => count($this->criteriaOptions), 'poolCount' => $files['count'], 'modRowMap' => $modRowMap,
|
|
|
|
'showPoolCount' => $showPoolCount))
|
2012-07-24 18:13:51 +02:00
|
|
|
));
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
|
|
|
public function preValidation($params)
|
|
|
|
{
|
2012-08-15 22:22:56 +02:00
|
|
|
$data = Application_Model_Block::organizeSmartPlyalistCriteria($params['data']);
|
2012-08-29 05:04:55 +02:00
|
|
|
// add elelments that needs to be added
|
2012-08-15 22:22:56 +02:00
|
|
|
// set multioption for modifier according to creiteria_field
|
|
|
|
$modRowMap = array();
|
|
|
|
foreach ($data['criteria'] as $critKey=>$d) {
|
|
|
|
$count = 1;
|
2012-08-29 05:04:55 +02:00
|
|
|
foreach ($d as $modKey=>$modInfo) {
|
2012-08-15 22:22:56 +02:00
|
|
|
if ($modKey == 0) {
|
|
|
|
$eleCrit = $this->getElement("sp_criteria_field_".$critKey."_".$modKey);
|
|
|
|
$eleCrit->setValue($this->criteriaOptions[$modInfo['sp_criteria_field']]);
|
|
|
|
$eleCrit->setAttrib("disabled", null);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 22:22:56 +02:00
|
|
|
$eleMod = $this->getElement("sp_criteria_modifier_".$critKey."_".$modKey);
|
|
|
|
$criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']];
|
|
|
|
if ($criteriaType == "s") {
|
|
|
|
$eleMod->setMultiOptions($this->stringCriteriaOptions);
|
2012-08-29 05:04:55 +02:00
|
|
|
} elseif ($criteriaType == "n") {
|
2012-08-15 22:22:56 +02:00
|
|
|
$eleMod->setMultiOptions($this->numericCriteriaOptions);
|
|
|
|
} else {
|
|
|
|
$eleMod->setMultiOptions(array('0' => 'Select modifier'));
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
$eleMod->setValue($modInfo['sp_criteria_modifier']);
|
2012-08-15 22:22:56 +02:00
|
|
|
$eleMod->setAttrib("disabled", null);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 22:22:56 +02:00
|
|
|
$eleValue = $this->getElement("sp_criteria_value_".$critKey."_".$modKey);
|
2012-08-29 05:04:55 +02:00
|
|
|
$eleValue->setValue($modInfo['sp_criteria_value']);
|
2012-08-15 22:22:56 +02:00
|
|
|
$eleValue->setAttrib("disabled", null);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 22:22:56 +02:00
|
|
|
if (isset($modInfo['sp_criteria_extra'])) {
|
2012-08-29 05:04:55 +02:00
|
|
|
$eleExtra = $this->getElement("sp_criteria_extra_".$critKey."_".$modKey);
|
2012-08-15 22:22:56 +02:00
|
|
|
$eleExtra->setValue($modInfo['sp_criteria_extra']);
|
2012-08-29 05:04:55 +02:00
|
|
|
$eleValue->setAttrib('class', 'input_text sp_extra_input_text');
|
2012-08-15 22:22:56 +02:00
|
|
|
$eleExtra->setAttrib("disabled", null);
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 22:22:56 +02:00
|
|
|
} else {
|
2012-08-29 05:04:55 +02:00
|
|
|
$criteria = new Zend_Form_Element_Select("sp_criteria_field_".$critKey."_".$modKey);
|
|
|
|
$criteria->setAttrib('class', 'input_select sp_input_select sp-invisible')
|
|
|
|
->setValue('Select criteria')
|
|
|
|
->setDecorators(array('viewHelper'))
|
|
|
|
->setMultiOptions($this->criteriaOptions);
|
|
|
|
|
|
|
|
$criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']];
|
|
|
|
$criteria->setValue($this->criteriaOptions[$modInfo['sp_criteria_field']]);
|
|
|
|
$this->addElement($criteria);
|
|
|
|
|
|
|
|
/****************** MODIFIER ***********/
|
|
|
|
$criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$critKey."_".$modKey);
|
|
|
|
$criteriaModifers->setValue('Select modifier')
|
|
|
|
->setAttrib('class', 'input_select sp_input_select')
|
|
|
|
->setDecorators(array('viewHelper'));
|
|
|
|
|
|
|
|
if ($criteriaType == "s") {
|
|
|
|
$criteriaModifers->setMultiOptions($this->stringCriteriaOptions);
|
|
|
|
} elseif ($criteriaType == "n") {
|
|
|
|
$criteriaModifers->setMultiOptions($this->numericCriteriaOptions);
|
|
|
|
} else {
|
|
|
|
$criteriaModifers->setMultiOptions(array('0' => 'Select modifier'));
|
|
|
|
}
|
|
|
|
$criteriaModifers->setValue($modInfo['sp_criteria_modifier']);
|
|
|
|
$this->addElement($criteriaModifers);
|
|
|
|
|
|
|
|
/****************** VALUE ***********/
|
|
|
|
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$critKey."_".$modKey);
|
|
|
|
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
|
|
|
|
->setDecorators(array('viewHelper'));
|
|
|
|
$criteriaValue->setValue($modInfo['sp_criteria_value']);
|
|
|
|
$this->addElement($criteriaValue);
|
|
|
|
|
|
|
|
/****************** EXTRA ***********/
|
|
|
|
$criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$critKey."_".$modKey);
|
|
|
|
$criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text')
|
2012-08-15 22:22:56 +02:00
|
|
|
->setDecorators(array('viewHelper'));
|
2012-08-29 05:04:55 +02:00
|
|
|
if (isset($modInfo['sp_criteria_extra'])) {
|
|
|
|
$criteriaExtra->setValue($modInfo['sp_criteria_extra']);
|
|
|
|
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
|
|
|
|
} else {
|
|
|
|
$criteriaExtra->setAttrib('disabled', 'disabled');
|
2012-08-15 22:22:56 +02:00
|
|
|
}
|
|
|
|
$this->addElement($criteriaExtra);
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$modRowMap[$critKey] = $count;
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 22:22:56 +02:00
|
|
|
$decorator = $this->getDecorator("ViewScript");
|
|
|
|
$existingModRow = $decorator->getOption("modRowMap");
|
|
|
|
foreach ($modRowMap as $key=>$v) {
|
|
|
|
$existingModRow[$key] = $v;
|
2012-08-15 17:36:41 +02:00
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
$decorator->setOption("modRowMap", $existingModRow);
|
|
|
|
|
|
|
|
// reconstruct the params['criteria'] so we can populate the form
|
|
|
|
$formData = array();
|
|
|
|
foreach ($params['data'] as $ele) {
|
|
|
|
$formData[$ele['name']] = $ele['value'];
|
2012-08-15 22:22:56 +02:00
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
$this->populate($formData);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 22:22:56 +02:00
|
|
|
return $data;
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
|
|
|
public function isValid($params)
|
|
|
|
{
|
2012-08-15 22:22:56 +02:00
|
|
|
$isValid = true;
|
|
|
|
$data = $this->preValidation($params);
|
2012-08-29 05:04:55 +02:00
|
|
|
$criteria2PeerMap = array(
|
|
|
|
0 => "Select criteria",
|
|
|
|
"album_title" => "DbAlbumTitle",
|
|
|
|
"artist_name" => "DbArtistName",
|
|
|
|
"bit_rate" => "DbBitRate",
|
|
|
|
"bpm" => "DbBpm",
|
|
|
|
"comments" => "DbComments",
|
|
|
|
"composer" => "DbComposer",
|
|
|
|
"conductor" => "DbConductor",
|
|
|
|
"utime" => "DbUtime",
|
|
|
|
"mtime" => "DbMtime",
|
|
|
|
"lptime" => "DbLPtime",
|
|
|
|
"disc_number" => "DbDiscNumber",
|
|
|
|
"genre" => "DbGenre",
|
|
|
|
"isrc_number" => "DbIsrcNumber",
|
|
|
|
"label" => "DbLabel",
|
|
|
|
"language" => "DbLanguage",
|
|
|
|
"length" => "DbLength",
|
|
|
|
"lyricist" => "DbLyricist",
|
|
|
|
"mood" => "DbMood",
|
|
|
|
"name" => "DbName",
|
|
|
|
"orchestra" => "DbOrchestra",
|
|
|
|
"rating" => "DbRating",
|
|
|
|
"sample_rate" => "DbSampleRate",
|
|
|
|
"track_title" => "DbTrackTitle",
|
|
|
|
"track_number" => "DbTrackNumber",
|
|
|
|
"year" => "DbYear"
|
2012-08-15 17:36:41 +02:00
|
|
|
);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
// things we need to check
|
|
|
|
// 1. limit value shouldn't be empty and has upperbound of 24 hrs
|
|
|
|
// 2. sp_criteria or sp_criteria_modifier shouldn't be 0
|
|
|
|
// 3. validate formate according to DB column type
|
|
|
|
$multiplier = 1;
|
|
|
|
$result = 0;
|
|
|
|
$errors = array();
|
|
|
|
$error = array();
|
2012-08-29 05:04:55 +02:00
|
|
|
|
|
|
|
// validation start
|
|
|
|
if ($data['etc']['sp_limit_options'] == 'hours') {
|
|
|
|
$multiplier = 60;
|
|
|
|
}
|
2012-08-15 17:36:41 +02:00
|
|
|
if ($data['etc']['sp_limit_options'] == 'hours' || $data['etc']['sp_limit_options'] == 'mins') {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element = $this->getElement("sp_limit_value");
|
|
|
|
if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
|
|
|
|
$element->addError("Limit cannot be empty or smaller than 0");
|
|
|
|
$isValid = false;
|
|
|
|
} else {
|
|
|
|
$mins = floatval($data['etc']['sp_limit_value']) * $multiplier;
|
2012-08-15 17:36:41 +02:00
|
|
|
if ($mins > 1440) {
|
|
|
|
$element->addError("Limit cannot be more than 24 hrs");
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
}
|
2012-08-15 17:36:41 +02:00
|
|
|
} else {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element = $this->getElement("sp_limit_value");
|
2012-08-15 17:36:41 +02:00
|
|
|
if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element->addError("Limit cannot be empty or smaller than 0");
|
|
|
|
$isValid = false;
|
|
|
|
} elseif (!ctype_digit($data['etc']['sp_limit_value'])) {
|
|
|
|
$element->addError("The value should be an integer");
|
|
|
|
$isValid = false;
|
|
|
|
} elseif (intval($data['etc']['sp_limit_value']) > 500) {
|
|
|
|
$element->addError("500 is the max item limit value you can set");
|
|
|
|
$isValid = false;
|
|
|
|
}
|
2012-08-15 17:36:41 +02:00
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
$criteriaFieldsUsed = array();
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
if (isset($data['criteria'])) {
|
|
|
|
foreach ($data['criteria'] as $rowKey=>$row) {
|
2012-08-29 05:04:55 +02:00
|
|
|
foreach ($row as $key=>$d) {
|
|
|
|
$element = $this->getElement("sp_criteria_field_".$rowKey."_".$key);
|
|
|
|
$error = array();
|
|
|
|
// check for not selected select box
|
|
|
|
if ($d['sp_criteria_field'] == "0" || $d['sp_criteria_modifier'] == "0") {
|
|
|
|
$element->addError("You must select Criteria and Modifier");
|
|
|
|
$isValid = false;
|
|
|
|
} else {
|
|
|
|
$column = CcFilesPeer::getTableMap()->getColumnByPhpName($criteria2PeerMap[$d['sp_criteria_field']]);
|
|
|
|
// validation on type of column
|
|
|
|
if ($d['sp_criteria_field'] == 'length') {
|
2012-08-15 17:36:41 +02:00
|
|
|
if (!preg_match("/(\d{2}):(\d{2}):(\d{2})/", $d['sp_criteria_value'])) {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element->addError("'Length' should be in '00:00:00' format");
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
} elseif ($column->getType() == PropelColumnTypes::TIMESTAMP) {
|
2012-08-15 17:36:41 +02:00
|
|
|
if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element->addError("The value should be in timestamp format(eg. 0000-00-00 or 00-00-00 00:00:00");
|
|
|
|
$isValid = false;
|
|
|
|
} else {
|
|
|
|
$result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']);
|
|
|
|
if (!$result["success"]) {
|
2012-08-15 17:36:41 +02:00
|
|
|
// check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
|
2012-08-29 05:04:55 +02:00
|
|
|
$element->addError($result["errMsg"]);
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($d['sp_criteria_extra'])) {
|
2012-08-15 17:36:41 +02:00
|
|
|
if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element->addError("The value should be in timestamp format(eg. 0000-00-00 or 00-00-00 00:00:00");
|
|
|
|
$isValid = false;
|
|
|
|
} else {
|
|
|
|
$result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_extra']);
|
|
|
|
if (!$result["success"]) {
|
|
|
|
// check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
|
2012-08-15 17:36:41 +02:00
|
|
|
$element->addError($result["errMsg"]);
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif ($column->getType() == PropelColumnTypes::INTEGER) {
|
2012-08-15 17:36:41 +02:00
|
|
|
if (!is_numeric($d['sp_criteria_value'])) {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element->addError("The value has to be numeric");
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
// length check
|
2012-08-15 17:36:41 +02:00
|
|
|
if (intval($d['sp_criteria_value']) >= pow(2,31)) {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element->addError("The value should be less then 2147483648");
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
} elseif ($column->getType() == PropelColumnTypes::VARCHAR) {
|
2012-08-15 17:36:41 +02:00
|
|
|
if (strlen($d['sp_criteria_value']) > $column->getSize()) {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element->addError("The value should be less ".$column->getSize()." characters");
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
if ($d['sp_criteria_value'] == "") {
|
2012-08-29 05:04:55 +02:00
|
|
|
$element->addError("Value cannot be empty");
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
}//end foreach
|
|
|
|
}//for loop
|
2012-08-15 17:36:41 +02:00
|
|
|
}//if
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
return $isValid;
|
|
|
|
}
|
2012-07-24 18:13:51 +02:00
|
|
|
}
|