From f901e13a843fb4ac60ebf6063d48617b9bf5ddec Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Fri, 3 Aug 2012 18:06:47 -0400 Subject: [PATCH] CC-1665: Scheduled stream rebroadcasting and recording -Make playlist builder show creator name instead of creator id --- .../controllers/WebstreamController.php | 28 +++++++++++++++++-- airtime_mvc/application/models/StoredFile.php | 8 +++--- airtime_mvc/application/models/Webstream.php | 27 ++---------------- .../airtime/map/CcWebstreamTableMap.php | 2 +- .../models/airtime/om/BaseCcWebstream.php | 10 +++---- .../airtime/om/BaseCcWebstreamQuery.php | 27 ++++++++++++------ airtime_mvc/build/schema.xml | 2 +- airtime_mvc/build/sql/schema.sql | 2 +- 8 files changed, 59 insertions(+), 47 deletions(-) diff --git a/airtime_mvc/application/controllers/WebstreamController.php b/airtime_mvc/application/controllers/WebstreamController.php index 340ac0a34..0cafb690b 100644 --- a/airtime_mvc/application/controllers/WebstreamController.php +++ b/airtime_mvc/application/controllers/WebstreamController.php @@ -34,7 +34,6 @@ class WebstreamController extends Zend_Controller_Action { $request = $this->getRequest(); - $id = $request->getParam("id"); if (is_null($id)) { throw new Exception("Missing parameter 'id'"); @@ -48,10 +47,35 @@ class WebstreamController extends Zend_Controller_Action { $request = $this->getRequest(); + + $user = Application_Model_User::getCurrentUser(); + $hasPermission = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER, UTYPE_HOST)); + $id = $request->getParam("id"); + + if ($id == -1) { + $webstream = new CcWebstream(); + } else { + $webstream = CcWebstreamQuery::create()->findPK($id); + } + + if ($id != -1) { + //we are updating a playlist. Ensure that if the user is a host/dj, that he has the correct permission. + $user = Application_Model_User::getCurrentUser(); + if ($webstream->getDbCreatorId() != $user->getId()) { + header("Status: 401 Not Authorized"); + return; + } + } + + if (!$hasPermission) { + header("Status: 401 Not Authorized"); + return; + } + $analysis = Application_Model_Webstream::analyzeFormData($request); if (Application_Model_Webstream::isValid($analysis)) { - Application_Model_Webstream::save($request); + Application_Model_Webstream::save($request, $webstream); $this->view->statusMessage = "
Webstream saved.
"; } else { $this->view->statusMessage = "
Invalid form values.
"; diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php index eefdb155f..e7534bc8e 100644 --- a/airtime_mvc/application/models/StoredFile.php +++ b/airtime_mvc/application/models/StoredFile.php @@ -606,7 +606,7 @@ class Application_Model_StoredFile $plSelect[] = "PL.id AS ".$key; $blSelect[] = "BL.id AS ".$key; $fileSelect[] = $key; - $streamSelect[] = $key; + $streamSelect[] = "ws.id AS ".$key; } elseif ($key === "track_title") { $plSelect[] = "name AS ".$key; $blSelect[] = "name AS ".$key; @@ -621,7 +621,7 @@ class Application_Model_StoredFile $plSelect[] = "login AS ".$key; $blSelect[] = "login AS ".$key; $fileSelect[] = $key; - $streamSelect[] = "creator_id AS ".$key; + $streamSelect[] = "login AS ".$key; } //same columns in each table. else if (in_array($key, array("length", "utime", "mtime"))) { @@ -659,7 +659,7 @@ class Application_Model_StoredFile $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')"; - $streamTable = "({$streamSelect} FROM cc_webstream AS WEBSTREAM)"; + $streamTable = "({$streamSelect} FROM cc_webstream AS ws LEFT JOIN cc_subjs AS sub ON (sub.id = ws.creator_id))"; $unionTable = "({$plTable} UNION {$blTable} UNION {$fileTable} UNION {$streamTable}) AS RESULTS"; //choose which table we need to select data from. @@ -699,7 +699,7 @@ class Application_Model_StoredFile $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())); diff --git a/airtime_mvc/application/models/Webstream.php b/airtime_mvc/application/models/Webstream.php index cfb1f33d1..97f74666d 100644 --- a/airtime_mvc/application/models/Webstream.php +++ b/airtime_mvc/application/models/Webstream.php @@ -14,7 +14,7 @@ class Application_Model_Webstream{ $this->webstream->setDbName("Untitled Webstream"); $this->webstream->setDbDescription(""); $this->webstream->setDbUrl("http://"); - $this->webstream->setDbLength("00h 00m"); + $this->webstream->setDbLength("00:00:00"); $this->webstream->setDbName("Untitled Webstream"); } else { $this->id = $id; @@ -44,7 +44,7 @@ class Application_Model_Webstream{ if (count($arr) == 3) { list($hours, $min, $sec) = $arr; $di = new DateInterval("PT{$hours}H{$min}M{$sec}S"); - return $di->format("%Hh %im"); + return $di->format("%Hh %Im"); } return ""; } @@ -100,20 +100,6 @@ class Application_Model_Webstream{ return $leftOvers; } -/* -Array -( - [controller] => Webstream - [action] => save - [module] => default - [format] => json - [description] => desc - [url] => http:// - [length] => 00h 20m - [name] => Default -) - */ - public static function analyzeFormData($request) { @@ -173,7 +159,7 @@ Array return true; } - public static function save($request) + public static function save($request, $webstream) { $userInfo = Zend_Auth::getInstance()->getStorage()->read(); @@ -191,14 +177,7 @@ Array throw new Exception("Invalid date format: $length"); } - $id = $request->getParam("id"); - if (is_null($id)) { - $webstream = new CcWebstream(); - } else { - $webstream = CcWebstreamQuery::create()->findPK($id); - } - $webstream->setDbName($request->getParam("name")); $webstream->setDbDescription($request->getParam("description")); $webstream->setDbUrl($request->getParam("url")); diff --git a/airtime_mvc/application/models/airtime/map/CcWebstreamTableMap.php b/airtime_mvc/application/models/airtime/map/CcWebstreamTableMap.php index 1b475e675..316553581 100644 --- a/airtime_mvc/application/models/airtime/map/CcWebstreamTableMap.php +++ b/airtime_mvc/application/models/airtime/map/CcWebstreamTableMap.php @@ -43,7 +43,7 @@ class CcWebstreamTableMap extends TableMap { $this->addColumn('DESCRIPTION', 'DbDescription', 'VARCHAR', true, 255, null); $this->addColumn('URL', 'DbUrl', 'VARCHAR', true, 255, null); $this->addColumn('LENGTH', 'DbLength', 'VARCHAR', true, null, '00:00:00'); - $this->addColumn('CREATOR_ID', 'DbCreatorId', 'VARCHAR', true, 255, null); + $this->addColumn('CREATOR_ID', 'DbCreatorId', 'INTEGER', true, null, null); $this->addColumn('MTIME', 'DbMtime', 'TIMESTAMP', true, 6, null); $this->addColumn('UTIME', 'DbUtime', 'TIMESTAMP', true, 6, null); // validators diff --git a/airtime_mvc/application/models/airtime/om/BaseCcWebstream.php b/airtime_mvc/application/models/airtime/om/BaseCcWebstream.php index eccecf650..b570309dc 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcWebstream.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcWebstream.php @@ -57,7 +57,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent /** * The value for the creator_id field. - * @var string + * @var int */ protected $creator_id; @@ -166,7 +166,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent /** * Get the [creator_id] column value. * - * @return string + * @return int */ public function getDbCreatorId() { @@ -342,13 +342,13 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent /** * Set the value of [creator_id] column. * - * @param string $v new value + * @param int $v new value * @return CcWebstream The current object (for fluent API support) */ public function setDbCreatorId($v) { if ($v !== null) { - $v = (string) $v; + $v = (int) $v; } if ($this->creator_id !== $v) { @@ -498,7 +498,7 @@ abstract class BaseCcWebstream extends BaseObject implements Persistent $this->description = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null; $this->url = ($row[$startcol + 3] !== null) ? (string) $row[$startcol + 3] : null; $this->length = ($row[$startcol + 4] !== null) ? (string) $row[$startcol + 4] : null; - $this->creator_id = ($row[$startcol + 5] !== null) ? (string) $row[$startcol + 5] : null; + $this->creator_id = ($row[$startcol + 5] !== null) ? (int) $row[$startcol + 5] : null; $this->mtime = ($row[$startcol + 6] !== null) ? (string) $row[$startcol + 6] : null; $this->utime = ($row[$startcol + 7] !== null) ? (string) $row[$startcol + 7] : null; $this->resetModified(); diff --git a/airtime_mvc/application/models/airtime/om/BaseCcWebstreamQuery.php b/airtime_mvc/application/models/airtime/om/BaseCcWebstreamQuery.php index 0798a8e16..b5bf09979 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcWebstreamQuery.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcWebstreamQuery.php @@ -40,7 +40,7 @@ * @method CcWebstream findOneByDbDescription(string $description) Return the first CcWebstream filtered by the description column * @method CcWebstream findOneByDbUrl(string $url) Return the first CcWebstream filtered by the url column * @method CcWebstream findOneByDbLength(string $length) Return the first CcWebstream filtered by the length column - * @method CcWebstream findOneByDbCreatorId(string $creator_id) Return the first CcWebstream filtered by the creator_id column + * @method CcWebstream findOneByDbCreatorId(int $creator_id) Return the first CcWebstream filtered by the creator_id column * @method CcWebstream findOneByDbMtime(string $mtime) Return the first CcWebstream filtered by the mtime column * @method CcWebstream findOneByDbUtime(string $utime) Return the first CcWebstream filtered by the utime column * @@ -49,7 +49,7 @@ * @method array findByDbDescription(string $description) Return CcWebstream objects filtered by the description column * @method array findByDbUrl(string $url) Return CcWebstream objects filtered by the url column * @method array findByDbLength(string $length) Return CcWebstream objects filtered by the length column - * @method array findByDbCreatorId(string $creator_id) Return CcWebstream objects filtered by the creator_id column + * @method array findByDbCreatorId(int $creator_id) Return CcWebstream objects filtered by the creator_id column * @method array findByDbMtime(string $mtime) Return CcWebstream objects filtered by the mtime column * @method array findByDbUtime(string $utime) Return CcWebstream objects filtered by the utime column * @@ -269,20 +269,29 @@ abstract class BaseCcWebstreamQuery extends ModelCriteria /** * Filter the query on the creator_id column * - * @param string $dbCreatorId The value to use as filter. - * Accepts wildcards (* and % trigger a LIKE) + * @param int|array $dbCreatorId 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 CcWebstreamQuery The current query, for fluid interface */ public function filterByDbCreatorId($dbCreatorId = null, $comparison = null) { - if (null === $comparison) { - if (is_array($dbCreatorId)) { + if (is_array($dbCreatorId)) { + $useMinMax = false; + if (isset($dbCreatorId['min'])) { + $this->addUsingAlias(CcWebstreamPeer::CREATOR_ID, $dbCreatorId['min'], Criteria::GREATER_EQUAL); + $useMinMax = true; + } + if (isset($dbCreatorId['max'])) { + $this->addUsingAlias(CcWebstreamPeer::CREATOR_ID, $dbCreatorId['max'], Criteria::LESS_EQUAL); + $useMinMax = true; + } + if ($useMinMax) { + return $this; + } + if (null === $comparison) { $comparison = Criteria::IN; - } elseif (preg_match('/[\%\*]/', $dbCreatorId)) { - $dbCreatorId = str_replace('*', '%', $dbCreatorId); - $comparison = Criteria::LIKE; } } return $this->addUsingAlias(CcWebstreamPeer::CREATOR_ID, $dbCreatorId, $comparison); diff --git a/airtime_mvc/build/schema.xml b/airtime_mvc/build/schema.xml index 95f8329ae..f44043bd1 100644 --- a/airtime_mvc/build/schema.xml +++ b/airtime_mvc/build/schema.xml @@ -419,7 +419,7 @@ - + diff --git a/airtime_mvc/build/sql/schema.sql b/airtime_mvc/build/sql/schema.sql index 493f805e0..c8d488f97 100644 --- a/airtime_mvc/build/sql/schema.sql +++ b/airtime_mvc/build/sql/schema.sql @@ -635,7 +635,7 @@ CREATE TABLE "cc_webstream" "description" VARCHAR(255) NOT NULL, "url" VARCHAR(255) NOT NULL, "length" interval default '00:00:00' NOT NULL, - "creator_id" VARCHAR(255) NOT NULL, + "creator_id" INTEGER NOT NULL, "mtime" TIMESTAMP(6) NOT NULL, "utime" TIMESTAMP(6) NOT NULL, PRIMARY KEY ("id")