CC-84: Smart Playlists
- added 'Smart Block' filter in datatable - added block files to library datatable
This commit is contained in:
parent
1f3cbd8aba
commit
bef9ba1eea
9 changed files with 147 additions and 50 deletions
|
@ -94,7 +94,7 @@ class Application_Model_Block
|
|||
}
|
||||
} else {
|
||||
$this->block = new CcBlock();
|
||||
$this->block->setDbUTime("now", new DateTimeZone("UTC"));
|
||||
$this->block->setDbUTime(new DateTime("now", new DateTimeZone("UTC")));
|
||||
$this->block->save();
|
||||
}
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ class Application_Model_Playlist
|
|||
}
|
||||
} else {
|
||||
$this->pl = new CcPlaylist();
|
||||
$this->pl->setDbUTime("now", new DateTimeZone("UTC"));
|
||||
$this->pl->setDbUTime(new DateTime("now", new DateTimeZone("UTC")));
|
||||
$this->pl->save();
|
||||
}
|
||||
|
||||
|
@ -135,6 +135,9 @@ class Application_Model_Playlist
|
|||
|
||||
public function getLastModified($format = null)
|
||||
{
|
||||
//Logging::log($this->pl->getDbMtime($format));
|
||||
//Logging::log($this->pl);
|
||||
Logging::log("5555");
|
||||
return $this->pl->getDbMtime($format);
|
||||
}
|
||||
|
||||
|
|
|
@ -648,49 +648,60 @@ Logging::log("getting media! - 2");
|
|||
);
|
||||
|
||||
$plSelect = array();
|
||||
$blSelect = array();
|
||||
$fileSelect = array();
|
||||
foreach ($displayColumns as $key) {
|
||||
|
||||
if ($key === "id") {
|
||||
$plSelect[] = "PL.id AS ".$key;
|
||||
$blSelect[] = "BL.id AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
} elseif ($key === "track_title") {
|
||||
$plSelect[] = "name AS ".$key;
|
||||
$blSelect[] = "name AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
} elseif ($key === "ftype") {
|
||||
$plSelect[] = "'playlist'::varchar AS ".$key;
|
||||
$blSelect[] = "'block'::varchar AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
} elseif ($key === "artist_name") {
|
||||
$plSelect[] = "login AS ".$key;
|
||||
$blSelect[] = "login AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
}
|
||||
//same columns in each table.
|
||||
else if (in_array($key, array("length", "utime", "mtime"))) {
|
||||
$plSelect[] = $key;
|
||||
$blSelect[] = $key;
|
||||
$fileSelect[] = $key;
|
||||
} elseif ($key === "year") {
|
||||
|
||||
$plSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
|
||||
$blSelect[] = "EXTRACT(YEAR FROM utime)::varchar AS ".$key;
|
||||
$fileSelect[] = "year 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"))) {
|
||||
$plSelect[] = "NULL::int AS ".$key;
|
||||
$blSelect[] = "NULL::int AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
} else {
|
||||
$plSelect[] = "NULL::text AS ".$key;
|
||||
$blSelect[] = "NULL::text AS ".$key;
|
||||
$fileSelect[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
$plSelect = "SELECT ". join(",", $plSelect);
|
||||
$blSelect = "SELECT ". join(",", $blSelect);
|
||||
$fileSelect = "SELECT ". join(",", $fileSelect);
|
||||
|
||||
$type = intval($datatables["type"]);
|
||||
|
||||
$plTable = "({$plSelect} FROM cc_playlist AS PL LEFT JOIN cc_subjs AS sub ON (sub.id = PL.creator_id))";
|
||||
$blTable = "({$blSelect} FROM cc_block AS BL LEFT JOIN cc_subjs AS sub ON (sub.id = BL.creator_id))";
|
||||
$fileTable = "({$fileSelect} FROM cc_files AS FILES WHERE file_exists = 'TRUE')";
|
||||
$unionTable = "({$plTable} UNION {$fileTable} ) AS RESULTS";
|
||||
$unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} ) AS RESULTS";
|
||||
|
||||
//choose which table we need to select data from.
|
||||
switch ($type) {
|
||||
|
@ -703,6 +714,9 @@ Logging::log("getting media! - 2");
|
|||
case 2:
|
||||
$fromTable = $plTable." AS Playlist"; //need an alias for the table if it's standalone.
|
||||
break;
|
||||
case 3:
|
||||
$fromTable = $blTable." AS Block"; //need an alias for the table if it's standalone.
|
||||
break;
|
||||
default:
|
||||
$fromTable = $unionTable;
|
||||
}
|
||||
|
@ -723,16 +737,15 @@ Logging::log("getting media! - 2");
|
|||
$formatter = new BitrateFormatter($row['bit_rate']);
|
||||
$row['bit_rate'] = $formatter->format();
|
||||
}
|
||||
|
||||
|
||||
//convert mtime and utime to localtime
|
||||
$row['mtime'] = new DateTime($row['mtime'], new DateTimeZone('UTC'));
|
||||
$row['mtime']->setTimeZone(new DateTimeZone(date_default_timezone_get()));
|
||||
$row['mtime'] = $row['mtime']->format('Y-m-d H:i:s');
|
||||
|
||||
$row['utime'] = new DateTime($row['utime'], new DateTimeZone('UTC'));
|
||||
$row['utime']->setTimeZone(new DateTimeZone(date_default_timezone_get()));
|
||||
$row['utime'] = $row['utime']->format('Y-m-d H:i:s');
|
||||
|
||||
|
||||
// add checkbox row
|
||||
$row['checkbox'] = "<input type='checkbox' name='cb_".$row['id']."'>";
|
||||
|
||||
|
|
|
@ -14,5 +14,87 @@
|
|||
* @package propel.generator.airtime
|
||||
*/
|
||||
class CcBlock extends BaseCcBlock {
|
||||
/**
|
||||
* Get the [optionally formatted] temporal [utime] column value.
|
||||
*
|
||||
*
|
||||
* @param string $format The date/time format string (either date()-style or strftime()-style).
|
||||
* If format is NULL, then the raw DateTime object will be returned.
|
||||
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
|
||||
* @throws PropelException - if unable to parse/validate the date/time value.
|
||||
*/
|
||||
public function getDbUtime($format = 'Y-m-d H:i:s')
|
||||
{
|
||||
if ($this->utime === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$dt = new DateTime($this->utime, new DateTimeZone("UTC"));
|
||||
} catch (Exception $x) {
|
||||
throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->utime, true), $x);
|
||||
}
|
||||
|
||||
if ($format === null) {
|
||||
// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
|
||||
return $dt;
|
||||
} elseif (strpos($format, '%') !== false) {
|
||||
return strftime($format, $dt->format('U'));
|
||||
} else {
|
||||
return $dt->format($format);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the [optionally formatted] temporal [mtime] column value.
|
||||
*
|
||||
*
|
||||
* @param string $format The date/time format string (either date()-style or strftime()-style).
|
||||
* If format is NULL, then the raw DateTime object will be returned.
|
||||
* @return mixed Formatted date/time value as string or DateTime object (if format is NULL), NULL if column is NULL
|
||||
* @throws PropelException - if unable to parse/validate the date/time value.
|
||||
*/
|
||||
public function getDbMtime($format = 'Y-m-d H:i:s')
|
||||
{
|
||||
if ($this->mtime === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
$dt = new DateTime($this->mtime, new DateTimeZone("UTC"));
|
||||
} catch (Exception $x) {
|
||||
throw new PropelException("Internally stored date/time/timestamp value could not be converted to DateTime: " . var_export($this->mtime, true), $x);
|
||||
}
|
||||
|
||||
if ($format === null) {
|
||||
// Because propel.useDateTimeClass is TRUE, we return a DateTime object.
|
||||
return $dt;
|
||||
} elseif (strpos($format, '%') !== false) {
|
||||
return strftime($format, $dt->format('U'));
|
||||
} else {
|
||||
return $dt->format($format);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes the value of the aggregate column length
|
||||
* Overridden to provide a default of 00:00:00 if the playlist is empty.
|
||||
*
|
||||
* @param PropelPDO $con A connection object
|
||||
*
|
||||
* @return mixed The scalar result from the aggregate query
|
||||
*/
|
||||
public function computeDbLength(PropelPDO $con)
|
||||
{
|
||||
$stmt = $con->prepare('SELECT SUM(cliplength) FROM "cc_playlistcontents" WHERE cc_playlistcontents.PLAYLIST_ID = :p1');
|
||||
$stmt->bindValue(':p1', $this->getDbId());
|
||||
$stmt->execute();
|
||||
$length = $stmt->fetchColumn();
|
||||
|
||||
if (is_null($length)) {
|
||||
$length = "00:00:00";
|
||||
}
|
||||
|
||||
return $length;
|
||||
}
|
||||
} // CcBlock
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue