From 3947b6d033a4bb9b357dffa89f00f349dbc74ae5 Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 15 Aug 2012 15:13:07 -0400 Subject: [PATCH 01/10] CC-4113: Smart Playlist: Filename contains '\' cannot be searched -fixed --- airtime_mvc/application/models/Block.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index 617f53265..d8f75fcb0 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1160,12 +1160,13 @@ EOT; } else if ($spCriteriaModifier == "is in the range") { $spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria < '$criteria[extra]'"; } + $spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier]; try{ if ($i > 0) { - $qry->addOr($spCriteria, $spCriteriaValue, $spCriteriaModifier); + $qry->addOr($spCriteria, addslashes($spCriteriaValue), $spCriteriaModifier); } else { - $qry->add($spCriteria, $spCriteriaValue, $spCriteriaModifier); + $qry->add($spCriteria, addslashes($spCriteriaValue), $spCriteriaModifier); } }catch (Exception $e){ Logging::log($e); From 3e8078130873c4669d57362572a45fb2edd0b40a Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 15 Aug 2012 15:36:06 -0400 Subject: [PATCH 02/10] Smart playlist: - fixed modifier selection onchange function --- .../public/js/airtime/playlist/smart_playlistbuilder.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js index 5eb2a2ba5..f9e48b1ef 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js @@ -414,7 +414,8 @@ function sizeTextBoxes(ele, classToRemove, classToAdd) { function populateModifierSelect(e) { var criteria_type = getCriteriaOptionType(e), index = getRowIndex($(e).parent()), - divs = $(e).parents().find('select[id^="sp_criteria_modifier_'+index+'"]'); + critIndex = index.substring(0, 1), + divs = $(e).parents().find('select[id^="sp_criteria_modifier_'+critIndex+'"]'); $.each(divs, function(i, div){ $(div).children().remove(); From 70747d380ca9bb9daad3f69bad9239babf4daa6b Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 15 Aug 2012 15:55:33 -0400 Subject: [PATCH 03/10] cc-4230: fixed bug in no_extension_basename function --- python_apps/media-monitor2/media/monitor/pure.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index 7160f18c0..81843e8bd 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -117,15 +117,17 @@ def no_extension_basename(path): """ returns the extensionsless basename of a filepath >>> no_extension_basename("/home/test.mp3") - 'test' + u'test' >>> no_extension_basename("/home/test") - 'test' + u'test' >>> no_extension_basename('blah.ml') - 'blah' + u'blah' + >>> no_extension_basename('a.b.c.d.mp3') + u'a.b.c.d' """ base = unicode(os.path.basename(path)) if extension(base) == "": return base - else: return base.split(".")[-2] + else: return '.'.join(base.split(".")[0:-1]) def walk_supported(directory, clean_empties=False): """ From 7fe45a5bbc6bf7ded0f05808dca3966a0fe9b132 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 15 Aug 2012 15:04:15 -0400 Subject: [PATCH 04/10] cc-4232: changed bit formatter to give empty string when bitrate is set to 0 --- .../application/models/formatters/BitrateFormatter.php | 8 ++++++-- python_apps/media-monitor2/media/monitor/metadata.py | 2 +- python_apps/media-monitor2/media/monitor/pure.py | 8 ++++---- python_apps/media-monitor2/tests/test_pure.py | 5 +++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/models/formatters/BitrateFormatter.php b/airtime_mvc/application/models/formatters/BitrateFormatter.php index 00828a672..db64a4048 100644 --- a/airtime_mvc/application/models/formatters/BitrateFormatter.php +++ b/airtime_mvc/application/models/formatters/BitrateFormatter.php @@ -19,6 +19,10 @@ class BitrateFormatter { { $Kbps = bcdiv($this->_bitrate, 1000, 0); - return "{$Kbps} Kbps"; + if($Kbps == 0) { + return ""; + } else { + return "{$Kbps} Kbps"; + } } -} \ No newline at end of file +} diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index 2a209d2bd..931ab52da 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -51,7 +51,7 @@ airtime_special = { "MDATA_KEY_DURATION" : lambda m: format_length(getattr(m.info, u'length', 0.0)), "MDATA_KEY_BITRATE" : - lambda m: getattr(m.info, "bitrate", 0), + lambda m: getattr(m.info, "bitrate", ''), "MDATA_KEY_SAMPLERATE" : lambda m: getattr(m.info, u'sample_rate', 0), "MDATA_KEY_MIME" : diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index 81843e8bd..cc70a2f1e 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -209,12 +209,12 @@ def parse_int(s): >>> parse_int("123saf") 123 >>> parse_int("asdf") - 0 + '' """ if s.isdigit(): return s else: - try : return reduce(op.add, takewhile(lambda x: x.isdigit(), s)) - except: return 0 + try : return str(reduce(op.add, takewhile(lambda x: x.isdigit(), s))) + except: return '' def normalized_metadata(md, original_path): """ @@ -241,10 +241,10 @@ def normalized_metadata(md, original_path): # could possibly lead to subtle bugs down the road. Plus the following # approach gives us the flexibility to use different defaults for different # attributes + new_md = remove_whitespace(new_md) new_md = apply_rules_dict(new_md, format_rules) new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'], default=no_extension_basename(original_path)) - new_md = remove_whitespace(new_md) new_md = default_to(dictionary=new_md, keys=path_md, default=u'') new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_FTYPE'], diff --git a/python_apps/media-monitor2/tests/test_pure.py b/python_apps/media-monitor2/tests/test_pure.py index c3b08f874..81918fd10 100644 --- a/python_apps/media-monitor2/tests/test_pure.py +++ b/python_apps/media-monitor2/tests/test_pure.py @@ -67,4 +67,9 @@ class TestMMP(unittest.TestCase): self.assertTrue( mmp.sub_path(d1, f1) ) self.assertTrue( mmp.sub_path(d2, f1) ) + def test_parse_int(self): + self.assertEqual( mmp.parse_int("123"), "123" ) + self.assertEqual( mmp.parse_int("123asf"), "123" ) + self.assertEqual( mmp.parse_int("asdf"), "" ) + if __name__ == '__main__': unittest.main() From a2dfcd6bc261cd8a5aa1aab24b9a0a1e1ed750ab Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 15 Aug 2012 15:05:35 -0400 Subject: [PATCH 05/10] Revert "cc-4232: changed bit formatter to give empty string when bitrate is set to 0" This reverts commit 4e25a5ff442258c13f366a4557ca22181cdfac02. --- .../application/models/formatters/BitrateFormatter.php | 8 ++------ python_apps/media-monitor2/media/monitor/metadata.py | 2 +- python_apps/media-monitor2/media/monitor/pure.py | 8 ++++---- python_apps/media-monitor2/tests/test_pure.py | 5 ----- 4 files changed, 7 insertions(+), 16 deletions(-) diff --git a/airtime_mvc/application/models/formatters/BitrateFormatter.php b/airtime_mvc/application/models/formatters/BitrateFormatter.php index db64a4048..00828a672 100644 --- a/airtime_mvc/application/models/formatters/BitrateFormatter.php +++ b/airtime_mvc/application/models/formatters/BitrateFormatter.php @@ -19,10 +19,6 @@ class BitrateFormatter { { $Kbps = bcdiv($this->_bitrate, 1000, 0); - if($Kbps == 0) { - return ""; - } else { - return "{$Kbps} Kbps"; - } + return "{$Kbps} Kbps"; } -} +} \ No newline at end of file diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index 931ab52da..2a209d2bd 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -51,7 +51,7 @@ airtime_special = { "MDATA_KEY_DURATION" : lambda m: format_length(getattr(m.info, u'length', 0.0)), "MDATA_KEY_BITRATE" : - lambda m: getattr(m.info, "bitrate", ''), + lambda m: getattr(m.info, "bitrate", 0), "MDATA_KEY_SAMPLERATE" : lambda m: getattr(m.info, u'sample_rate', 0), "MDATA_KEY_MIME" : diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index cc70a2f1e..81843e8bd 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -209,12 +209,12 @@ def parse_int(s): >>> parse_int("123saf") 123 >>> parse_int("asdf") - '' + 0 """ if s.isdigit(): return s else: - try : return str(reduce(op.add, takewhile(lambda x: x.isdigit(), s))) - except: return '' + try : return reduce(op.add, takewhile(lambda x: x.isdigit(), s)) + except: return 0 def normalized_metadata(md, original_path): """ @@ -241,10 +241,10 @@ def normalized_metadata(md, original_path): # could possibly lead to subtle bugs down the road. Plus the following # approach gives us the flexibility to use different defaults for different # attributes - new_md = remove_whitespace(new_md) new_md = apply_rules_dict(new_md, format_rules) new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'], default=no_extension_basename(original_path)) + new_md = remove_whitespace(new_md) new_md = default_to(dictionary=new_md, keys=path_md, default=u'') new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_FTYPE'], diff --git a/python_apps/media-monitor2/tests/test_pure.py b/python_apps/media-monitor2/tests/test_pure.py index 81918fd10..c3b08f874 100644 --- a/python_apps/media-monitor2/tests/test_pure.py +++ b/python_apps/media-monitor2/tests/test_pure.py @@ -67,9 +67,4 @@ class TestMMP(unittest.TestCase): self.assertTrue( mmp.sub_path(d1, f1) ) self.assertTrue( mmp.sub_path(d2, f1) ) - def test_parse_int(self): - self.assertEqual( mmp.parse_int("123"), "123" ) - self.assertEqual( mmp.parse_int("123asf"), "123" ) - self.assertEqual( mmp.parse_int("asdf"), "" ) - if __name__ == '__main__': unittest.main() From c58e2e7ff9250c9eedad18587879e3eef3c0127b Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 15 Aug 2012 15:07:09 -0400 Subject: [PATCH 06/10] Revert "Revert "cc-4232: changed bit formatter to give empty string when bitrate is set to 0"" This reverts commit 340e5deb51c11c2dd3445cc1483b21c533d5bdef. --- .../application/models/formatters/BitrateFormatter.php | 8 ++++++-- python_apps/media-monitor2/media/monitor/metadata.py | 2 +- python_apps/media-monitor2/media/monitor/pure.py | 8 ++++---- python_apps/media-monitor2/tests/test_pure.py | 5 +++++ 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/models/formatters/BitrateFormatter.php b/airtime_mvc/application/models/formatters/BitrateFormatter.php index 00828a672..db64a4048 100644 --- a/airtime_mvc/application/models/formatters/BitrateFormatter.php +++ b/airtime_mvc/application/models/formatters/BitrateFormatter.php @@ -19,6 +19,10 @@ class BitrateFormatter { { $Kbps = bcdiv($this->_bitrate, 1000, 0); - return "{$Kbps} Kbps"; + if($Kbps == 0) { + return ""; + } else { + return "{$Kbps} Kbps"; + } } -} \ No newline at end of file +} diff --git a/python_apps/media-monitor2/media/monitor/metadata.py b/python_apps/media-monitor2/media/monitor/metadata.py index 2a209d2bd..931ab52da 100644 --- a/python_apps/media-monitor2/media/monitor/metadata.py +++ b/python_apps/media-monitor2/media/monitor/metadata.py @@ -51,7 +51,7 @@ airtime_special = { "MDATA_KEY_DURATION" : lambda m: format_length(getattr(m.info, u'length', 0.0)), "MDATA_KEY_BITRATE" : - lambda m: getattr(m.info, "bitrate", 0), + lambda m: getattr(m.info, "bitrate", ''), "MDATA_KEY_SAMPLERATE" : lambda m: getattr(m.info, u'sample_rate', 0), "MDATA_KEY_MIME" : diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index 81843e8bd..cc70a2f1e 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -209,12 +209,12 @@ def parse_int(s): >>> parse_int("123saf") 123 >>> parse_int("asdf") - 0 + '' """ if s.isdigit(): return s else: - try : return reduce(op.add, takewhile(lambda x: x.isdigit(), s)) - except: return 0 + try : return str(reduce(op.add, takewhile(lambda x: x.isdigit(), s))) + except: return '' def normalized_metadata(md, original_path): """ @@ -241,10 +241,10 @@ def normalized_metadata(md, original_path): # could possibly lead to subtle bugs down the road. Plus the following # approach gives us the flexibility to use different defaults for different # attributes + new_md = remove_whitespace(new_md) new_md = apply_rules_dict(new_md, format_rules) new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'], default=no_extension_basename(original_path)) - new_md = remove_whitespace(new_md) new_md = default_to(dictionary=new_md, keys=path_md, default=u'') new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_FTYPE'], diff --git a/python_apps/media-monitor2/tests/test_pure.py b/python_apps/media-monitor2/tests/test_pure.py index c3b08f874..81918fd10 100644 --- a/python_apps/media-monitor2/tests/test_pure.py +++ b/python_apps/media-monitor2/tests/test_pure.py @@ -67,4 +67,9 @@ class TestMMP(unittest.TestCase): self.assertTrue( mmp.sub_path(d1, f1) ) self.assertTrue( mmp.sub_path(d2, f1) ) + def test_parse_int(self): + self.assertEqual( mmp.parse_int("123"), "123" ) + self.assertEqual( mmp.parse_int("123asf"), "123" ) + self.assertEqual( mmp.parse_int("asdf"), "" ) + if __name__ == '__main__': unittest.main() From 4e0b4c210e13166e2c91075abbf53e9e04fc42b8 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 15 Aug 2012 15:48:41 -0400 Subject: [PATCH 07/10] cc-4232: added some comments and doctests --- python_apps/media-monitor2/media/monitor/pure.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/pure.py b/python_apps/media-monitor2/media/monitor/pure.py index cc70a2f1e..8bc1639c0 100644 --- a/python_apps/media-monitor2/media/monitor/pure.py +++ b/python_apps/media-monitor2/media/monitor/pure.py @@ -62,7 +62,7 @@ def partition(f, alist): Partition is very similar to filter except that it also returns the elements for which f return false but in a tuple. >>> partition(lambda x : x > 3, [1,2,3,4,5,6]) - [4,5,6],[1,2,3] + ([4, 5, 6], [1, 2, 3]) """ return (filter(f, alist), filter(lambda x: not f(x), alist)) @@ -104,6 +104,8 @@ def extension(path): I.e. interpreter won't enforce None checks on the programmer >>> extension("testing.php") 'php' + >>> extension("a.b.c.d.php") + 'php' >>> extension('/no/extension') '' >>> extension('/path/extension.ml') @@ -205,9 +207,9 @@ def parse_int(s): Tries very hard to get some sort of integer result from s. Defaults to 0 when it failes >>> parse_int("123") - 123 + '123' >>> parse_int("123saf") - 123 + '123' >>> parse_int("asdf") '' """ @@ -244,11 +246,10 @@ def normalized_metadata(md, original_path): new_md = remove_whitespace(new_md) new_md = apply_rules_dict(new_md, format_rules) new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_TITLE'], - default=no_extension_basename(original_path)) - new_md = default_to(dictionary=new_md, keys=path_md, - default=u'') + default=no_extension_basename(original_path)) + new_md = default_to(dictionary=new_md, keys=path_md, default=u'') new_md = default_to(dictionary=new_md, keys=['MDATA_KEY_FTYPE'], - default=u'audioclip') + default=u'audioclip') # In the case where the creator is 'Airtime Show Recorder' we would like to # format the MDATA_KEY_TITLE slightly differently # Note: I don't know why I'm doing a unicode string comparison here From 2d8013135178b85e060805a65dcfceebfba08ec2 Mon Sep 17 00:00:00 2001 From: James Date: Wed, 15 Aug 2012 16:22:56 -0400 Subject: [PATCH 08/10] CC-4229: Smart Playlist: refactor code - bug fixes --- .../application/forms/SmartBlockCriteria.php | 293 ++++++++++++------ .../scripts/form/smart-block-criteria.phtml | 7 + .../airtime/playlist/smart_playlistbuilder.js | 10 +- 3 files changed, 207 insertions(+), 103 deletions(-) diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php index 06835ed24..e8da5c0e1 100644 --- a/airtime_mvc/application/forms/SmartBlockCriteria.php +++ b/airtime_mvc/application/forms/SmartBlockCriteria.php @@ -1,6 +1,88 @@ "Select criteria", + "album_title" => "Album", + "bit_rate" => "Bit Rate", + "bpm" => "Bpm", + "comments" => "Comments", + "composer" => "Composer", + "conductor" => "Conductor", + "artist_name" => "Creator", + "disc_number" => "Disc Number", + "genre" => "Genre", + "isrc_number" => "ISRC", + "label" => "Label", + "language" => "Language", + "mtime" => "Last Modified", + "lptime" => "Last Played", + "length" => "Length", + "lyricist" => "Lyricist", + "mood" => "Mood", + "name" => "Name", + "orchestra" => "Orchestra", + "rating" => "Rating", + "sample_rate" => "Sample Rate", + "track_title" => "Title", + "track_number" => "Track Number", + "utime" => "Uploaded", + "year" => "Year" + ); + + private $criteriaTypes = array( + 0 => "", + "album_title" => "s", + "artist_name" => "s", + "bit_rate" => "n", + "bpm" => "n", + "comments" => "s", + "composer" => "s", + "conductor" => "s", + "utime" => "n", + "mtime" => "n", + "lptime" => "n", + "disc_number" => "n", + "genre" => "s", + "isrc_number" => "s", + "label" => "s", + "language" => "s", + "length" => "n", + "lyricist" => "s", + "mood" => "s", + "name" => "s", + "orchestra" => "s", + "rating" => "n", + "sample_rate" => "n", + "track_title" => "s", + "track_number" => "n", + "year" => "n" + ); + + private $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" + ); + + private $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" + ); + + private $limitOptions = array( + "hours" => "hours", + "minutes" => "minutes", + "items" => "items" + ); public function init(){ @@ -8,89 +90,6 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm public function startForm($p_blockId) { - $criteriaOptions = array( - 0 => "Select criteria", - "album_title" => "Album", - "bit_rate" => "Bit Rate", - "bpm" => "Bpm", - "comments" => "Comments", - "composer" => "Composer", - "conductor" => "Conductor", - "artist_name" => "Creator", - "disc_number" => "Disc Number", - "genre" => "Genre", - "isrc_number" => "ISRC", - "label" => "Label", - "language" => "Language", - "mtime" => "Last Modified", - "lptime" => "Last Played", - "length" => "Length", - "lyricist" => "Lyricist", - "mood" => "Mood", - "name" => "Name", - "orchestra" => "Orchestra", - "rating" => "Rating", - "sample_rate" => "Sample Rate", - "track_title" => "Title", - "track_number" => "Track Number", - "utime" => "Uploaded", - "year" => "Year" - ); - - $criteriaTypes = array( - 0 => "", - "album_title" => "s", - "artist_name" => "s", - "bit_rate" => "n", - "bpm" => "s", - "comments" => "s", - "composer" => "s", - "conductor" => "s", - "utime" => "n", - "mtime" => "n", - "lptime" => "n", - "disc_number" => "n", - "genre" => "s", - "isrc_number" => "s", - "label" => "s", - "language" => "s", - "length" => "n", - "lyricist" => "s", - "mood" => "s", - "name" => "s", - "orchestra" => "s", - "rating" => "n", - "sample_rate" => "n", - "track_title" => "s", - "track_number" => "n", - "year" => "n" - ); - - $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" - ); - - $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" - ); - - $limitOptions = array( - "hours" => "hours", - "minutes" => "minutes", - "items" => "items" - ); - // load type $out = CcBlockQuery::create()->findPk($p_blockId); if ($out->getDbType() == "static") { @@ -128,7 +127,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm if (isset($storedCrit["crit"])) { $criteriaKeys = array_keys($storedCrit["crit"]); } - $numElements = count($criteriaOptions); + $numElements = count($this->criteriaOptions); for ($i = 0; $i < $numElements; $i++) { $criteriaType = ""; @@ -155,13 +154,13 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $criteria->setAttrib('class', 'input_select sp_input_select'.$invisible) ->setValue('Select criteria') ->setDecorators(array('viewHelper')) - ->setMultiOptions($criteriaOptions); + ->setMultiOptions($this->criteriaOptions); if ($i != 0 && !isset($criteriaKeys[$i])) { $criteria->setAttrib('disabled', 'disabled'); } if (isset($criteriaKeys[$i])) { - $criteriaType = $criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]]; + $criteriaType = $this->criteriaTypes[$storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]]; $criteria->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["criteria"]); } $this->addElement($criteria); @@ -176,9 +175,9 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm } if (isset($criteriaKeys[$i])) { if($criteriaType == "s"){ - $criteriaModifers->setMultiOptions($stringCriteriaOptions); + $criteriaModifers->setMultiOptions($this->stringCriteriaOptions); }else{ - $criteriaModifers->setMultiOptions($numericCriteriaOptions); + $criteriaModifers->setMultiOptions($this->numericCriteriaOptions); } $criteriaModifers->setValue($storedCrit["crit"][$criteriaKeys[$i]][$j]["modifier"]); }else{ @@ -217,7 +216,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $limit = new Zend_Form_Element_Select('sp_limit_options'); $limit->setAttrib('class', 'sp_input_select') ->setDecorators(array('viewHelper')) - ->setMultiOptions($limitOptions); + ->setMultiOptions($this->limitOptions); if (isset($storedCrit["limit"])) { $limit->setValue($storedCrit["limit"]["modifier"]); } @@ -262,19 +261,117 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm $this->setDecorators(array( array('ViewScript', array('viewScript' => 'form/smart-block-criteria.phtml', "openOption"=> $openSmartBlockOption, - 'criteriasLength' => count($criteriaOptions), 'poolCount' => $files['count'], 'modRowMap' => $modRowMap)) + 'criteriasLength' => count($this->criteriaOptions), 'poolCount' => $files['count'], 'modRowMap' => $modRowMap)) )); } - function isValid($params){ - Logging::log("isvalid called"); - $isValid = true; - // reconstruct the params['criteria'] so we can populate the form - $formData = array(); - foreach ($params['data'] as $ele) { - $formData[$ele['name']] = $ele['value']; + function preValidation($params) { + $data = Application_Model_Block::organizeSmartPlyalistCriteria($params['data']); + // add elelments that needs to be added + // set multioption for modifier according to creiteria_field + $modRowMap = array(); + foreach ($data['criteria'] as $critKey=>$d) { + $count = 1; + foreach($d as $modKey=>$modInfo) { + if ($modKey == 0) { + $eleCrit = $this->getElement("sp_criteria_field_".$critKey."_".$modKey); + $eleCrit->setValue($this->criteriaOptions[$modInfo['sp_criteria_field']]); + $eleCrit->setAttrib("disabled", null); + + $eleMod = $this->getElement("sp_criteria_modifier_".$critKey."_".$modKey); + $criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']]; + if ($criteriaType == "s") { + $eleMod->setMultiOptions($this->stringCriteriaOptions); + } else if ($criteriaType == "n") { + $eleMod->setMultiOptions($this->numericCriteriaOptions); + } else { + $eleMod->setMultiOptions(array('0' => 'Select modifier')); + } + $eleMod->setValue($modInfo['sp_criteria_modifier']); + $eleMod->setAttrib("disabled", null); + + $eleValue = $this->getElement("sp_criteria_value_".$critKey."_".$modKey); + $eleValue->setValue($modInfo['sp_criteria_value']); + $eleValue->setAttrib("disabled", null); + + if (isset($modInfo['sp_criteria_extra'])) { + $eleExtra = $this->getElement("sp_criteria_extra_".$critKey."_".$modKey); + $eleExtra->setValue($modInfo['sp_criteria_extra']); + $eleValue->setAttrib('class', 'input_text sp_extra_input_text'); + $eleExtra->setAttrib("disabled", null); + } + + } else { + $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')) + ->setMultiOptions($this->criteriaOptions); + + $criteriaType = $this->criteriaTypes[$modInfo['sp_criteria_field']]; + $criteria->setValue($this->criteriaOptions[$modInfo['sp_criteria_field']]); + $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") { + $criteriaModifers->setMultiOptions($this->stringCriteriaOptions); + } else if ($criteriaType == "n") { + $criteriaModifers->setMultiOptions($this->numericCriteriaOptions); + } else { + $criteriaModifers->setMultiOptions(array('0' => 'Select modifier')); + } + $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); + + /****************** EXTRA ***********/ + $criteriaExtra = new Zend_Form_Element_Text("sp_criteria_extra_".$critKey."_".$modKey); + $criteriaExtra->setAttrib('class', 'input_text sp_extra_input_text') + ->setDecorators(array('viewHelper')); + 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'); + } + $this->addElement($criteriaExtra); + $count++; + } + } + $modRowMap[$critKey] = $count; } + + $decorator = $this->getDecorator("ViewScript"); + $existingModRow = $decorator->getOption("modRowMap"); + foreach ($modRowMap as $key=>$v) { + $existingModRow[$key] = $v; + } + $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']; + } + $this->populate($formData); + return $data; + } + + function isValid($params){ + $isValid = true; + $data = $this->preValidation($params); $criteria2PeerMap = array( 0 => "Select criteria", "album_title" => "DbAlbumTitle", @@ -303,7 +400,7 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm "track_number" => "DbTrackNumber", "year" => "DbYear" ); - $data = Application_Model_Block::organizeSmartPlyalistCriteria($params['data']); + // 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 diff --git a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml index 38c2719d8..2559d20f6 100644 --- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml +++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml @@ -57,6 +57,13 @@ element->getElement('sp_limit_value')->getLabel() ?> element->getElement('sp_limit_value')?> element->getElement('sp_limit_options') ?> + element->getElement("sp_limit_value")->hasErrors()) : ?> + element->getElement("sp_limit_value")->getMessages() as $error): ?> + + + + +
diff --git a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js index 5eb2a2ba5..8c275ee02 100644 --- a/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js +++ b/airtime_mvc/public/js/airtime/playlist/smart_playlistbuilder.js @@ -441,14 +441,12 @@ function getCriteriaOptionType(e) { } function callback(data, type) { - var form = $('#smart-playlist-form'), - json = $.parseJSON(data), + var json = $.parseJSON(data), dt = $('table[id="library_display"]').dataTable(); - form.find('span[class="errors sp-errors"]').remove(); if (type == 'shuffle' || type == 'generate') { AIRTIME.playlist.fnOpenPlaylist(json); - form = $('#smart-playlist-form'); + var form = $('#smart-playlist-form'); if (json.result == "0") { if (type == 'shuffle') { form.find('.success').text('Smart playlist shuffled'); @@ -462,6 +460,7 @@ function callback(data, type) { form.find('#smart_playlist_options').removeClass("closed"); } else { AIRTIME.playlist.fnOpenPlaylist(json); + var form = $('#smart-playlist-form'); if (json.result == "0") { $('#sp-success-saved').text('Smart playlist saved'); $('#sp-success-saved').show(); @@ -470,6 +469,7 @@ function callback(data, type) { var dt = $('table[id="library_display"]').dataTable(); dt.fnStandingRedraw(); } + form.find('#smart_playlist_options').removeClass("closed"); } setTimeout(removeSuccessMsg, 5000); } @@ -529,7 +529,7 @@ var criteriaTypes = { "album_title" : "s", "artist_name" : "s", "bit_rate" : "n", - "bpm" : "s", + "bpm" : "n", "comments" : "s", "composer" : "s", "conductor" : "s", From 8f114689ae9d6fa9086fecbc74c4d4cc63319944 Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 15 Aug 2012 16:30:33 -0400 Subject: [PATCH 09/10] cc-4232: removed wrong comments --- python_apps/media-monitor2/media/monitor/listeners.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/python_apps/media-monitor2/media/monitor/listeners.py b/python_apps/media-monitor2/media/monitor/listeners.py index 93c77f394..ecc2b793a 100644 --- a/python_apps/media-monitor2/media/monitor/listeners.py +++ b/python_apps/media-monitor2/media/monitor/listeners.py @@ -65,8 +65,6 @@ class BaseListener(object): self.signal = signal class OrganizeListener(BaseListener, pyinotify.ProcessEvent, Loggable): - # this class still don't handle the case where a dir was copied recursively - def process_IN_CLOSE_WRITE(self, event): self.process_to_organize(event) # got cookie From ea621fd9dc5ba6edd41e40e4218566ed5c26f429 Mon Sep 17 00:00:00 2001 From: denise Date: Wed, 15 Aug 2012 16:40:04 -0400 Subject: [PATCH 10/10] CC-4223: Smart playlists: BPM criteria should have numeric modifiers -done --- airtime_mvc/application/models/Block.php | 8 +++--- airtime_mvc/application/models/StoredFile.php | 2 +- .../models/airtime/map/CcFilesTableMap.php | 2 +- .../models/airtime/om/BaseCcFiles.php | 10 +++---- .../models/airtime/om/BaseCcFilesQuery.php | 27 ++++++++++++------- airtime_mvc/build/schema.xml | 2 +- airtime_mvc/build/sql/schema.sql | 2 +- 7 files changed, 31 insertions(+), 22 deletions(-) diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php index d8f75fcb0..640389bbe 100644 --- a/airtime_mvc/application/models/Block.php +++ b/airtime_mvc/application/models/Block.php @@ -1148,7 +1148,7 @@ EOT; // e.g 192kps is stored as 192000 $spCriteriaValue = $criteria['value']*1000; } else { - $spCriteriaValue = $criteria['value']; + $spCriteriaValue = addslashes($criteria['value']); } if ($spCriteriaModifier == "starts with") { @@ -1158,15 +1158,15 @@ EOT; } else if ($spCriteriaModifier == "contains" || $spCriteriaModifier == "does not contain") { $spCriteriaValue = "%$spCriteriaValue%"; } else if ($spCriteriaModifier == "is in the range") { - $spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria < '$criteria[extra]'"; + $spCriteriaValue = "$spCriteria > '$spCriteriaValue' AND $spCriteria <= '$criteria[extra]'"; } $spCriteriaModifier = self::$modifier2CriteriaMap[$spCriteriaModifier]; try{ if ($i > 0) { - $qry->addOr($spCriteria, addslashes($spCriteriaValue), $spCriteriaModifier); + $qry->addOr($spCriteria, $spCriteriaValue, $spCriteriaModifier); } else { - $qry->add($spCriteria, addslashes($spCriteriaValue), $spCriteriaModifier); + $qry->add($spCriteria, $spCriteriaValue, $spCriteriaModifier); } }catch (Exception $e){ Logging::log($e); diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index 144cfef73..d0194b54c 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -634,7 +634,7 @@ class Application_Model_StoredFile $streamSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS ".$key; } //need to cast certain data as ints for the union to search on. - else if (in_array($key, array("track_number", "bit_rate", "sample_rate"))) { + else if (in_array($key, array("track_number", "bit_rate", "sample_rate", "bpm"))) { $plSelect[] = "NULL::int AS ".$key; $blSelect[] = "NULL::int AS ".$key; $fileSelect[] = $key; diff --git a/airtime_mvc/application/models/airtime/map/CcFilesTableMap.php b/airtime_mvc/application/models/airtime/map/CcFilesTableMap.php index 99d2ab18d..0f0707722 100644 --- a/airtime_mvc/application/models/airtime/map/CcFilesTableMap.php +++ b/airtime_mvc/application/models/airtime/map/CcFilesTableMap.php @@ -64,7 +64,7 @@ class CcFilesTableMap extends TableMap { $this->addColumn('TRACK_NUMBER', 'DbTrackNumber', 'INTEGER', false, null, null); $this->addColumn('CHANNELS', 'DbChannels', 'INTEGER', false, null, null); $this->addColumn('URL', 'DbUrl', 'VARCHAR', false, 1024, null); - $this->addColumn('BPM', 'DbBpm', 'VARCHAR', false, 8, null); + $this->addColumn('BPM', 'DbBpm', 'INTEGER', false, null, null); $this->addColumn('RATING', 'DbRating', 'VARCHAR', false, 8, null); $this->addColumn('ENCODED_BY', 'DbEncodedBy', 'VARCHAR', false, 255, null); $this->addColumn('DISC_NUMBER', 'DbDiscNumber', 'VARCHAR', false, 8, null); diff --git a/airtime_mvc/application/models/airtime/om/BaseCcFiles.php b/airtime_mvc/application/models/airtime/om/BaseCcFiles.php index 57228452f..3b8daf54f 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcFiles.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcFiles.php @@ -189,7 +189,7 @@ abstract class BaseCcFiles extends BaseObject implements Persistent /** * The value for the bpm field. - * @var string + * @var int */ protected $bpm; @@ -814,7 +814,7 @@ abstract class BaseCcFiles extends BaseObject implements Persistent /** * Get the [bpm] column value. * - * @return string + * @return int */ public function getDbBpm() { @@ -1822,13 +1822,13 @@ abstract class BaseCcFiles extends BaseObject implements Persistent /** * Set the value of [bpm] column. * - * @param string $v new value + * @param int $v new value * @return CcFiles The current object (for fluent API support) */ public function setDbBpm($v) { if ($v !== null) { - $v = (string) $v; + $v = (int) $v; } if ($this->bpm !== $v) { @@ -2678,7 +2678,7 @@ abstract class BaseCcFiles extends BaseObject implements Persistent $this->track_number = ($row[$startcol + 23] !== null) ? (int) $row[$startcol + 23] : null; $this->channels = ($row[$startcol + 24] !== null) ? (int) $row[$startcol + 24] : null; $this->url = ($row[$startcol + 25] !== null) ? (string) $row[$startcol + 25] : null; - $this->bpm = ($row[$startcol + 26] !== null) ? (string) $row[$startcol + 26] : null; + $this->bpm = ($row[$startcol + 26] !== null) ? (int) $row[$startcol + 26] : null; $this->rating = ($row[$startcol + 27] !== null) ? (string) $row[$startcol + 27] : null; $this->encoded_by = ($row[$startcol + 28] !== null) ? (string) $row[$startcol + 28] : null; $this->disc_number = ($row[$startcol + 29] !== null) ? (string) $row[$startcol + 29] : null; diff --git a/airtime_mvc/application/models/airtime/om/BaseCcFilesQuery.php b/airtime_mvc/application/models/airtime/om/BaseCcFilesQuery.php index 42d2f42f2..1dce43d8d 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcFilesQuery.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcFilesQuery.php @@ -191,7 +191,7 @@ * @method CcFiles findOneByDbTrackNumber(int $track_number) Return the first CcFiles filtered by the track_number column * @method CcFiles findOneByDbChannels(int $channels) Return the first CcFiles filtered by the channels column * @method CcFiles findOneByDbUrl(string $url) Return the first CcFiles filtered by the url column - * @method CcFiles findOneByDbBpm(string $bpm) Return the first CcFiles filtered by the bpm column + * @method CcFiles findOneByDbBpm(int $bpm) Return the first CcFiles filtered by the bpm column * @method CcFiles findOneByDbRating(string $rating) Return the first CcFiles filtered by the rating column * @method CcFiles findOneByDbEncodedBy(string $encoded_by) Return the first CcFiles filtered by the encoded_by column * @method CcFiles findOneByDbDiscNumber(string $disc_number) Return the first CcFiles filtered by the disc_number column @@ -255,7 +255,7 @@ * @method array findByDbTrackNumber(int $track_number) Return CcFiles objects filtered by the track_number column * @method array findByDbChannels(int $channels) Return CcFiles objects filtered by the channels column * @method array findByDbUrl(string $url) Return CcFiles objects filtered by the url column - * @method array findByDbBpm(string $bpm) Return CcFiles objects filtered by the bpm column + * @method array findByDbBpm(int $bpm) Return CcFiles objects filtered by the bpm column * @method array findByDbRating(string $rating) Return CcFiles objects filtered by the rating column * @method array findByDbEncodedBy(string $encoded_by) Return CcFiles objects filtered by the encoded_by column * @method array findByDbDiscNumber(string $disc_number) Return CcFiles objects filtered by the disc_number column @@ -1061,20 +1061,29 @@ abstract class BaseCcFilesQuery extends ModelCriteria /** * Filter the query on the bpm column * - * @param string $dbBpm The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) + * @param int|array $dbBpm The value to use as filter. + * Accepts an associative array('min' => $minValue, 'max' => $maxValue) * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL * * @return CcFilesQuery The current query, for fluid interface */ public function filterByDbBpm($dbBpm = null, $comparison = null) { - if (null === $comparison) { - if (is_array($dbBpm)) { + if (is_array($dbBpm)) { + $useMinMax = false; + if (isset($dbBpm['min'])) { + $this->addUsingAlias(CcFilesPeer::BPM, $dbBpm['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($dbBpm['max'])) { + $this->addUsingAlias(CcFilesPeer::BPM, $dbBpm['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $dbBpm)) { - $dbBpm = str_replace('*', '%', $dbBpm); - $comparison = Criteria::LIKE; } } return $this->addUsingAlias(CcFilesPeer::BPM, $dbBpm, $comparison); diff --git a/airtime_mvc/build/schema.xml b/airtime_mvc/build/schema.xml index 6486208ed..6a81f5ae4 100644 --- a/airtime_mvc/build/schema.xml +++ b/airtime_mvc/build/schema.xml @@ -38,7 +38,7 @@ - + diff --git a/airtime_mvc/build/sql/schema.sql b/airtime_mvc/build/sql/schema.sql index 421b4cff4..2fb1bd978 100644 --- a/airtime_mvc/build/sql/schema.sql +++ b/airtime_mvc/build/sql/schema.sql @@ -56,7 +56,7 @@ CREATE TABLE "cc_files" "track_number" INTEGER, "channels" INTEGER, "url" VARCHAR(1024), - "bpm" VARCHAR(8), + "bpm" INTEGER, "rating" VARCHAR(8), "encoded_by" VARCHAR(255), "disc_number" VARCHAR(8),