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-11-15 16:59:06 +01:00
|
|
|
private $criteriaOptions;
|
|
|
|
private $stringCriteriaOptions;
|
|
|
|
private $numericCriteriaOptions;
|
2017-08-17 02:05:02 +02:00
|
|
|
private $dateTimeCriteriaOptions;
|
2017-08-24 16:27:13 +02:00
|
|
|
private $timePeriodCriteriaOptions;
|
2014-10-20 05:02:40 +02:00
|
|
|
private $sortOptions;
|
2012-11-15 16:59:06 +01:00
|
|
|
private $limitOptions;
|
2013-06-20 20:03:13 +02:00
|
|
|
|
2013-02-19 22:38:58 +01:00
|
|
|
/* We need to know if the criteria value will be a string
|
|
|
|
* or numeric value in order to populate the modifier
|
|
|
|
* select list
|
|
|
|
*/
|
2012-08-29 05:04:55 +02:00
|
|
|
private $criteriaTypes = array(
|
2012-11-15 16:59:06 +01:00
|
|
|
0 => "",
|
|
|
|
"album_title" => "s",
|
|
|
|
"bit_rate" => "n",
|
|
|
|
"bpm" => "n",
|
|
|
|
"composer" => "s",
|
|
|
|
"conductor" => "s",
|
|
|
|
"copyright" => "s",
|
2013-02-19 22:38:58 +01:00
|
|
|
"cuein" => "n",
|
|
|
|
"cueout" => "n",
|
2015-09-14 23:00:54 +02:00
|
|
|
"description" => "s",
|
2012-11-15 16:59:06 +01:00
|
|
|
"artist_name" => "s",
|
|
|
|
"encoded_by" => "s",
|
2017-08-16 20:55:48 +02:00
|
|
|
"utime" => "d",
|
|
|
|
"mtime" => "d",
|
|
|
|
"lptime" => "d",
|
2012-11-15 16:59:06 +01:00
|
|
|
"genre" => "s",
|
|
|
|
"isrc_number" => "s",
|
|
|
|
"label" => "s",
|
|
|
|
"language" => "s",
|
|
|
|
"length" => "n",
|
|
|
|
"mime" => "s",
|
|
|
|
"mood" => "s",
|
|
|
|
"owner_id" => "s",
|
|
|
|
"replay_gain" => "n",
|
|
|
|
"sample_rate" => "n",
|
|
|
|
"track_title" => "s",
|
|
|
|
"track_number" => "n",
|
|
|
|
"info_url" => "s",
|
|
|
|
"year" => "n"
|
2012-08-29 05:04:55 +02:00
|
|
|
);
|
2013-06-20 20:03:13 +02:00
|
|
|
|
2012-11-15 16:59:06 +01:00
|
|
|
private function getCriteriaOptions($option = null)
|
|
|
|
{
|
|
|
|
if (!isset($this->criteriaOptions)) {
|
|
|
|
$this->criteriaOptions = array(
|
|
|
|
0 => _("Select criteria"),
|
|
|
|
"album_title" => _("Album"),
|
|
|
|
"bit_rate" => _("Bit Rate (Kbps)"),
|
|
|
|
"bpm" => _("BPM"),
|
|
|
|
"composer" => _("Composer"),
|
|
|
|
"conductor" => _("Conductor"),
|
|
|
|
"copyright" => _("Copyright"),
|
2013-02-19 22:38:58 +01:00
|
|
|
"cuein" => _("Cue In"),
|
|
|
|
"cueout" => _("Cue Out"),
|
2015-09-14 23:00:54 +02:00
|
|
|
"description" => _("Description"),
|
2012-11-15 16:59:06 +01:00
|
|
|
"artist_name" => _("Creator"),
|
|
|
|
"encoded_by" => _("Encoded By"),
|
|
|
|
"genre" => _("Genre"),
|
|
|
|
"isrc_number" => _("ISRC"),
|
|
|
|
"label" => _("Label"),
|
|
|
|
"language" => _("Language"),
|
|
|
|
"mtime" => _("Last Modified"),
|
|
|
|
"lptime" => _("Last Played"),
|
|
|
|
"length" => _("Length"),
|
|
|
|
"mime" => _("Mime"),
|
|
|
|
"mood" => _("Mood"),
|
|
|
|
"owner_id" => _("Owner"),
|
|
|
|
"replay_gain" => _("Replay Gain"),
|
|
|
|
"sample_rate" => _("Sample Rate (kHz)"),
|
|
|
|
"track_title" => _("Title"),
|
|
|
|
"track_number" => _("Track Number"),
|
|
|
|
"utime" => _("Uploaded"),
|
|
|
|
"info_url" => _("Website"),
|
|
|
|
"year" => _("Year")
|
|
|
|
);
|
|
|
|
}
|
2013-06-20 20:03:13 +02:00
|
|
|
|
2012-11-15 16:59:06 +01:00
|
|
|
if (is_null($option)) return $this->criteriaOptions;
|
|
|
|
else return $this->criteriaOptions[$option];
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-11-15 16:59:06 +01:00
|
|
|
private function getStringCriteriaOptions()
|
|
|
|
{
|
|
|
|
if (!isset($this->stringCriteriaOptions)) {
|
|
|
|
$this->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")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->stringCriteriaOptions;
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-11-15 16:59:06 +01:00
|
|
|
private function getNumericCriteriaOptions()
|
|
|
|
{
|
|
|
|
if (!isset($this->numericCriteriaOptions)) {
|
|
|
|
$this->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")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->numericCriteriaOptions;
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2017-08-16 05:25:11 +02:00
|
|
|
|
2017-08-16 20:55:48 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-24 16:27:13 +02:00
|
|
|
private function getTimePeriodCriteriaOptions()
|
|
|
|
{
|
2017-08-16 05:25:11 +02:00
|
|
|
if (!isset($this->timePeriodCriteriaOptions)) {
|
|
|
|
$this->timePeriodCriteriaOptions = array(
|
|
|
|
"0" => _("Select unit of time"),
|
2017-08-24 16:27:13 +02:00
|
|
|
"minute" => _("minute(s)"),
|
|
|
|
"hour" => _("hour(s)"),
|
|
|
|
"day" => _("day(s)"),
|
|
|
|
"week" => _("week(s)"),
|
2017-10-15 06:03:36 +02:00
|
|
|
"month" => _("month(s)"),
|
2017-08-24 16:27:13 +02:00
|
|
|
"year" => _("year(s)")
|
2017-08-16 05:25:11 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->timePeriodCriteriaOptions;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-15 16:59:06 +01:00
|
|
|
private function getLimitOptions()
|
|
|
|
{
|
|
|
|
if (!isset($this->limitOptions)) {
|
|
|
|
$this->limitOptions = array(
|
|
|
|
"hours" => _("hours"),
|
|
|
|
"minutes" => _("minutes"),
|
2018-11-24 23:08:39 +01:00
|
|
|
"items" => _("items"),
|
2018-11-26 21:26:19 +01:00
|
|
|
"remaining" => _("time remaining in show")
|
2012-11-15 16:59:06 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->limitOptions;
|
|
|
|
}
|
2014-10-20 05:02:40 +02:00
|
|
|
private function getSortOptions()
|
|
|
|
{
|
|
|
|
if (!isset($this->sortOptions)) {
|
|
|
|
$this->sortOptions = array(
|
2015-08-26 19:10:51 +02:00
|
|
|
"random" => _("Randomly"),
|
|
|
|
"newest" => _("Newest"),
|
|
|
|
"oldest" => _("Oldest")
|
2014-10-20 05:02:40 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return $this->sortOptions;
|
|
|
|
}
|
2013-06-20 20:03:13 +02:00
|
|
|
|
2012-08-29 05:04:55 +02:00
|
|
|
|
|
|
|
public function init()
|
|
|
|
{
|
2012-07-24 18:13:51 +02:00
|
|
|
}
|
2013-12-11 23:35:31 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* converts UTC timestamp citeria into user timezone strings.
|
|
|
|
*/
|
|
|
|
private function convertTimestamps(&$criteria)
|
|
|
|
{
|
|
|
|
$columns = array("utime", "mtime", "lptime");
|
|
|
|
|
|
|
|
foreach ($columns as $column) {
|
|
|
|
|
|
|
|
if (isset($criteria[$column])) {
|
|
|
|
|
|
|
|
foreach ($criteria[$column] as &$constraint) {
|
2017-10-14 07:00:06 +02:00
|
|
|
// convert to appropriate timezone timestamps only if the modifier is not a relative time
|
|
|
|
if (!in_array($constraint['modifier'], array('before','after','between'))) {
|
2018-01-09 03:48:31 +01:00
|
|
|
$constraint['value'] =
|
|
|
|
Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['value']);
|
2017-10-14 07:00:06 +02:00
|
|
|
if (isset($constraint['extra'])) {
|
|
|
|
$constraint['extra'] =
|
|
|
|
Application_Common_DateHelper::UTCStringToUserTimezoneString($constraint['extra']);
|
|
|
|
}
|
|
|
|
}
|
2013-12-11 23:35:31 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2017-08-16 20:55:48 +02:00
|
|
|
/*
|
2017-10-14 07:00:06 +02:00
|
|
|
* This function takes a blockID as param and creates the data structure for the form displayed with the view
|
2017-08-16 20:55:48 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
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);
|
2018-12-12 03:14:35 +01:00
|
|
|
if ($out->getDbType() == "dynamic") {
|
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');
|
2015-08-26 19:10:51 +02:00
|
|
|
$spType->setLabel(_('Type:'))
|
2012-07-24 18:13:51 +02:00
|
|
|
->setDecorators(array('viewHelper'))
|
|
|
|
->setMultiOptions(array(
|
2018-12-12 03:14:35 +01:00
|
|
|
'dynamic' => _('Dynamic'),
|
|
|
|
'static' => _('Static')
|
|
|
|
|
2012-07-24 18:13:51 +02:00
|
|
|
))
|
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();
|
2013-12-11 23:35:31 +01:00
|
|
|
|
|
|
|
//need to convert criteria to be displayed in the user's timezone if there's some timestamp type.
|
|
|
|
self::convertTimestamps($storedCrit["crit"]);
|
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
|
|
|
|
2017-08-16 20:55:48 +02:00
|
|
|
// this returns a number indexed array for each criteria found in the database
|
2012-07-30 22:42:37 +02:00
|
|
|
$criteriaKeys = array();
|
|
|
|
if (isset($storedCrit["crit"])) {
|
|
|
|
$criteriaKeys = array_keys($storedCrit["crit"]);
|
|
|
|
}
|
2012-11-15 16:59:06 +01:00
|
|
|
$numElements = count($this->getCriteriaOptions());
|
2017-08-16 20:55:48 +02:00
|
|
|
// loop through once for each potential criteria option ie album, composer, track
|
|
|
|
|
2012-07-24 18:13:51 +02:00
|
|
|
for ($i = 0; $i < $numElements; $i++) {
|
|
|
|
$criteriaType = "";
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2017-08-16 20:55:48 +02:00
|
|
|
// if there is a criteria found then count the number of rows for this specific criteria ie > 1 track title
|
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
|
|
|
|
2017-08-16 20:55:48 +02:00
|
|
|
// store the number of items with the same key in the ModRowMap
|
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 ***********/
|
2017-08-16 20:55:48 +02:00
|
|
|
// hide the criteria drop down select on any rows after the first
|
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-11-15 16:59:06 +01:00
|
|
|
->setMultiOptions($this->getCriteriaOptions());
|
2017-08-16 20:55:48 +02:00
|
|
|
// if this isn't the first criteria and there isn't an entry for it already disable it
|
2012-08-14 16:02:36 +02:00
|
|
|
if ($i != 0 && !isset($criteriaKeys[$i])) {
|
|
|
|
$criteria->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
2017-08-16 20:55:48 +02:00
|
|
|
// 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
|
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
|
|
|
|
2017-08-16 20:55:48 +02:00
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
/****************** MODIFIER ***********/
|
2017-08-16 20:55:48 +02:00
|
|
|
// every element has an optional modifier dropdown select
|
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
$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');
|
|
|
|
}
|
2017-08-16 20:55:48 +02:00
|
|
|
// determine the modifier based upon criteria type which is looked up based upon an array
|
2012-08-14 16:02:36 +02:00
|
|
|
if (isset($criteriaKeys[$i])) {
|
2012-08-29 05:04:55 +02:00
|
|
|
if ($criteriaType == "s") {
|
2012-11-15 16:59:06 +01:00
|
|
|
$criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
|
2017-08-16 20:55:48 +02:00
|
|
|
}
|
|
|
|
elseif ($criteriaType == "d") {
|
|
|
|
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
|
|
|
|
}
|
|
|
|
else {
|
2012-11-15 16:59:06 +01:00
|
|
|
$criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
|
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-11-15 16:59:06 +01:00
|
|
|
$criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
|
2012-08-14 16:02:36 +02:00
|
|
|
}
|
|
|
|
$this->addElement($criteriaModifers);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2012-08-14 16:02:36 +02:00
|
|
|
/****************** VALUE ***********/
|
2017-10-14 07:00:06 +02:00
|
|
|
/* The challenge here is that datetime */
|
2012-08-14 16:02:36 +02:00
|
|
|
$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])) {
|
2017-10-14 07:00:06 +02:00
|
|
|
/*
|
|
|
|
* Need to parse relative dates in a special way to populate select box down below
|
|
|
|
*/
|
2017-10-15 05:51:18 +02:00
|
|
|
// this is used below to test whether the datetime select should be shown or hidden
|
|
|
|
$relativeDateTime = false;
|
2017-10-14 07:00:06 +02:00
|
|
|
$modifierTest = (string)$storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"];
|
|
|
|
if(isset($criteriaType) && $criteriaType == "d" &&
|
|
|
|
preg_match('/before|after|between/', $modifierTest) == 1) {
|
2017-10-15 05:51:18 +02:00
|
|
|
// set relativeDatetime boolean to true so that the datetime select is displayed below
|
|
|
|
$relativeDateTime = true;
|
2017-10-14 07:00:06 +02:00
|
|
|
// the criteria value will be a number followed by time unit and ago so set input to number part
|
|
|
|
$criteriaValue->setValue(filter_var($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"], FILTER_SANITIZE_NUMBER_INT));
|
|
|
|
} else {
|
|
|
|
$criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
|
|
|
}
|
2012-08-14 16:02:36 +02:00
|
|
|
}
|
|
|
|
$this->addElement($criteriaValue);
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2017-08-24 16:27:13 +02:00
|
|
|
|
|
|
|
/****************** DATETIME SELECT *************/
|
|
|
|
$criteriaDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_datetime_select_".$i."_".$j);
|
|
|
|
$criteriaDatetimeSelect->setAttrib('class','input_select sp_input_select')
|
|
|
|
->setDecorators(array('viewHelper'));
|
2018-01-09 03:48:31 +01:00
|
|
|
if (isset($criteriaKeys[$i]) && $relativeDateTime) {
|
|
|
|
$criteriaDatetimeSelect->setAttrib('enabled', 'enabled');
|
|
|
|
}
|
|
|
|
else {
|
2017-08-24 16:27:13 +02:00
|
|
|
$criteriaDatetimeSelect->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
2017-10-14 07:00:06 +02:00
|
|
|
// check if the value is stored and it is a relative datetime field
|
|
|
|
if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"])
|
|
|
|
&& isset($criteriaType) && $criteriaType == "d" &&
|
|
|
|
preg_match('/before|after|between/', $modifierTest) == 1) {
|
2018-01-09 03:48:31 +01:00
|
|
|
// need to remove any leading numbers stored in the database
|
2017-10-14 07:00:06 +02:00
|
|
|
$dateTimeSelectValue = preg_replace('/[0-9]+/', '', $storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
|
|
|
|
// need to strip white from front and ago from the end to match with the value of the time unit select dropdown
|
|
|
|
$dateTimeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $dateTimeSelectValue));
|
|
|
|
$criteriaDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
|
|
|
|
$criteriaDatetimeSelect->setValue($dateTimeSelectValue);
|
|
|
|
$criteriaDatetimeSelect->setAttrib('enabled', 'enabled');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$criteriaDatetimeSelect->setMultiOptions(array('0' => _('Select unit of time')));
|
|
|
|
$criteriaDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
|
|
|
|
|
2017-08-24 16:27:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->addElement($criteriaDatetimeSelect);
|
|
|
|
|
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"])) {
|
2017-10-14 07:00:06 +02:00
|
|
|
// need to check if this is a relative date time value
|
|
|
|
if(isset($criteriaType) && $criteriaType == "d" && $modifierTest == 'between') {
|
|
|
|
// the criteria value will be a number followed by time unit and ago so set input to number part
|
|
|
|
$criteriaExtra->setValue(filter_var($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"], FILTER_SANITIZE_NUMBER_INT));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$criteriaExtra->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]);
|
|
|
|
}
|
2012-08-14 16:02:36 +02:00
|
|
|
$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);
|
2017-10-14 07:00:06 +02:00
|
|
|
/****************** DATETIME SELECT EXTRA **********/
|
|
|
|
|
|
|
|
$criteriaExtraDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_extra_datetime_select_".$i."_".$j);
|
|
|
|
$criteriaExtraDatetimeSelect->setAttrib('class','input_select sp_input_select')
|
|
|
|
->setDecorators(array('viewHelper'));
|
|
|
|
|
|
|
|
if (isset($criteriaKeys[$i]) && isset($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"])
|
|
|
|
&& $modifierTest == 'between') {
|
|
|
|
// need to remove the leading numbers stored in the database
|
|
|
|
$extraDateTimeSelectValue = preg_replace('/[0-9]+/', '', $storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]);
|
|
|
|
// need to strip white from front and ago from the end to match with the value of the time unit select dropdown
|
|
|
|
$extraDateTimeSelectValue = trim(preg_replace('/\W\w+\s*(\W*)$/', '$1', $extraDateTimeSelectValue));
|
|
|
|
$criteriaExtraDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
|
2017-10-15 05:15:47 +02:00
|
|
|
// Logging::info('THIS IS-'.$extraDateTimeSelectValue.'-IT');
|
2017-10-14 07:00:06 +02:00
|
|
|
$criteriaExtraDatetimeSelect->setValue($extraDateTimeSelectValue);
|
|
|
|
$criteriaExtraDatetimeSelect->setAttrib('enabled', 'enabled');
|
2012-08-29 05:04:55 +02:00
|
|
|
|
2017-10-14 07:00:06 +02:00
|
|
|
} else {
|
|
|
|
$criteriaExtraDatetimeSelect->setMultiOptions(array('0' => _('Select unit of time')));
|
|
|
|
$criteriaExtraDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
|
|
|
|
$criteriaExtraDatetimeSelect->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
|
|
|
$this->addElement($criteriaExtraDatetimeSelect);
|
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-10-30 23:03:03 +01:00
|
|
|
$repeatTracks = new Zend_Form_Element_Checkbox('sp_repeat_tracks');
|
|
|
|
$repeatTracks->setDecorators(array('viewHelper'))
|
2015-08-26 19:10:51 +02:00
|
|
|
->setLabel(_('Allow Repeated Tracks:'));
|
2012-10-30 23:03:03 +01:00
|
|
|
if (isset($storedCrit["repeat_tracks"])) {
|
|
|
|
$repeatTracks->setChecked($storedCrit["repeat_tracks"]["value"] == 1?true:false);
|
2012-10-30 22:57:58 +01:00
|
|
|
}
|
|
|
|
$this->addElement($repeatTracks);
|
2013-06-20 20:03:13 +02:00
|
|
|
|
2018-11-25 19:16:26 +01:00
|
|
|
$overflowTracks = new Zend_Form_Element_Checkbox('sp_overflow_tracks');
|
|
|
|
$overflowTracks->setDecorators(array('viewHelper'))
|
2018-12-11 20:58:23 +01:00
|
|
|
->setLabel(_('Allow last track to exceed time limit:'));
|
2018-11-25 19:16:26 +01:00
|
|
|
if (isset($storedCrit["overflow_tracks"])) {
|
2018-11-26 00:28:14 +01:00
|
|
|
$overflowTracks->setChecked($storedCrit["overflow_tracks"]["value"] == 1);
|
2018-11-25 19:16:26 +01:00
|
|
|
}
|
|
|
|
$this->addElement($overflowTracks);
|
|
|
|
|
2014-10-20 05:02:40 +02:00
|
|
|
$sort = new Zend_Form_Element_Select('sp_sort_options');
|
|
|
|
$sort->setAttrib('class', 'sp_input_select')
|
|
|
|
->setDecorators(array('viewHelper'))
|
2015-08-26 19:10:51 +02:00
|
|
|
->setLabel(_("Sort Tracks:"))
|
2014-10-20 05:02:40 +02:00
|
|
|
->setMultiOptions($this->getSortOptions());
|
|
|
|
if (isset($storedCrit["sort"])) {
|
|
|
|
$sort->setValue($storedCrit["sort"]["value"]);
|
|
|
|
}
|
|
|
|
$this->addElement($sort);
|
|
|
|
|
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-11-15 16:59:06 +01:00
|
|
|
->setMultiOptions($this->getLimitOptions());
|
2012-07-24 18:13:51 +02:00
|
|
|
if (isset($storedCrit["limit"])) {
|
|
|
|
$limit->setValue($storedCrit["limit"]["modifier"]);
|
|
|
|
}
|
|
|
|
$this->addElement($limit);
|
2013-06-20 20:03:13 +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')
|
2015-08-26 19:10:51 +02:00
|
|
|
->setLabel(_('Limit to:'))
|
2012-07-24 18:13:51 +02:00
|
|
|
->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-24 18:13:51 +02:00
|
|
|
$generate = new Zend_Form_Element_Button('generate_button');
|
2015-08-18 21:23:42 +02:00
|
|
|
$generate->setAttrib('class', 'sp-button btn');
|
2012-11-15 16:59:06 +01:00
|
|
|
$generate->setAttrib('title', _('Generate playlist content and save criteria'));
|
2012-07-24 18:13:51 +02:00
|
|
|
$generate->setIgnore(true);
|
2017-11-22 03:22:06 +01:00
|
|
|
if ($blockType == 0) {
|
2018-12-12 03:14:35 +01:00
|
|
|
$generate->setLabel(_('Preview'));
|
2017-11-22 03:22:06 +01:00
|
|
|
}
|
|
|
|
else {
|
2018-12-12 03:14:35 +01:00
|
|
|
$generate->setLabel(_('Generate'));
|
2017-11-22 03:22:06 +01:00
|
|
|
}
|
2012-07-24 18:13:51 +02:00
|
|
|
$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');
|
2015-08-18 21:23:42 +02:00
|
|
|
$shuffle->setAttrib('class', 'sp-button btn');
|
2012-11-15 16:59:06 +01:00
|
|
|
$shuffle->setAttrib('title', _('Shuffle playlist content'));
|
2012-07-24 18:13:51 +02:00
|
|
|
$shuffle->setIgnore(true);
|
2012-11-15 16:59:06 +01:00
|
|
|
$shuffle->setLabel(_('Shuffle'));
|
2012-07-24 18:13:51 +02:00
|
|
|
$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,
|
2018-01-04 00:57:02 +01:00
|
|
|
'criteriasLength' => count($this->getCriteriaOptions()), 'modRowMap' => $modRowMap))
|
2012-07-24 18:13:51 +02:00
|
|
|
));
|
|
|
|
}
|
2018-01-09 03:48:31 +01:00
|
|
|
/*
|
|
|
|
* This is a simple function that determines if a modValue should enable a datetime
|
|
|
|
*/
|
|
|
|
public function enableDateTimeUnit($modValue) {
|
|
|
|
return (preg_match('/before|after|between/', $modValue) == 1);
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
|
|
|
|
public function preValidation($params)
|
|
|
|
{
|
2014-10-20 05:02:40 +02:00
|
|
|
$data = Application_Model_Block::organizeSmartPlaylistCriteria($params['data']);
|
2012-08-29 05:04:55 +02:00
|
|
|
// add elelments that needs to be added
|
2012-11-28 17:54:22 +01:00
|
|
|
// set multioption for modifier according to criteria_field
|
2012-08-15 22:22:56 +02:00
|
|
|
$modRowMap = array();
|
2015-09-02 22:25:30 +02:00
|
|
|
if (!isset($data['criteria'])) {
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
2012-08-15 22:22:56 +02:00
|
|
|
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);
|
2012-11-15 16:59:06 +01:00
|
|
|
$eleCrit->setValue($this->getCriteriaOptions($modInfo['sp_criteria_field']));
|
2012-08-15 22:22:56 +02:00
|
|
|
$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") {
|
2012-11-15 16:59:06 +01:00
|
|
|
$eleMod->setMultiOptions($this->getStringCriteriaOptions());
|
2012-08-29 05:04:55 +02:00
|
|
|
} elseif ($criteriaType == "n") {
|
2012-11-15 16:59:06 +01:00
|
|
|
$eleMod->setMultiOptions($this->getNumericCriteriaOptions());
|
2017-10-15 05:15:47 +02:00
|
|
|
} elseif ($criteriaType == "d") {
|
|
|
|
$eleMod->setMultiOptions($this->getDateTimeCriteriaOptions());
|
2012-08-15 22:22:56 +02:00
|
|
|
} else {
|
2012-11-15 16:59:06 +01:00
|
|
|
$eleMod->setMultiOptions(array('0' => _('Select modifier')));
|
2012-08-15 22:22:56 +02:00
|
|
|
}
|
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
|
|
|
|
2018-01-09 03:48:31 +01:00
|
|
|
$eleDatetime = $this->getElement("sp_criteria_datetime_select_".$critKey."_".$modKey);
|
|
|
|
if ($this->enableDateTimeUnit($eleMod->getValue())) {
|
|
|
|
$eleDatetime->setAttrib("enabled", "enabled");
|
|
|
|
$eleDatetime->setValue($modInfo['sp_criteria_datetime_select']);
|
|
|
|
$eleDatetime->setAttrib("disabled", null);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$eleDatetime->setAttrib("disabled","disabled");
|
|
|
|
}
|
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);
|
|
|
|
}
|
2018-01-09 03:48:31 +01:00
|
|
|
$eleExtraDatetime = $this->getElement("sp_criteria_extra_datetime_select_".$critKey."_".$modKey);
|
|
|
|
if ($eleMod->getValue() == 'between') {
|
|
|
|
$eleExtraDatetime->setAttrib("enabled", "enabled");
|
|
|
|
$eleExtraDatetime->setValue($modInfo['sp_criteria_extra_datetime_select']);
|
|
|
|
$eleExtraDatetime->setAttrib("disabled", null);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$eleExtraDatetime->setAttrib("disabled","disabled");
|
|
|
|
}
|
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'))
|
2012-11-15 16:59:06 +01:00
|
|
|
->setMultiOptions($this->getCriteriaOptions());
|
2012-08-29 05:04:55 +02:00
|
|
|
|
|
|
|
$criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']];
|
2012-11-15 16:59:06 +01:00
|
|
|
$criteria->setValue($this->getCriteriaOptions($modInfo['sp_criteria_field']));
|
2012-08-29 05:04:55 +02:00
|
|
|
$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") {
|
2012-11-15 16:59:06 +01:00
|
|
|
$criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
|
2012-08-29 05:04:55 +02:00
|
|
|
} elseif ($criteriaType == "n") {
|
2012-11-15 16:59:06 +01:00
|
|
|
$criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
|
2017-10-15 05:15:47 +02:00
|
|
|
}
|
|
|
|
elseif ($criteriaType == "d") {
|
|
|
|
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
|
2012-08-29 05:04:55 +02:00
|
|
|
} else {
|
2012-11-15 16:59:06 +01:00
|
|
|
$criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
|
2012-08-29 05:04:55 +02:00
|
|
|
}
|
|
|
|
$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);
|
2018-01-09 03:48:31 +01:00
|
|
|
/****************** DATETIME UNIT SELECT ***********/
|
|
|
|
|
|
|
|
$criteriaDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_datetime_select_".$critKey."_".$modKey);
|
|
|
|
$criteriaDatetimeSelect->setAttrib('class','input_select sp_input_select')
|
|
|
|
->setDecorators(array('viewHelper'));
|
|
|
|
if ($this->enableDateTimeUnit($criteriaValue->getValue())) {
|
|
|
|
$criteriaDatetimeSelect->setAttrib('enabled', 'enabled');
|
|
|
|
$criteriaDatetimeSelect->setAttrib('disabled', null);
|
|
|
|
$criteriaDatetimeSelect->setValue($modInfo['sp_criteria_datetime_select']);
|
|
|
|
$this->addElement($criteriaDatetimeSelect);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$criteriaDatetimeSelect->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
2012-08-29 05:04:55 +02:00
|
|
|
/****************** 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);
|
2018-01-09 03:48:31 +01:00
|
|
|
|
|
|
|
/****************** EXTRA DATETIME UNIT SELECT ***********/
|
|
|
|
|
|
|
|
$criteriaExtraDatetimeSelect = new Zend_Form_Element_Select("sp_criteria_extra_datetime_select_".$critKey."_".$modKey);
|
|
|
|
$criteriaExtraDatetimeSelect->setAttrib('class','input_select sp_input_select')
|
|
|
|
->setDecorators(array('viewHelper'));
|
|
|
|
if ($criteriaValue->getValue() == 'between') {
|
|
|
|
$criteriaExtraDatetimeSelect->setAttrib('enabled', 'enabled');
|
|
|
|
$criteriaExtraDatetimeSelect->setAttrib('disabled', null);
|
|
|
|
$criteriaExtraDatetimeSelect->setValue($modInfo['sp_criteria_extra_datetime_select']);
|
|
|
|
$this->addElement($criteriaExtraDatetimeSelect);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$criteriaExtraDatetimeSelect->setAttrib('disabled', 'disabled');
|
|
|
|
}
|
2012-08-15 22:22:56 +02:00
|
|
|
$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
|
|
|
|
2017-10-15 05:15:47 +02:00
|
|
|
// Logging::info($formData);
|
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(
|
2013-02-19 22:38:58 +01:00
|
|
|
0 => "Select criteria",
|
|
|
|
"album_title" => "DbAlbumTitle",
|
|
|
|
"artist_name" => "DbArtistName",
|
|
|
|
"bit_rate" => "DbBitRate",
|
|
|
|
"bpm" => "DbBpm",
|
|
|
|
"composer" => "DbComposer",
|
|
|
|
"conductor" => "DbConductor",
|
|
|
|
"copyright" => "DbCopyright",
|
|
|
|
"cuein" => "DbCuein",
|
|
|
|
"cueout" => "DbCueout",
|
2015-09-14 23:00:54 +02:00
|
|
|
"description" => "DbDescription",
|
2013-02-19 22:38:58 +01:00
|
|
|
"encoded_by" => "DbEncodedBy",
|
|
|
|
"utime" => "DbUtime",
|
|
|
|
"mtime" => "DbMtime",
|
|
|
|
"lptime" => "DbLPtime",
|
|
|
|
"genre" => "DbGenre",
|
|
|
|
"info_url" => "DbInfoUrl",
|
|
|
|
"isrc_number" => "DbIsrcNumber",
|
|
|
|
"label" => "DbLabel",
|
|
|
|
"language" => "DbLanguage",
|
|
|
|
"length" => "DbLength",
|
|
|
|
"mime" => "DbMime",
|
|
|
|
"mood" => "DbMood",
|
|
|
|
"owner_id" => "DbOwnerId",
|
|
|
|
"replay_gain" => "DbReplayGain",
|
|
|
|
"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;
|
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) {
|
2012-11-15 16:59:06 +01:00
|
|
|
$element->addError(_("Limit cannot be empty or smaller than 0"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
} else {
|
|
|
|
$mins = floatval($data['etc']['sp_limit_value']) * $multiplier;
|
2012-08-15 17:36:41 +02:00
|
|
|
if ($mins > 1440) {
|
2012-11-15 16:59:06 +01:00
|
|
|
$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-11-15 16:59:06 +01:00
|
|
|
$element->addError(_("Limit cannot be empty or smaller than 0"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
} elseif (!ctype_digit($data['etc']['sp_limit_value'])) {
|
2012-11-15 16:59:06 +01:00
|
|
|
$element->addError(_("The value should be an integer"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
} elseif (intval($data['etc']['sp_limit_value']) > 500) {
|
2012-11-15 16:59:06 +01:00
|
|
|
$element->addError(_("500 is the max item limit value you can set"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$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
|
|
|
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);
|
|
|
|
// check for not selected select box
|
|
|
|
if ($d['sp_criteria_field'] == "0" || $d['sp_criteria_modifier'] == "0") {
|
2012-11-15 16:59:06 +01:00
|
|
|
$element->addError(_("You must select Criteria and Modifier"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
} else {
|
|
|
|
$column = CcFilesPeer::getTableMap()->getColumnByPhpName($criteria2PeerMap[$d['sp_criteria_field']]);
|
|
|
|
// validation on type of column
|
2013-02-19 22:38:58 +01:00
|
|
|
if (in_array($d['sp_criteria_field'], array('length', 'cuein', 'cueout'))) {
|
2012-10-19 20:27:57 +02:00
|
|
|
if (!preg_match("/^(\d{2}):(\d{2}):(\d{2})/", $d['sp_criteria_value'])) {
|
2012-11-15 16:59:06 +01:00
|
|
|
$element->addError(_("'Length' should be in '00:00:00' format"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
}
|
2017-08-17 02:05:02 +02:00
|
|
|
// this looks up the column type for the criteria the modified time, upload time etc.
|
2012-08-29 05:04:55 +02:00
|
|
|
} elseif ($column->getType() == PropelColumnTypes::TIMESTAMP) {
|
2017-08-17 02:05:02 +02:00
|
|
|
// need to check for relative modifiers first - bypassing currently
|
2017-10-14 07:00:06 +02:00
|
|
|
if (in_array($d['sp_criteria_modifier'], array('before','after','between'))) {
|
2017-10-15 05:15:47 +02:00
|
|
|
if (!preg_match("/^[1-9][0-9]*$|0/",$d['sp_criteria_value'])) {
|
|
|
|
$element->addError(_("Only non-negative integer numbers are allowed (e.g 1 or 5) for the text value"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
2017-10-15 05:15:47 +02:00
|
|
|
// TODO validate this on numeric input with whatever parsing also do for extra
|
|
|
|
//if the modifier is before ago or between we skip validation until we confirm format
|
2012-08-29 05:04:55 +02:00
|
|
|
}
|
2017-10-15 05:15:47 +02:00
|
|
|
elseif (isSet($d['sp_criteria_datetime_select']) && $d['sp_criteria_datetime_select'] == "0") {
|
|
|
|
$element->addError(_("You must select a time unit for a relative datetime."));
|
|
|
|
$isValid = false;
|
2012-08-29 05:04:55 +02:00
|
|
|
}
|
2017-10-15 05:15:47 +02:00
|
|
|
} else {
|
2017-08-17 02:05:02 +02:00
|
|
|
if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) {
|
2013-05-22 11:25:43 +02:00
|
|
|
$element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-00-00 00:00:00)"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
} else {
|
2017-08-17 02:05:02 +02:00
|
|
|
$result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']);
|
2012-08-29 05:04:55 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-08-17 02:05:02 +02:00
|
|
|
if (isset($d['sp_criteria_extra'])) {
|
|
|
|
if ($d['sp_criteria_modifier'] == 'between') {
|
2017-10-15 05:15:47 +02:00
|
|
|
// validate that the input value only contains a number if using relative date times
|
|
|
|
if (!preg_match("/^[1-9][0-9]*$|0/",$d['sp_criteria_extra'])) {
|
|
|
|
$element->addError(_("Only non-negative integer numbers are allowed for a relative date time"));
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
// also need to check to make sure they chose a time unit from the dropdown
|
|
|
|
elseif ($d['sp_criteria_extra_datetime_select'] == "0") {
|
|
|
|
$element->addError(_("You must select a time unit for a relative datetime."));
|
|
|
|
$isValid = false;
|
|
|
|
}
|
2017-08-17 02:05:02 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) {
|
|
|
|
$element->addError(_("The value should be in timestamp format (e.g. 0000-00-00 or 0000-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 )
|
|
|
|
$element->addError($result["errMsg"]);
|
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-09-11 23:18:17 +02:00
|
|
|
} elseif ($column->getType() == PropelColumnTypes::INTEGER &&
|
|
|
|
$d['sp_criteria_field'] != 'owner_id') {
|
2012-08-15 17:36:41 +02:00
|
|
|
if (!is_numeric($d['sp_criteria_value'])) {
|
2012-11-15 16:59:06 +01:00
|
|
|
$element->addError(_("The value has to be numeric"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
// length check
|
2013-06-20 20:03:13 +02:00
|
|
|
if ($d['sp_criteria_value'] >= pow(2,31)) {
|
2012-11-15 16:59:06 +01:00
|
|
|
$element->addError(_("The value should be less then 2147483648"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
} elseif ($column->getType() == PropelColumnTypes::VARCHAR) {
|
2012-08-15 17:36:41 +02:00
|
|
|
if (strlen($d['sp_criteria_value']) > $column->getSize()) {
|
2012-11-15 16:59:06 +01:00
|
|
|
$element->addError(sprintf(_("The value should be less than %s characters"), $column->getSize()));
|
2012-08-29 05:04:55 +02:00
|
|
|
$isValid = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-15 17:36:41 +02:00
|
|
|
if ($d['sp_criteria_value'] == "") {
|
2012-11-15 16:59:06 +01:00
|
|
|
$element->addError(_("Value cannot be empty"));
|
2012-08-29 05:04:55 +02:00
|
|
|
$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
|
|
|
}
|