CC-4223: Smart playlists: BPM criteria should have numeric modifiers

-done
This commit is contained in:
denise 2012-08-15 16:40:04 -04:00
parent 1dbdadef62
commit ea621fd9dc
7 changed files with 31 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -38,7 +38,7 @@
<column name="track_number" phpName="DbTrackNumber" type="INTEGER" required="false"/>
<column name="channels" phpName="DbChannels" type="INTEGER" required="false"/>
<column name="url" phpName="DbUrl" type="VARCHAR" size="1024" required="false"/>
<column name="bpm" phpName="DbBpm" type="VARCHAR" size="8" required="false"/>
<column name="bpm" phpName="DbBpm" type="INTEGER" required="false"/>
<column name="rating" phpName="DbRating" type="VARCHAR" size="8" required="false"/>
<column name="encoded_by" phpName="DbEncodedBy" type="VARCHAR" size="255" required="false"/>
<column name="disc_number" phpName="DbDiscNumber" type="VARCHAR" size="8" required="false"/>

View File

@ -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),