diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 0461142ea..e16c41eb1 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -4,6 +4,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm private $criteriaOptions; private $stringCriteriaOptions; private $numericCriteriaOptions; + private $dateTimeCriteriaOptions; private $sortOptions; private $limitOptions; @@ -629,25 +630,18 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $element->addError(_("'Length' should be in '00:00:00' format")); $isValid = false; } + // this looks up the column type for the criteria the modified time, upload time etc. } elseif ($column->getType() == PropelColumnTypes::TIMESTAMP) { - if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) { - $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_value']); - if (!$result["success"]) { - // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 ) - $element->addError($result["errMsg"]); - $isValid = false; + // need to check for relative modifiers first - bypassing currently + if (in_array($d['sp_criteria_modifier'], array('before','ago','between'))) { + //if the modifier is before ago or between we skip validation until we confirm format } - } - - if (isset($d['sp_criteria_extra'])) { - if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) { + else { + if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) { $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']); + $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']); if (!$result["success"]) { // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 ) $element->addError($result["errMsg"]); @@ -655,6 +649,24 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } } } + if (isset($d['sp_criteria_extra'])) { + if ($d['sp_criteria_modifier'] == 'between') { + //disabling validation as this doesn't require the same format + } + 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; + } + } + } + } } elseif ($column->getType() == PropelColumnTypes::INTEGER && $d['sp_criteria_field'] != 'owner_id') { if (!is_numeric($d['sp_criteria_value'])) { diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 1ca0e354b..0fe87df43 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -51,7 +51,10 @@ class Application_Model_Block implements Application_Model_LibraryEditable "ends with" => Criteria::ILIKE, "is greater than" => Criteria::GREATER_THAN, "is less than" => Criteria::LESS_THAN, - "is in the range" => Criteria::CUSTOM); + "is in the range" => Criteria::CUSTOM, + "before" => Criteria::CUSTOM, + "after" => Criteria::CUSTOM, + "between" => Criteria::CUSTOM); private static $criteria2PeerMap = array( 0 => "Select criteria", @@ -1197,9 +1200,13 @@ SQL; $field = $d['sp_criteria_field']; $value = $d['sp_criteria_value']; + $modifier = $d['sp_criteria_modifier']; if ($field == 'utime' || $field == 'mtime' || $field == 'lptime') { - $value = Application_Common_DateHelper::UserTimezoneStringToUTCString($value); + // if the date isn't relative we want to convert the value to a specific UTC date + if (!in_array($modifier,array('before','ago','between'))) { + $value = Application_Common_DateHelper::UserTimezoneStringToUTCString($value); + } } $qry = new CcBlockcriteria(); @@ -1463,9 +1470,9 @@ SQL; //data should already be in UTC, do we have to do anything special here anymore? if ($column->getType() == PropelColumnTypes::TIMESTAMP) { - + $spCriteriaValue = $criteria['value']; - + if (isset($criteria['extra'])) { $spCriteriaExtra = $criteria['extra']; } @@ -1511,6 +1518,26 @@ SQL; } elseif ($spCriteriaModifier == "is in the range") { $spCriteriaValue = "$spCriteria >= '$spCriteriaValue' AND $spCriteria <= '$spCriteriaExtra'"; } + elseif ($spCriteriaModifier == "before") { + // need to pull in the current time and subtract the value or figure out how to make it relative + $relativedate = new DateTime($spCriteriaValue); + $dt = $relativedate->format(DateTime::ISO8601); + $spCriteriaValue = "$spCriteria <= '$dt'"; + Logging::info($spCriteriaValue); + } + elseif ($spCriteriaModifier == "after") { + $relativedate = new DateTime($spCriteriaValue); + $dt = $relativedate->format(DateTime::ISO8601); + $spCriteriaValue = "$spCriteria >= '$dt'"; + Logging::info($spCriteriaValue); + } elseif ($spCriteriaModifier == "between") { + $fromrelativedate = new DateTime($spCriteriaValue); + $fdt = $fromrelativedate->format(DateTime::ISO8601); + + $torelativedate = new DateTime($spCriteriaValue); + $tdt = $fromrelativedate->format(DateTime::ISO8601); + $spCriteriaValue = "$spCriteria >= '$fdt' AND $spCriteria <= '$tdt'"; + } $spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier]; diff --git a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js index 0bbc16852..910c67256 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_blockbuilder.js @@ -484,7 +484,15 @@ function populateModifierSelect(e, popAllMods) { .attr('value', key) .text(value)); }); - } else { + } + else if(criteria_type == 'd') { + $.each(dateTimeCriteriaOptions, function(key, value){ + $(div).append($('') + .attr('value', key) + .text(value)); + }); + } + else { $.each(numericCriteriaOptions, function(key, value){ $(div).append($('') .attr('value', key) @@ -610,9 +618,9 @@ var criteriaTypes = { "description" : "s", "artist_name" : "s", "encoded_by" : "s", - "utime" : "n", - "mtime" : "n", - "lptime" : "n", + "utime" : "d", + "mtime" : "d", + "lptime" : "d", "genre" : "s", "isrc_number" : "s", "label" : "s", @@ -647,3 +655,15 @@ var numericCriteriaOptions = { "is less than" : $.i18n._("is less than"), "is in the range" : $.i18n._("is in the range") }; + +var dateTimeCriteriaOptions = { + "0" : $.i18n._("Select modifier"), + "before" : $.i18n._("before"), + "after" : $.i18n._("after"), + "between" : $.i18n._("between"), + "is" : $.i18n._("is"), + "is not" : $.i18n._("is not"), + "is greater than" : $.i18n._("is greater than"), + "is less than" : $.i18n._("is less than"), + "is in the range" : $.i18n._("is in the range") +};