added comments to document smartblock functions and added new options to permit datetime based select fields

This commit is contained in:
Robb Ebright 2017-08-16 14:55:48 -04:00
parent e3f52ad968
commit 0b80a429b3
3 changed files with 64 additions and 5 deletions

View File

@ -555,6 +555,7 @@ class PlaylistController extends Zend_Controller_Action
if ($form->isValid($params)) { if ($form->isValid($params)) {
$this->setPlaylistNameDescAction(); $this->setPlaylistNameDescAction();
$bl->saveSmartBlockCriteria($params['data']); $bl->saveSmartBlockCriteria($params['data']);
// Logging::info($params['data']);
$this->createUpdateResponse($bl); $this->createUpdateResponse($bl);
$this->view->result = 0; $this->view->result = 0;

View File

@ -24,9 +24,9 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
"description" => "s", "description" => "s",
"artist_name" => "s", "artist_name" => "s",
"encoded_by" => "s", "encoded_by" => "s",
"utime" => "n", "utime" => "d",
"mtime" => "n", "mtime" => "d",
"lptime" => "n", "lptime" => "d",
"genre" => "s", "genre" => "s",
"isrc_number" => "s", "isrc_number" => "s",
"label" => "s", "label" => "s",
@ -115,6 +115,25 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
} }
private function getDateTimeCriteriaOptions()
{
if (!isset($this->dateTimeCriteriaOptions)) {
$this->dateTimeCriteriaOptions = array(
"0" => _("Select modifier"),
"before" => _("before"),
"after" => _("after"),
"between" => _("between"),
"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")
);
}
return $this->dateTimeCriteriaOptions;
}
private function getTimePeriodCriteriaOptions() { private function getTimePeriodCriteriaOptions() {
if (!isset($this->timePeriodCriteriaOptions)) { if (!isset($this->timePeriodCriteriaOptions)) {
$this->timePeriodCriteriaOptions = array( $this->timePeriodCriteriaOptions = array(
@ -183,6 +202,18 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
} }
} }
/*
* This function takes a blockID as param and creates the datastructure for the form displayed with the view
* smart-block-criteria.phtml
*
* A description of the dataflow. First it loads the block and determines if it is a static or dynamic smartblock.
* Next it adds a radio selector for static or dynamic type.
* Then it loads the criteria via the getCriteria() function, which returns an array for each criteria.
*
*
*/
public function startForm($p_blockId, $p_isValid = false) public function startForm($p_blockId, $p_isValid = false)
{ {
// load type // load type
@ -220,20 +251,25 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
$openSmartBlockOption = true; $openSmartBlockOption = true;
} }
// this returns a number indexed array for each criteria found in the database
$criteriaKeys = array(); $criteriaKeys = array();
if (isset($storedCrit["crit"])) { if (isset($storedCrit["crit"])) {
$criteriaKeys = array_keys($storedCrit["crit"]); $criteriaKeys = array_keys($storedCrit["crit"]);
} }
$numElements = count($this->getCriteriaOptions()); $numElements = count($this->getCriteriaOptions());
// loop through once for each potential criteria option ie album, composer, track
for ($i = 0; $i < $numElements; $i++) { for ($i = 0; $i < $numElements; $i++) {
$criteriaType = ""; $criteriaType = "";
// if there is a criteria found then count the number of rows for this specific criteria ie > 1 track title
if (isset($criteriaKeys[$i])) { if (isset($criteriaKeys[$i])) {
$critCount = count($storedCrit["crit"][$criteriaKeys[$i]]); $critCount = count($storedCrit["crit"][$criteriaKeys[$i]]);
} else { } else {
$critCount = 1; $critCount = 1;
} }
// store the number of items with the same key in the ModRowMap
$modRowMap[$i] = $critCount; $modRowMap[$i] = $critCount;
/* Loop through all criteria with the same field /* Loop through all criteria with the same field
@ -241,6 +277,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
*/ */
for ($j = 0; $j < $critCount; $j++) { for ($j = 0; $j < $critCount; $j++) {
/****************** CRITERIA ***********/ /****************** CRITERIA ***********/
// hide the criteria drop down select on any rows after the first
if ($j > 0) { if ($j > 0) {
$invisible = ' sp-invisible'; $invisible = ' sp-invisible';
} else { } else {
@ -252,17 +289,23 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
->setValue('Select criteria') ->setValue('Select criteria')
->setDecorators(array('viewHelper')) ->setDecorators(array('viewHelper'))
->setMultiOptions($this->getCriteriaOptions()); ->setMultiOptions($this->getCriteriaOptions());
// if this isn't the first criteria and there isn't an entry for it already disable it
if ($i != 0 && !isset($criteriaKeys[$i])) { if ($i != 0 && !isset($criteriaKeys[$i])) {
$criteria->setAttrib('disabled', 'disabled'); $criteria->setAttrib('disabled', 'disabled');
} }
// add the numbering to the form ie the i loop for each specific criteria and
// the j loop starts at 0 and grows for each item matching the same criteria
// look up the criteria type using the criteriaTypes function from above based upon the criteria value
if (isset($criteriaKeys[$i])) { if (isset($criteriaKeys[$i])) {
$criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]]; $criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
$criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]); $criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]);
} }
$this->addElement($criteria); $this->addElement($criteria);
/****************** MODIFIER ***********/ /****************** MODIFIER ***********/
// every element has an optional modifier dropdown select
$criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$i."_".$j); $criteriaModifers = new Zend_Form_Element_Select("sp_criteria_modifier_".$i."_".$j);
$criteriaModifers->setValue('Select modifier') $criteriaModifers->setValue('Select modifier')
->setAttrib('class', 'input_select sp_input_select') ->setAttrib('class', 'input_select sp_input_select')
@ -270,10 +313,15 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
if ($i != 0 && !isset($criteriaKeys[$i])) { if ($i != 0 && !isset($criteriaKeys[$i])) {
$criteriaModifers->setAttrib('disabled', 'disabled'); $criteriaModifers->setAttrib('disabled', 'disabled');
} }
// determine the modifier based upon criteria type which is looked up based upon an array
if (isset($criteriaKeys[$i])) { if (isset($criteriaKeys[$i])) {
if ($criteriaType == "s") { if ($criteriaType == "s") {
$criteriaModifers->setMultiOptions($this->getStringCriteriaOptions()); $criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
} else { }
elseif ($criteriaType == "d") {
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
}
else {
$criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions()); $criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
} }
$criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]); $criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]);

View File

@ -1350,6 +1350,13 @@ SQL;
return $insertList; return $insertList;
} }
/**
* Parses each row in the database for the criteria associated with this block and renders human readable labels.
* Returns it as an array with each criteria_name and modifier_name added based upon options array lookup.
*
*/
public function getCriteria() public function getCriteria()
{ {
$criteriaOptions = array( $criteriaOptions = array(
@ -1393,6 +1400,9 @@ SQL;
"is not" => _("is not"), "is not" => _("is not"),
"starts with" => _("starts with"), "starts with" => _("starts with"),
"ends with" => _("ends with"), "ends with" => _("ends with"),
"before" => _("before"),
"after" => _("after"),
"between" => _("between"),
"is" => _("is"), "is" => _("is"),
"is not" => _("is not"), "is not" => _("is not"),
"is greater than" => _("is greater than"), "is greater than" => _("is greater than"),