Merge pull request #704 from Robbt/fix-smartblock-multi-criteria

Fix smartblock multi criteria
This commit is contained in:
Robb 2019-02-09 11:22:29 -05:00 committed by GitHub
commit a4d0fcd8f3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
20 changed files with 857 additions and 220 deletions

1
.gitignore vendored
View File

@ -15,3 +15,4 @@ VERSION
airtime_mvc/tests/log/*.log
.vagrant/
.DS_Store
.idea/

View File

@ -0,0 +1 @@
ALTER TABLE cc_blockcriteria DROP COLUMN IF EXISTS criteriagroup;

View File

@ -0,0 +1 @@
ALTER TABLE cc_blockcriteria ADD COLUMN criteriagroup integer;

View File

@ -242,7 +242,8 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
$this->addElement($spType);
$bl = new Application_Model_Block($p_blockId);
$storedCrit = $bl->getCriteria();
$storedCrit = $bl->getCriteriaGrouped();
Logging::info($storedCrit);
//need to convert criteria to be displayed in the user's timezone if there's some timestamp type.
self::convertTimestamps($storedCrit["crit"]);
@ -263,181 +264,183 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
if (isset($storedCrit["crit"])) {
$criteriaKeys = array_keys($storedCrit["crit"]);
}
//the way the everything is currently built it setups 25 smartblock criteria forms and then disables them
//but this creates 29 elements
$numElements = count($this->getCriteriaOptions());
// loop through once for each potential criteria option ie album, composer, track
// criteria from different groups are separated already by the getCriteriaGrouped call
for ($i = 0; $i < $numElements; $i++) {
$criteriaType = "";
// if there is a criteria found then count the number of rows for this specific criteria ie > 1 track title
// need to refactor this to maintain separation based upon criteria grouping
if (isset($criteriaKeys[$i])) {
//Logging::info($criteriaKeys[$i]);
Logging::info($storedCrit["crit"][$criteriaKeys[$i]]);
$critCount = count($storedCrit["crit"][$criteriaKeys[$i]]);
} else {
$critCount = 1;
}
// the challenge is that we need to increment the element for a new group
// within the same criteria but not the reference point i in the array
// and for these secondary groups they will have a differe$storedCrit["crit"][$criteriaKeys[$i]]nt j reference point
// store the number of items with the same key in the ModRowMap
$modRowMap[$i] = $critCount;
// store the number of items with the same key in the ModRowMap
$modRowMap[$i] = $critCount;
/* Loop through all criteria with the same field
* Ex: all criteria for 'Album'
*/
for ($j = 0; $j < $critCount; $j++) {
/****************** CRITERIA ***********/
// hide the criteria drop down select on any rows after the first
if ($j > 0) {
$invisible = ' sp-invisible';
} else {
$invisible = '';
}
$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'))
->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])) {
$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])) {
$criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
$criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]);
}
$this->addElement($criteria);
/****************** MODIFIER ***********/
// every element has an optional modifier dropdown select
$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');
}
// determine the modifier based upon criteria type which is looked up based upon an array
if (isset($criteriaKeys[$i])) {
if ($criteriaType == "s") {
$criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
}
elseif ($criteriaType == "d") {
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
}
else {
$criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
}
$criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]);
} else {
$criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
}
$this->addElement($criteriaModifers);
/****************** VALUE ***********/
/* The challenge here is that datetime */
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_".$i."_".$j);
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
->setDecorators(array('viewHelper'));
if ($i != 0 && !isset($criteriaKeys[$i])) {
$criteriaValue->setAttrib('disabled', 'disabled');
}
if (isset($criteriaKeys[$i])) {
/*
* Need to parse relative dates in a special way to populate select box down below
*/
// this is used below to test whether the datetime select should be shown or hidden
$relativeDateTime = false;
$modifierTest = (string)$storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"];
if(isset($criteriaType) && $criteriaType == "d" &&
preg_match('/before|after|between/', $modifierTest) == 1) {
// set relativeDatetime boolean to true so that the datetime select is displayed below
$relativeDateTime = true;
// 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));
/* Loop through all criteria with the same field
* Ex: all criteria for 'Album'
*/
for ($j = 0; $j < $critCount; $j++) {
/****************** CRITERIA ***********/
// hide the criteria drop down select on any rows after the first
if ($j > 0) {
$invisible = ' sp-invisible';
} else {
$criteriaValue->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["value"]);
$invisible = '';
}
}
$this->addElement($criteriaValue);
/****************** 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'));
if (isset($criteriaKeys[$i]) && $relativeDateTime) {
$criteriaDatetimeSelect->setAttrib('enabled', 'enabled');
}
else {
$criteriaDatetimeSelect->setAttrib('disabled', 'disabled');
}
// 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) {
// need to remove any leading numbers stored in the database
$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());
}
$this->addElement($criteriaDatetimeSelect);
/****************** 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"])) {
// 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));
$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'))
->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])) {
$criteria->setAttrib('disabled', 'disabled');
}
else {
$criteriaExtra->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["extra"]);
// 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])) {
$criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]];
$criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]);
}
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
} else {
$criteriaExtra->setAttrib('disabled', 'disabled');
}
$this->addElement($criteriaExtra);
/****************** DATETIME SELECT EXTRA **********/
$this->addElement($criteria);
$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());
// Logging::info('THIS IS-'.$extraDateTimeSelectValue.'-IT');
$criteriaExtraDatetimeSelect->setValue($extraDateTimeSelectValue);
$criteriaExtraDatetimeSelect->setAttrib('enabled', 'enabled');
/****************** MODIFIER ***********/
// every element has an optional modifier dropdown select
} else {
$criteriaExtraDatetimeSelect->setMultiOptions(array('0' => _('Select unit of time')));
$criteriaExtraDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
$criteriaExtraDatetimeSelect->setAttrib('disabled', 'disabled');
}
$this->addElement($criteriaExtraDatetimeSelect);
}//for
$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');
}
// determine the modifier based upon criteria type which is looked up based upon an array
if (isset($criteriaKeys[$i])) {
if ($criteriaType == "s") {
$criteriaModifers->setMultiOptions($this->getStringCriteriaOptions());
} elseif ($criteriaType == "d") {
$criteriaModifers->setMultiOptions($this->getDateTimeCriteriaOptions());
} else {
$criteriaModifers->setMultiOptions($this->getNumericCriteriaOptions());
}
$criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]);
} else {
$criteriaModifers->setMultiOptions(array('0' => _('Select modifier')));
}
$this->addElement($criteriaModifers);
/****************** VALUE ***********/
/* The challenge here is that datetime */
$criteriaValue = new Zend_Form_Element_Text("sp_criteria_value_" . $i . "_" . $j);
$criteriaValue->setAttrib('class', 'input_text sp_input_text')
->setDecorators(array('viewHelper'));
if ($i != 0 && !isset($criteriaKeys[$i])) {
$criteriaValue->setAttrib('disabled', 'disabled');
}
if (isset($criteriaKeys[$i])) {
/*
* Need to parse relative dates in a special way to populate select box down below
*/
// this is used below to test whether the datetime select should be shown or hidden
$relativeDateTime = false;
$modifierTest = (string)$storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"];
if (isset($criteriaType) && $criteriaType == "d" &&
preg_match('/before|after|between/', $modifierTest) == 1) {
// set relativeDatetime boolean to true so that the datetime select is displayed below
$relativeDateTime = true;
// 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"]);
}
}
$this->addElement($criteriaValue);
/****************** 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'));
if (isset($criteriaKeys[$i]) && $relativeDateTime) {
$criteriaDatetimeSelect->setAttrib('enabled', 'enabled');
} else {
$criteriaDatetimeSelect->setAttrib('disabled', 'disabled');
}
// 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) {
// need to remove any leading numbers stored in the database
$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());
}
$this->addElement($criteriaDatetimeSelect);
/****************** 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"])) {
// 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"]);
}
$criteriaValue->setAttrib('class', 'input_text sp_extra_input_text');
} else {
$criteriaExtra->setAttrib('disabled', 'disabled');
}
$this->addElement($criteriaExtra);
/****************** 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());
// Logging::info('THIS IS-'.$extraDateTimeSelectValue.'-IT');
$criteriaExtraDatetimeSelect->setValue($extraDateTimeSelectValue);
$criteriaExtraDatetimeSelect->setAttrib('enabled', 'enabled');
} else {
$criteriaExtraDatetimeSelect->setMultiOptions(array('0' => _('Select unit of time')));
$criteriaExtraDatetimeSelect->setMultiOptions($this->getTimePeriodCriteriaOptions());
$criteriaExtraDatetimeSelect->setAttrib('disabled', 'disabled');
}
$this->addElement($criteriaExtraDatetimeSelect);
}//for
}//for
$repeatTracks = new Zend_Form_Element_Checkbox('sp_repeat_tracks');
@ -511,7 +514,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
$this->setDecorators(array(
array('ViewScript', array('viewScript' => 'form/smart-block-criteria.phtml', "openOption"=> $openSmartBlockOption,
'criteriasLength' => count($this->getCriteriaOptions()), 'modRowMap' => $modRowMap))
'criteriasLength' => $numElements, 'modRowMap' => $modRowMap))
));
}
/*
@ -524,7 +527,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
public function preValidation($params)
{
$data = Application_Model_Block::organizeSmartPlaylistCriteria($params['data']);
// add elelments that needs to be added
// add elements that needs to be added
// set multioption for modifier according to criteria_field
$modRowMap = array();
if (!isset($data['criteria'])) {

View File

@ -1198,8 +1198,11 @@ SQL;
if (isset($p_criteriaData['criteria'])) {
$critKeys = array_keys($p_criteriaData['criteria']);
for ($i = 0; $i < count($critKeys); $i++) {
// in order to maintain separation of different criteria to preserve AND statements for criteria
// that might contradict itself we group them based upon their original position on the form
$criteriaGroup = $i;
foreach ($p_criteriaData['criteria'][$critKeys[$i]] as $d) {
// Logging::info($d);
Logging::info($d);
$field = $d['sp_criteria_field'];
$value = $d['sp_criteria_value'];
$modifier = $d['sp_criteria_modifier'];
@ -1240,6 +1243,11 @@ SQL;
$qry->setDbExtra($extra);
}
// save the criteria group so separation via new modifiers AND can be preserved vs. lumping
// them all into a single or later on
if (isset($criteriaGroup)) {
$qry->setDbCriteriaGroup($criteriaGroup);
}
$qry->save();
}
}
@ -1483,6 +1491,7 @@ SQL;
$modifier = $crit->getDbModifier();
$value = $crit->getDbValue();
$extra = $crit->getDbExtra();
$criteriagroup = $crit->getDbCriteriaGroup();
if ($criteria == "limit") {
$storedCrit["limit"] = array(
@ -1501,6 +1510,7 @@ SQL;
"value"=>$value,
"modifier"=>$modifier,
"extra"=>$extra,
"criteria_group"=>$criteriagroup,
"display_name"=>$criteriaOptions[$criteria],
"display_modifier"=>$modifierOptions[$modifier]);
}
@ -1510,6 +1520,107 @@ SQL;
}
/**
* 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.
* Maintains original separation of similar criteria that were separated by and statements
*
*/
public function getCriteriaGrouped()
{
$criteriaOptions = array(
0 => _("Select criteria"),
"album_title" => _("Album"),
"bit_rate" => _("Bit Rate (Kbps)"),
"bpm" => _("BPM"),
"composer" => _("Composer"),
"conductor" => _("Conductor"),
"copyright" => _("Copyright"),
"cuein" => _("Cue In"),
"cueout" => _("Cue Out"),
"description" => _("Description"),
"artist_name" => _("Creator"),
"encoded_by" => _("Encoded By"),
"genre" => _("Genre"),
"isrc_number" => _("ISRC"),
"label" => _("Label"),
"language" => _("Language"),
"utime" => _("Upload Time"),
"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")
);
$modifierOptions = 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"),
"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")
);
// Load criteria from db
$out = CcBlockcriteriaQuery::create()->orderByDbCriteria()->findByDbBlockId($this->id);
$storedCrit = array();
foreach ($out as $crit) {
Logging::info($crit);
$criteria = $crit->getDbCriteria();
$modifier = $crit->getDbModifier();
$value = $crit->getDbValue();
$extra = $crit->getDbExtra();
$criteriagroup = $crit->getDbCriteriaGroup();
if ($criteria == "limit") {
$storedCrit["limit"] = array(
"value"=>$value,
"modifier"=>$modifier,
"display_modifier"=>_($modifier));
} else if($criteria == "repeat_tracks") {
$storedCrit["repeat_tracks"] = array("value"=>$value);
} else if($criteria == "overflow_tracks") {
$storedCrit["overflow_tracks"] = array("value"=>$value);
} else if($criteria == "sort") {
$storedCrit["sort"] = array("value"=>$value);
} else {
$storedCrit["crit"][$criteria . $criteriagroup][] = array(
"criteria"=>$criteria,
"value"=>$value,
"modifier"=>$modifier,
"extra"=>$extra,
"display_name"=>$criteriaOptions[$criteria],
"display_modifier"=>$modifierOptions[$modifier]);
}
}
Logging::info($storedCrit);
return $storedCrit;
}
// this function return list of propel object
public function getListofFilesMeetCriteria($show = null)
{
@ -1518,10 +1629,19 @@ SQL;
$qry = CcFilesQuery::create();
$qry->useFkOwnerQuery("subj", "left join");
//Logging::info($storedCrit);
if (isset($storedCrit["crit"])) {
foreach ($storedCrit["crit"] as $crit) {
$i = 0;
$prevgroup = null;
$group = null;
// now we need to sort based upon extra which contains the and grouping from the form
usort($crit, function($a, $b) {
return $a['criteria_group'] - $b['criteria_group'];
});
// we need to run the following loop separately for each criteria group inside of each array
foreach ($crit as $criteria) {
$group = $criteria['criteria_group'];
$spCriteria = $criteria['criteria'];
$spCriteriaModifier = $criteria['modifier'];
@ -1538,9 +1658,9 @@ SQL;
} elseif ($spCriteria == "bit_rate" || $spCriteria == 'sample_rate') {
// multiply 1000 because we store only number value
// e.g 192kps is stored as 192000
$spCriteriaValue = $criteria['value']*1000;
$spCriteriaValue = $criteria['value'] * 1000;
if (isset($criteria['extra'])) {
$spCriteriaExtra = $criteria['extra']*1000;
$spCriteriaExtra = $criteria['extra'] * 1000;
}
/*
* If user is searching for an exact match of length we need to
@ -1564,7 +1684,6 @@ SQL;
} else {
$spCriteriaValue = ($criteria['value']);
}
$spCriteriaExtra = $criteria['extra'];
}
@ -1599,25 +1718,38 @@ SQL;
// Logging::info($tdt);
$spCriteriaValue = "$spCriteria >= '$fdt' AND $spCriteria <= '$tdt'";
}
// logging::info('before');
// logging::info($spCriteriaModifier);
$spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier];
// logging::info('after');
// logging::info($spCriteriaModifier);
try {
if ($spCriteria == "owner_id") {
$spCriteria = "subj.login";
}
if ($i > 0) {
Logging::info($i);
Logging::info($group);
Logging::info($prevgroup);
if ($i > 0 && $prevgroup == $group) {
Logging::info('adding or');
$qry->addOr($spCriteria, $spCriteriaValue, $spCriteriaModifier);
} else {
$qry->add($spCriteria, $spCriteriaValue, $spCriteriaModifier);
Logging::info('adding and');
$qry->addAnd($spCriteria, $spCriteriaValue, $spCriteriaModifier);
}
// only add this NOT LIKE null if you aren't also matching on another criteria
if ($i == 0) {
if ($spCriteriaModifier == Criteria::NOT_ILIKE || $spCriteriaModifier == Criteria::NOT_EQUAL) {
$qry->addOr($spCriteria, null, Criteria::ISNULL);
}
}
} catch (Exception $e) {
Logging::info($e);
}
$prevgroup = $group;
$i++;
}
}
@ -1682,6 +1814,7 @@ SQL;
try {
$out = $qry->setFormatter(ModelCriteria::FORMAT_ON_DEMAND)->find();
Logging::info($qry->toString());
return array("files"=>$out, "limit"=>$limits, "repeat_tracks"=> $repeatTracks, "overflow_tracks"=> $overflowTracks, "count"=>$out->count());
} catch (Exception $e) {
@ -1690,7 +1823,8 @@ SQL;
}
public static function organizeSmartPlaylistCriteria($p_criteria)
{
{
Logging::info($p_criteria);
$fieldNames = array('sp_criteria_field', 'sp_criteria_modifier', 'sp_criteria_value', 'sp_criteria_extra', 'sp_criteria_datetime_select', 'sp_criteria_extra_datetime_select');
$output = array();
foreach ($p_criteria as $ele) {
@ -1729,7 +1863,7 @@ SQL;
$output['etc'][$ele['name']] = $ele['value'];
}
}
Logging::info($output);
return $output;
}
public static function getAllBlockFiles()

View File

@ -44,6 +44,7 @@ class CcBlockcriteriaTableMap extends TableMap
$this->addColumn('modifier', 'DbModifier', 'VARCHAR', true, 16, null);
$this->addColumn('value', 'DbValue', 'VARCHAR', true, 512, null);
$this->addColumn('extra', 'DbExtra', 'VARCHAR', false, 512, null);
$this->addColumn('criteriagroup', 'DbCriteriaGroup', 'INTEGER', false, null, null);
$this->addForeignKey('block_id', 'DbBlockId', 'INTEGER', 'cc_block', 'id', true, null, null);
// validators
} // initialize()

View File

@ -75,7 +75,7 @@ abstract class BaseCcBlock extends BaseObject implements Persistent
/**
* The value for the type field.
* Note: this column has a database default value of: 'dynamic'
* Note: this column has a database default value of: 'static'
* @var string
*/
protected $type;
@ -151,7 +151,7 @@ abstract class BaseCcBlock extends BaseObject implements Persistent
{
$this->name = '';
$this->length = '00:00:00';
$this->type = 'dynamic';
$this->type = 'static';
}
/**
@ -494,7 +494,7 @@ abstract class BaseCcBlock extends BaseObject implements Persistent
return false;
}
if ($this->type !== 'dynamic') {
if ($this->type !== 'static') {
return false;
}

View File

@ -59,6 +59,12 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
*/
protected $extra;
/**
* The value for the criteriagroup field.
* @var int
*/
protected $criteriagroup;
/**
* The value for the block_id field.
* @var int
@ -145,6 +151,17 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
return $this->extra;
}
/**
* Get the [criteriagroup] column value.
*
* @return int
*/
public function getDbCriteriaGroup()
{
return $this->criteriagroup;
}
/**
* Get the [block_id] column value.
*
@ -261,6 +278,27 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
return $this;
} // setDbExtra()
/**
* Set the value of [criteriagroup] column.
*
* @param int $v new value
* @return CcBlockcriteria The current object (for fluent API support)
*/
public function setDbCriteriaGroup($v)
{
if ($v !== null && is_numeric($v)) {
$v = (int) $v;
}
if ($this->criteriagroup !== $v) {
$this->criteriagroup = $v;
$this->modifiedColumns[] = CcBlockcriteriaPeer::CRITERIAGROUP;
}
return $this;
} // setDbCriteriaGroup()
/**
* Set the value of [block_id] column.
*
@ -323,7 +361,8 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
$this->modifier = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null;
$this->value = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null;
$this->extra = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null;
$this->block_id = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null;
$this->criteriagroup = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null;
$this->block_id = ($row[$startcol + 6] !== null) ? (int) $row[$startcol + 6] : null;
$this->resetModified();
$this->setNew(false);
@ -333,7 +372,7 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
}
$this->postHydrate($row, $startcol, $rehydrate);
return $startcol + 6; // 6 = CcBlockcriteriaPeer::NUM_HYDRATE_COLUMNS.
return $startcol + 7; // 7 = CcBlockcriteriaPeer::NUM_HYDRATE_COLUMNS.
} catch (Exception $e) {
throw new PropelException("Error populating CcBlockcriteria object", $e);
@ -586,6 +625,9 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
if ($this->isColumnModified(CcBlockcriteriaPeer::EXTRA)) {
$modifiedColumns[':p' . $index++] = '"extra"';
}
if ($this->isColumnModified(CcBlockcriteriaPeer::CRITERIAGROUP)) {
$modifiedColumns[':p' . $index++] = '"criteriagroup"';
}
if ($this->isColumnModified(CcBlockcriteriaPeer::BLOCK_ID)) {
$modifiedColumns[':p' . $index++] = '"block_id"';
}
@ -615,6 +657,9 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
case '"extra"':
$stmt->bindValue($identifier, $this->extra, PDO::PARAM_STR);
break;
case '"criteriagroup"':
$stmt->bindValue($identifier, $this->criteriagroup, PDO::PARAM_INT);
break;
case '"block_id"':
$stmt->bindValue($identifier, $this->block_id, PDO::PARAM_INT);
break;
@ -773,6 +818,9 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
return $this->getDbExtra();
break;
case 5:
return $this->getDbCriteriaGroup();
break;
case 6:
return $this->getDbBlockId();
break;
default:
@ -809,7 +857,8 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
$keys[2] => $this->getDbModifier(),
$keys[3] => $this->getDbValue(),
$keys[4] => $this->getDbExtra(),
$keys[5] => $this->getDbBlockId(),
$keys[5] => $this->getDbCriteriaGroup(),
$keys[6] => $this->getDbBlockId(),
);
$virtualColumns = $this->virtualColumns;
foreach ($virtualColumns as $key => $virtualColumn) {
@ -870,6 +919,9 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
$this->setDbExtra($value);
break;
case 5:
$this->setDbCriteriaGroup($value);
break;
case 6:
$this->setDbBlockId($value);
break;
} // switch()
@ -901,7 +953,8 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
if (array_key_exists($keys[2], $arr)) $this->setDbModifier($arr[$keys[2]]);
if (array_key_exists($keys[3], $arr)) $this->setDbValue($arr[$keys[3]]);
if (array_key_exists($keys[4], $arr)) $this->setDbExtra($arr[$keys[4]]);
if (array_key_exists($keys[5], $arr)) $this->setDbBlockId($arr[$keys[5]]);
if (array_key_exists($keys[5], $arr)) $this->setDbCriteriaGroup($arr[$keys[5]]);
if (array_key_exists($keys[6], $arr)) $this->setDbBlockId($arr[$keys[6]]);
}
/**
@ -918,6 +971,7 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
if ($this->isColumnModified(CcBlockcriteriaPeer::MODIFIER)) $criteria->add(CcBlockcriteriaPeer::MODIFIER, $this->modifier);
if ($this->isColumnModified(CcBlockcriteriaPeer::VALUE)) $criteria->add(CcBlockcriteriaPeer::VALUE, $this->value);
if ($this->isColumnModified(CcBlockcriteriaPeer::EXTRA)) $criteria->add(CcBlockcriteriaPeer::EXTRA, $this->extra);
if ($this->isColumnModified(CcBlockcriteriaPeer::CRITERIAGROUP)) $criteria->add(CcBlockcriteriaPeer::CRITERIAGROUP, $this->criteriagroup);
if ($this->isColumnModified(CcBlockcriteriaPeer::BLOCK_ID)) $criteria->add(CcBlockcriteriaPeer::BLOCK_ID, $this->block_id);
return $criteria;
@ -986,6 +1040,7 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
$copyObj->setDbModifier($this->getDbModifier());
$copyObj->setDbValue($this->getDbValue());
$copyObj->setDbExtra($this->getDbExtra());
$copyObj->setDbCriteriaGroup($this->getDbCriteriaGroup());
$copyObj->setDbBlockId($this->getDbBlockId());
if ($deepCopy && !$this->startCopy) {
@ -1107,6 +1162,7 @@ abstract class BaseCcBlockcriteria extends BaseObject implements Persistent
$this->modifier = null;
$this->value = null;
$this->extra = null;
$this->criteriagroup = null;
$this->block_id = null;
$this->alreadyInSave = false;
$this->alreadyInValidation = false;

View File

@ -24,13 +24,13 @@ abstract class BaseCcBlockcriteriaPeer
const TM_CLASS = 'CcBlockcriteriaTableMap';
/** The total number of columns. */
const NUM_COLUMNS = 6;
const NUM_COLUMNS = 7;
/** The number of lazy-loaded columns. */
const NUM_LAZY_LOAD_COLUMNS = 0;
/** The number of columns to hydrate (NUM_COLUMNS - NUM_LAZY_LOAD_COLUMNS) */
const NUM_HYDRATE_COLUMNS = 6;
const NUM_HYDRATE_COLUMNS = 7;
/** the column name for the id field */
const ID = 'cc_blockcriteria.id';
@ -47,6 +47,9 @@ abstract class BaseCcBlockcriteriaPeer
/** the column name for the extra field */
const EXTRA = 'cc_blockcriteria.extra';
/** the column name for the criteriagroup field */
const CRITERIAGROUP = 'cc_blockcriteria.criteriagroup';
/** the column name for the block_id field */
const BLOCK_ID = 'cc_blockcriteria.block_id';
@ -69,12 +72,12 @@ abstract class BaseCcBlockcriteriaPeer
* e.g. CcBlockcriteriaPeer::$fieldNames[CcBlockcriteriaPeer::TYPE_PHPNAME][0] = 'Id'
*/
protected static $fieldNames = array (
BasePeer::TYPE_PHPNAME => array ('DbId', 'DbCriteria', 'DbModifier', 'DbValue', 'DbExtra', 'DbBlockId', ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbCriteria', 'dbModifier', 'dbValue', 'dbExtra', 'dbBlockId', ),
BasePeer::TYPE_COLNAME => array (CcBlockcriteriaPeer::ID, CcBlockcriteriaPeer::CRITERIA, CcBlockcriteriaPeer::MODIFIER, CcBlockcriteriaPeer::VALUE, CcBlockcriteriaPeer::EXTRA, CcBlockcriteriaPeer::BLOCK_ID, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID', 'CRITERIA', 'MODIFIER', 'VALUE', 'EXTRA', 'BLOCK_ID', ),
BasePeer::TYPE_FIELDNAME => array ('id', 'criteria', 'modifier', 'value', 'extra', 'block_id', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, )
BasePeer::TYPE_PHPNAME => array ('DbId', 'DbCriteria', 'DbModifier', 'DbValue', 'DbExtra', 'DbCriteriaGroup', 'DbBlockId', ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbCriteria', 'dbModifier', 'dbValue', 'dbExtra', 'dbCriteriaGroup', 'dbBlockId', ),
BasePeer::TYPE_COLNAME => array (CcBlockcriteriaPeer::ID, CcBlockcriteriaPeer::CRITERIA, CcBlockcriteriaPeer::MODIFIER, CcBlockcriteriaPeer::VALUE, CcBlockcriteriaPeer::EXTRA, CcBlockcriteriaPeer::CRITERIAGROUP, CcBlockcriteriaPeer::BLOCK_ID, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID', 'CRITERIA', 'MODIFIER', 'VALUE', 'EXTRA', 'CRITERIAGROUP', 'BLOCK_ID', ),
BasePeer::TYPE_FIELDNAME => array ('id', 'criteria', 'modifier', 'value', 'extra', 'criteriagroup', 'block_id', ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, )
);
/**
@ -84,12 +87,12 @@ abstract class BaseCcBlockcriteriaPeer
* e.g. CcBlockcriteriaPeer::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0
*/
protected static $fieldKeys = array (
BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbCriteria' => 1, 'DbModifier' => 2, 'DbValue' => 3, 'DbExtra' => 4, 'DbBlockId' => 5, ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbCriteria' => 1, 'dbModifier' => 2, 'dbValue' => 3, 'dbExtra' => 4, 'dbBlockId' => 5, ),
BasePeer::TYPE_COLNAME => array (CcBlockcriteriaPeer::ID => 0, CcBlockcriteriaPeer::CRITERIA => 1, CcBlockcriteriaPeer::MODIFIER => 2, CcBlockcriteriaPeer::VALUE => 3, CcBlockcriteriaPeer::EXTRA => 4, CcBlockcriteriaPeer::BLOCK_ID => 5, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'CRITERIA' => 1, 'MODIFIER' => 2, 'VALUE' => 3, 'EXTRA' => 4, 'BLOCK_ID' => 5, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'criteria' => 1, 'modifier' => 2, 'value' => 3, 'extra' => 4, 'block_id' => 5, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, )
BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbCriteria' => 1, 'DbModifier' => 2, 'DbValue' => 3, 'DbExtra' => 4, 'DbCriteriaGroup' => 5, 'DbBlockId' => 6, ),
BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbCriteria' => 1, 'dbModifier' => 2, 'dbValue' => 3, 'dbExtra' => 4, 'dbCriteriaGroup' => 5, 'dbBlockId' => 6, ),
BasePeer::TYPE_COLNAME => array (CcBlockcriteriaPeer::ID => 0, CcBlockcriteriaPeer::CRITERIA => 1, CcBlockcriteriaPeer::MODIFIER => 2, CcBlockcriteriaPeer::VALUE => 3, CcBlockcriteriaPeer::EXTRA => 4, CcBlockcriteriaPeer::CRITERIAGROUP => 5, CcBlockcriteriaPeer::BLOCK_ID => 6, ),
BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'CRITERIA' => 1, 'MODIFIER' => 2, 'VALUE' => 3, 'EXTRA' => 4, 'CRITERIAGROUP' => 5, 'BLOCK_ID' => 6, ),
BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'criteria' => 1, 'modifier' => 2, 'value' => 3, 'extra' => 4, 'criteriagroup' => 5, 'block_id' => 6, ),
BasePeer::TYPE_NUM => array (0, 1, 2, 3, 4, 5, 6, )
);
/**
@ -168,6 +171,7 @@ abstract class BaseCcBlockcriteriaPeer
$criteria->addSelectColumn(CcBlockcriteriaPeer::MODIFIER);
$criteria->addSelectColumn(CcBlockcriteriaPeer::VALUE);
$criteria->addSelectColumn(CcBlockcriteriaPeer::EXTRA);
$criteria->addSelectColumn(CcBlockcriteriaPeer::CRITERIAGROUP);
$criteria->addSelectColumn(CcBlockcriteriaPeer::BLOCK_ID);
} else {
$criteria->addSelectColumn($alias . '.id');
@ -175,6 +179,7 @@ abstract class BaseCcBlockcriteriaPeer
$criteria->addSelectColumn($alias . '.modifier');
$criteria->addSelectColumn($alias . '.value');
$criteria->addSelectColumn($alias . '.extra');
$criteria->addSelectColumn($alias . '.criteriagroup');
$criteria->addSelectColumn($alias . '.block_id');
}
}

View File

@ -11,6 +11,7 @@
* @method CcBlockcriteriaQuery orderByDbModifier($order = Criteria::ASC) Order by the modifier column
* @method CcBlockcriteriaQuery orderByDbValue($order = Criteria::ASC) Order by the value column
* @method CcBlockcriteriaQuery orderByDbExtra($order = Criteria::ASC) Order by the extra column
* @method CcBlockcriteriaQuery orderByDbCriteriaGroup($order = Criteria::ASC) Order by the criteriagroup column
* @method CcBlockcriteriaQuery orderByDbBlockId($order = Criteria::ASC) Order by the block_id column
*
* @method CcBlockcriteriaQuery groupByDbId() Group by the id column
@ -18,6 +19,7 @@
* @method CcBlockcriteriaQuery groupByDbModifier() Group by the modifier column
* @method CcBlockcriteriaQuery groupByDbValue() Group by the value column
* @method CcBlockcriteriaQuery groupByDbExtra() Group by the extra column
* @method CcBlockcriteriaQuery groupByDbCriteriaGroup() Group by the criteriagroup column
* @method CcBlockcriteriaQuery groupByDbBlockId() Group by the block_id column
*
* @method CcBlockcriteriaQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
@ -35,6 +37,7 @@
* @method CcBlockcriteria findOneByDbModifier(string $modifier) Return the first CcBlockcriteria filtered by the modifier column
* @method CcBlockcriteria findOneByDbValue(string $value) Return the first CcBlockcriteria filtered by the value column
* @method CcBlockcriteria findOneByDbExtra(string $extra) Return the first CcBlockcriteria filtered by the extra column
* @method CcBlockcriteria findOneByDbCriteriaGroup(int $criteriagroup) Return the first CcBlockcriteria filtered by the criteriagroup column
* @method CcBlockcriteria findOneByDbBlockId(int $block_id) Return the first CcBlockcriteria filtered by the block_id column
*
* @method array findByDbId(int $id) Return CcBlockcriteria objects filtered by the id column
@ -42,6 +45,7 @@
* @method array findByDbModifier(string $modifier) Return CcBlockcriteria objects filtered by the modifier column
* @method array findByDbValue(string $value) Return CcBlockcriteria objects filtered by the value column
* @method array findByDbExtra(string $extra) Return CcBlockcriteria objects filtered by the extra column
* @method array findByDbCriteriaGroup(int $criteriagroup) Return CcBlockcriteria objects filtered by the criteriagroup column
* @method array findByDbBlockId(int $block_id) Return CcBlockcriteria objects filtered by the block_id column
*
* @package propel.generator.airtime.om
@ -150,7 +154,7 @@ abstract class BaseCcBlockcriteriaQuery extends ModelCriteria
*/
protected function findPkSimple($key, $con)
{
$sql = 'SELECT "id", "criteria", "modifier", "value", "extra", "block_id" FROM "cc_blockcriteria" WHERE "id" = :p0';
$sql = 'SELECT "id", "criteria", "modifier", "value", "extra", "criteriagroup", "block_id" FROM "cc_blockcriteria" WHERE "id" = :p0';
try {
$stmt = $con->prepare($sql);
$stmt->bindValue(':p0', $key, PDO::PARAM_INT);
@ -397,6 +401,48 @@ abstract class BaseCcBlockcriteriaQuery extends ModelCriteria
return $this->addUsingAlias(CcBlockcriteriaPeer::EXTRA, $dbExtra, $comparison);
}
/**
* Filter the query on the criteriagroup column
*
* Example usage:
* <code>
* $query->filterByDbCriteriaGroup(1234); // WHERE criteriagroup = 1234
* $query->filterByDbCriteriaGroup(array(12, 34)); // WHERE criteriagroup IN (12, 34)
* $query->filterByDbCriteriaGroup(array('min' => 12)); // WHERE criteriagroup >= 12
* $query->filterByDbCriteriaGroup(array('max' => 12)); // WHERE criteriagroup <= 12
* </code>
*
* @param mixed $dbCriteriaGroup The value to use as filter.
* Use scalar values for equality.
* Use array values for in_array() equivalent.
* Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
* @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
*
* @return CcBlockcriteriaQuery The current query, for fluid interface
*/
public function filterByDbCriteriaGroup($dbCriteriaGroup = null, $comparison = null)
{
if (is_array($dbCriteriaGroup)) {
$useMinMax = false;
if (isset($dbCriteriaGroup['min'])) {
$this->addUsingAlias(CcBlockcriteriaPeer::CRITERIAGROUP, $dbCriteriaGroup['min'], Criteria::GREATER_EQUAL);
$useMinMax = true;
}
if (isset($dbCriteriaGroup['max'])) {
$this->addUsingAlias(CcBlockcriteriaPeer::CRITERIAGROUP, $dbCriteriaGroup['max'], Criteria::LESS_EQUAL);
$useMinMax = true;
}
if ($useMinMax) {
return $this;
}
if (null === $comparison) {
$comparison = Criteria::IN;
}
}
return $this->addUsingAlias(CcBlockcriteriaPeer::CRITERIAGROUP, $dbCriteriaGroup, $comparison);
}
/**
* Filter the query on the block_id column
*

View File

@ -26,34 +26,34 @@
$nextDisabled = $this->element->getElement("sp_criteria_field_".$nextIndex)->getAttrib('disabled') == 'disabled'?true:false;
?>
<div <?php if (/*($i > 0) && */ $disabled) {
echo 'style=display:none';
} ?> >
echo 'style="display:none"';
}?> class="search-row-<?php echo $logicLabel ?>">
<?php echo $this->element->getElement("sp_criteria_field_".$i."_".$j) ?>
<?php echo $this->element->getElement("sp_criteria_modifier_".$i."_".$j) /* @todo finish this */?>
<?php echo $this->element->getElement("sp_criteria_value_".$i."_".$j) ?>
<span class='sp_text_font' id="datetime_select" <?php echo $this->element->getElement("sp_criteria_datetime_select_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>><?php echo $this->element->getElement('sp_criteria_datetime_select_'.$i."_".$j) ?><?php echo _(" ago "); ?></span>
<a class='btn btn-small btn-new' id='modifier_add_<?php echo $i ?>'>
<i class='icon-white icon-plus'></i><?php echo(_("New Modifier")); ?>
<a <?php if ($disabled) { echo 'style=display:none'; } ?> class='modifier_add_link' id='modifier_add_<?php echo $i ?>'>
+ <?php echo(_("New Modifier")); ?>
</a>
<span class='sp_text_font' id="extra_criteria" <?php echo $this->element->getElement("sp_criteria_extra_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>><?php echo _(" to "); ?><?php echo $this->element->getElement('sp_criteria_extra_'.$i."_".$j) ?></span>
<span class='sp_text_font' id="extra_datetime_select" <?php echo $this->element->getElement("sp_criteria_extra_datetime_select_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>><?php echo $this->element->getElement('sp_criteria_extra_datetime_select_'.$i."_".$j) ?><?php echo _(" ago "); ?></span>
<a style='margin-right:3px' class='btn btn-small btn-danger' id='criteria_remove_<?php echo $i ?>'>
<i class='icon-white icon-remove spl-no-r-margin'></i>
</a>
<span class='db-logic-label' <?php if ($nextDisabled) echo "style='display:none'"?>>
<span class='db-logic-label' <?php if ($nextDisabled) echo 'style="display:none"';?>>
<?php echo $logicLabel;?>
</span>
<?php if($this->element->getElement("sp_criteria_field_".$i."_".$j)->hasErrors()) : ?>
<?php foreach($this->element->getElement("sp_criteria_field_".$i."_".$j)->getMessages() as $error): ?>
<span class='errors sp-errors'>
<?php echo $error; ?>
</span>
<?php endforeach; ?>
<?php foreach($this->element->getElement("sp_criteria_field_".$i."_".$j)->getMessages() as $error): ?>
<span class='errors sp-errors'>
<?php echo $error; ?>
</span>
<?php endforeach; ?>
<?php endif; ?>
</div>
<?php } ?>

View File

@ -315,6 +315,7 @@
<column name="modifier" phpName="DbModifier" type="VARCHAR" size="16" required="true"/>
<column name="value" phpName="DbValue" type="VARCHAR" size="512" required="true"/>
<column name="extra" phpName="DbExtra" type="VARCHAR" size="512" required="false"/>
<column name="criteriagroup" phpName="DbCriteriaGroup" type="INTEGER" required="false"/>
<column name="block_id" phpName="DbBlockId" type="INTEGER" required="true"/>
<foreign-key foreignTable="cc_block" name="cc_blockcontents_block_id_fkey" onDelete="CASCADE">
<reference local="block_id" foreign="id"/>

View File

@ -299,7 +299,7 @@ CREATE TABLE "cc_block"
"creator_id" INTEGER,
"description" VARCHAR(512),
"length" interval DEFAULT '00:00:00',
"type" VARCHAR(7) DEFAULT 'dynamic',
"type" VARCHAR(7) DEFAULT 'static',
PRIMARY KEY ("id")
);
@ -337,6 +337,7 @@ CREATE TABLE "cc_blockcriteria"
"modifier" VARCHAR(16) NOT NULL,
"value" VARCHAR(512) NOT NULL,
"extra" VARCHAR(512),
"criteriagroup" INTEGER,
"block_id" INTEGER NOT NULL,
PRIMARY KEY ("id")
);

View File

@ -216,7 +216,11 @@ tr.lib-selected > td > div.library_actions_btn:hover {
.search-criteria .criteria-element > div {
margin-bottom: 5px;
display: flex;
flex-wrap: wrap;
position: relative;
}
.search-criteria .criteria-element > div.search-row-and { margin-bottom: 42px; }
.search-criteria .criteria-element > div input[type="text"],
.search-criteria .criteria-element > div select {
-webkit-box-sizing: border-box;

View File

@ -533,6 +533,7 @@
#sp_criteria-element {
clear: both;
width: 100%;
}
/*
@ -633,7 +634,7 @@ li.spl_empty {
}
#criteria_add {
margin-bottom: 5px;
margin: -10px 0 5px;
}
.smart-block-form dt, .smart-block-form dd {

View File

@ -703,15 +703,42 @@ table.library-get-file-md.table-small{
/***** SMART BLOCK SPECIFIC STYLES BEGIN *****/
.db-logic-label{
font-size:11px;
.modifier_add_link {
font-size: 12px;
display: block;
margin: 0 0 10px 29%;
text-decoration: underline;
cursor: pointer;
position: absolute;
top: calc(100% + 5px);
}
.db-logic-label {
font-size:12px;
position: absolute;
top: calc(100% + 5px);
margin: 7px;
}
.search-row-and .db-logic-label {
display: table;
white-space: nowrap;
width: 100%;
text-align: center;
margin: 1.5em 0 0;
}
.search-row-and .db-logic-label:before, .search-row-and .db-logic-label:after {
border-top: 1px solid hsl(0, 0%, 29%);
content: '';
display: table-cell;
position: relative;
top: 0.5em;
width: 45%;
}
.sp-invisible{
visibility: hidden;
}
.sp_input_select{
width: 140px;
.sp_input_select, .sp_input_text {
flex: 0 0 29%;
}
.sp_input_text_limit{
@ -723,18 +750,13 @@ table.library-get-file-md.table-small{
margin-right: 0px !important;
}
input.input_text.sp_input_text{
width: 139px !important;
}
input.input_text.sp_extra_input_text{
width: 139px !important;
}
.sp_text_font{
font-size: 13px;
font-size: 12px;
font-family: Helvetica, Arial, sans-serif;
color: #FFFFFF;
line-height: 26px;
display: inline-block;
margin-right: 4px;
}
.sp_text_font_bold{

View File

@ -24,10 +24,14 @@ function setSmartBlockEvents() {
} else {
div.find('.db-logic-label').text('and').show();
div.find('.db-logic-label').text('and').css('display', 'table');
div.removeClass('search-row-or').addClass('search-row-and');
div = div.next().show();
div.children().removeAttr('disabled');
div.find(".modifier_add_link").show();
div = div.next();
if (div.length === 0) {
$(this).hide();
@ -36,7 +40,8 @@ function setSmartBlockEvents() {
appendAddButton();
appendModAddButton();
removeButtonCheck();
disableAndHideDateTimeDropdown(newRowVal);
// disableAndHideDateTimeDropdown(newRowVal);
groupCriteriaRows();
}
});
@ -44,7 +49,7 @@ function setSmartBlockEvents() {
/********** ADD MODIFIER ROW **********/
form.find('a[id^="modifier_add"]').live('click', function(){
var criteria_value = $(this).siblings('select[name^="sp_criteria_field"]').val();
//make new modifier row
var newRow = $(this).parent().clone(),
@ -76,12 +81,17 @@ function setSmartBlockEvents() {
//remove the 'criteria add' button from new modifier row
newRow.find('#criteria_add').remove();
$(this).parent().after(newRow);
// remove extra spacing from previous row
newRow.prev().removeClass('search-row-and').addClass('search-row-or');
reindexElements();
appendAddButton();
appendModAddButton();
removeButtonCheck();
groupCriteriaRows();
});
/********** REMOVE ROW **********/
@ -269,6 +279,9 @@ function setSmartBlockEvents() {
// remove the 'x' button if only one row is enabled
removeButtonCheck();
groupCriteriaRows();
});
/********** SAVE ACTION **********/
@ -305,7 +318,7 @@ function setSmartBlockEvents() {
/********** CRITERIA CHANGE **********/
form.find('select[id^="sp_criteria"]:not([id^="sp_criteria_modifier"])').live("change", function(){
form.find('select[id^="sp_criteria"]:not([id^="sp_criteria_modifier"]):not([id^="sp_criteria_datetime"]):not([id^="sp_criteria_extra_datetime"])').live("change", function(){
var index = getRowIndex($(this).parent());
//need to change the criteria value for any modifier rows
var critVal = $(this).val();
@ -805,6 +818,30 @@ function enableLoadingIcon() {
function disableLoadingIcon() {
$(".side_playlist.active-tab").unblock()
}
function groupCriteriaRows() {
// check whether rows should be "grouped" and shown with an "or" "logic label", or separated by an "and" "logic label"
var visibleRows = $("#sp_criteria-element > div:visible"),
prevRowGroup = "0";
visibleRows.each(function (index){
if (index > 0) {
var fieldId = $(this).find('select[id^="sp_criteria_field"]').attr("id");
var currRowGroup = fieldId[fieldId.length - 3];
if (currRowGroup === prevRowGroup) {
$(this).prev().addClass("search-row-or").removeClass("search-row-and")
} else {
$(this).prev().addClass("search-row-and").removeClass("search-row-or")
}
prevRowGroup = currRowGroup;
}
});
// ensure spacing below last visible row
$("#sp_criteria-element > div:visible:last").addClass("search-row-and").removeClass("search-row-or");
}
// We need to know if the criteria value will be a string
// or numeric value in order to populate the modifier
// select list

View File

@ -0,0 +1,95 @@
<?php
//require_once "../application/configs/conf.php";
class BlockDbTest extends Zend_Test_PHPUnit_DatabaseTestCase //PHPUnit_Framework_TestCase
{
private $_connectionMock;
public function setUp()
{
TestHelper::installTestDatabase();
TestHelper::setupZendBootstrap();
parent::setUp();
}
public function getConnection()
{
if ($this->_connectionMock == null) {
$config = TestHelper::getDbZendConfig();
$connection = Zend_Db::factory('pdo_pgsql', $config);
$this->_connectionMock = $this->createZendDbConnection(
$connection,
'airtimeunittests'
);
Zend_Db_Table_Abstract::setDefaultAdapter($connection);
}
return $this->_connectionMock;
}
/**
* Load a dataset into the database for the block database tests
*
* Defines how the initial state of the database should look before each test is executed
* Called once during setUp() and gets recreated for each new test
*/
public function getDataSet()
{
$dataset = new PHPUnit_Extensions_Database_DataSet_YamlDataSet(__DIR__ . '/datasets/seed_files.yml' );
return $dataset;
}
/**
* Test if the single newest file is added to the Database
*
*/
public function testGetListofFilesMeetCriteriaSingleMatch() {
TestHelper::loginUser();
$CC_CONFIG = Config::getConfig();
$testqry = CcFilesQuery::create();
$testout = $testqry->find();
$vd = $testout->getData();
$ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
$this->getConnection()
);
$testCriteria = BlockModelData::getCriteriaSingleNewestLabelNada();
$bltest = new Application_Model_Block();
$bltest->saveSmartBlockCriteria($testCriteria);
$tracks = $bltest->getListOfFilesUnderLimit();
//$tracks = $bltest->getLength();
$this->assertNotEmpty($tracks);
// need to load a example criteria into the database
}
/**
* Test if the single newest file is added to the Database
*
*/
public function testMultiTrackandAlbumsGetLoaded() {
TestHelper::loginUser();
$CC_CONFIG = Config::getConfig();
$testqry = CcFilesQuery::create();
$testout = $testqry->find();
$vd = $testout->getData();
$ds = new Zend_Test_PHPUnit_Db_DataSet_QueryDataSet(
$this->getConnection()
);
$testCriteria = BlockModelData::getCriteriaMultiTrackAndAlbum1Hour();
$bltest = new Application_Model_Block();
$bltest->saveSmartBlockCriteria($testCriteria);
$tracks = $bltest->getListOfFilesUnderLimit();
//$tracks = $bltest->getLength();
$this->assertNotEmpty($tracks);
// add assertion that the length is less than 1 hour...
// need to load a example criteria into the database
}
}

View File

@ -0,0 +1,177 @@
cc_music_dirs:
-
id: '1'
directory: '/tmp/libretime-test'
type: 'stor'
exists: 't'
watched: 't'
cc_files:
-
id: '1'
mime: 'audio/mp3'
ftype: 'audioclip'
directory: '1'
filepath: 'imported/1/oneminute.mp3'
mtime: '2017-08-06 04:27:36'
utime: '2017-08-06 04:26:47'
track_title: 'oneminute.mp3'
bit_rate: '320000'
sample_rate: '44100'
length: '00:01:00'
channels: '2'
genre: 'test'
label: 'nada'
owner_id: '1'
file_exists: 't'
hidden: 'f'
silan_check: 'f'
is_scheduled: 'f'
is_playlist: 'f'
filesize: '2586748'
-
id: '2'
mime: 'audio/mp3'
ftype: 'audioclip'
directory: '1'
filepath: 'imported/1/fiveminute.mp3'
mtime: '2017-08-06 04:28:36'
utime: '2017-08-06 04:27:47'
track_title: 'fiveminute.mp3'
bit_rate: '320000'
sample_rate: '44100'
length: '00:05:00'
channels: '2'
genre: 'test'
label: 'nada'
owner_id: '1'
file_exists: 't'
hidden: 'f'
silan_check: 'f'
is_scheduled: 'f'
is_playlist: 'f'
filesize: '5126748'
-
id: '3'
mime: 'audio/mp3'
ftype: 'audioclip'
directory: '1'
filepath: 'imported/1/track1.mp3'
mtime: '2017-08-06 04:28:36'
utime: '2017-08-06 04:27:47'
track_title: 'track1'
album_title: 'album1'
bit_rate: '320000'
sample_rate: '44100'
length: '00:01:30'
channels: '2'
genre: 'test'
label: 'nada'
owner_id: '1'
file_exists: 't'
hidden: 'f'
silan_check: 'f'
is_scheduled: 'f'
is_playlist: 'f'
filesize: '5126748'
id: '4'
mime: 'audio/mp3'
ftype: 'audioclip'
directory: '1'
filepath: 'imported/1/track2.mp3'
mtime: '2017-08-06 04:28:36'
utime: '2017-08-06 04:27:47'
track_title: 'track2'
album_title: 'album1'
bit_rate: '320000'
sample_rate: '44100'
length: '00:01:30'
channels: '2'
genre: 'test'
label: 'nada'
owner_id: '1'
file_exists: 't'
hidden: 'f'
silan_check: 'f'
is_scheduled: 'f'
is_playlist: 'f'
filesize: '5126748'
id: '5'
mime: 'audio/mp3'
ftype: 'audioclip'
directory: '1'
filepath: 'imported/1/track3.mp3'
mtime: '2017-08-06 04:28:36'
utime: '2017-08-06 04:27:47'
track_title: 'track3'
album_title: 'album1'
bit_rate: '320000'
sample_rate: '44100'
length: '00:01:30'
channels: '2'
genre: 'test'
label: 'nada'
owner_id: '1'
file_exists: 't'
hidden: 'f'
silan_check: 'f'
is_scheduled: 'f'
is_playlist: 'f'
filesize: '5126748'
id: '6'
mime: 'audio/mp3'
ftype: 'audioclip'
directory: '1'
filepath: 'imported/1/track1-2.mp3'
mtime: '2017-08-06 05:28:36'
utime: '2017-08-16 04:27:47'
track_title: 'track1'
album_title: 'album2'
bit_rate: '320000'
sample_rate: '44100'
length: '00:01:30'
channels: '2'
genre: 'test'
label: 'nada'
owner_id: '1'
file_exists: 't'
hidden: 'f'
silan_check: 'f'
is_scheduled: 'f'
is_playlist: 'f'
filesize: '5126748'
id: '7'
mime: 'audio/mp3'
ftype: 'audioclip'
directory: '1'
filepath: 'imported/1/track2-2.mp3'
mtime: '2017-08-06 04:28:36'
utime: '2017-08-06 04:27:47'
track_title: 'track2'
album_title: 'album2'
bit_rate: '320000'
sample_rate: '44100'
length: '00:01:30'
channels: '2'
genre: 'test'
label: 'nada'
owner_id: '1'
file_exists: 't'
hidden: 'f'
silan_check: 'f'
is_scheduled: 'f'
is_playlist: 'f'
filesize: '5126748'

View File

@ -0,0 +1,51 @@
<?php
Class BlockModelData
{
public static function getCriteriaSingleNewestLabelNada() {
return array(
Array("name" => "sp_type", "value" => 0),
Array("name" => "sp_type", "value" => 0),
Array("name" => "sp_repeat_tracks", "value" => 0),
Array("name" => "sp_sort_options", "value" => "newest"),
Array("name" => "sp_limit_value", "value" => 1),
Array("name" => "sp_limit_options", "value" => "items"),
Array("name" => "sp_criteria_field_0_0", "value" => "label"),
Array("name" => "sp_criteria_modifier_0_0", "value" => "contains"),
Array("name" => "sp_criteria_value_0_0", "value" => "nada"),
Array("name" => "sp_overflow_tracks", "value" => 0),
);
}
public static function getCriteriaMultiTrackAndAlbum1Hour()
{
return array (
Array("name" => "sp_type" , "value" => 1),
Array("name" => "sp_repeat_tracks", "value" => 0),
Array("name" => "sp_sort_options", "value" => "random"),
Array("name" => "sp_limit_value", "value" => 1),
Array("name" => "sp_limit_options", "value" => "hours"),
Array("name" => "sp_overflow_tracks", "value" => 0),
Array("name" => "sp_criteria_field_0_0", "value" => "album_title"),
Array("name" => "sp_criteria_modifier_0_0", "value" => "is"),
Array("name" => "sp_criteria_value_0_0", "value" => "album1"),
Array("name" => "sp_criteria_field_0_1", "value" => "album_title"),
Array("name" => "sp_criteria_modifier_0_1", "value" => "is"),
Array("name" => "sp_criteria_value_0_1", "value" => "album2"),
Array("name" => "sp_criteria_field_1_0", "value" => "track_title"),
Array("name" => "sp_criteria_modifier_1_0", "value" => "is"),
Array("name" => "sp_criteria_value_1_0", "value" => "track1"),
Array("name" => "sp_criteria_field_1_1", "value" => "track_title"),
Array("name" => "sp_criteria_modifier_1_1", "value" => "is"),
Array("name" => "sp_criteria_value_1_1", "value" => "track2"),
Array("name" => "sp_criteria_field_1_2", "value" => "track_title"),
Array("name" => "sp_criteria_modifier_1_2", "value" => "is"),
Array("name" => "sp_criteria_value_1_2", "value" => "track3"),
Array("name" => "sp_criteria_field_2_0", "value" => "length"),
Array("name" => "sp_criteria_modifier_2_0", "value" => "is greater than"),
Array("name" => "sp_criteria_value_2_0", "value" => "00:01:00"),
);
}
}