Added ability to text input relative date times w/o validation

This commit is contained in:
Robb Ebright 2017-08-16 20:05:02 -04:00
parent 0b80a429b3
commit c630a69b89
3 changed files with 81 additions and 22 deletions

View File

@ -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'])) {

View File

@ -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];

View File

@ -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($('<option></option>')
.attr('value', key)
.text(value));
});
}
else {
$.each(numericCriteriaOptions, function(key, value){
$(div).append($('<option></option>')
.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")
};