SAAS-1063: REST API for podcasts
Hierarchy routing is working Basic implentation of podcast INDEX and POST actions done
This commit is contained in:
parent
a444751397
commit
67db2c1d25
9 changed files with 391 additions and 9 deletions
|
@ -1,18 +1,77 @@
|
|||
<?php
|
||||
|
||||
class PodcastLimitReachedException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
class InvalidPodcastException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Skeleton subclass for representing a row from the 'podcast' table.
|
||||
*
|
||||
*
|
||||
*
|
||||
* You should add additional methods to this class to meet the
|
||||
* application requirements. This class will only be generated as
|
||||
* long as it does not already exist in the output directory.
|
||||
*
|
||||
* @package propel.generator.airtime
|
||||
*/
|
||||
class Podcast extends BasePodcast
|
||||
{
|
||||
/** Creates a Podcast object from an array containing metadata.
|
||||
* This is used by our Podcast REST API
|
||||
* @param $podcastArray An array containing metadata for a Podcast object.
|
||||
*
|
||||
* @return Podcast Array
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function create($podcastArray)
|
||||
{
|
||||
if (Application_Service_PodcastService::podcastLimitReached()) {
|
||||
throw new PodcastLimitReachedException();
|
||||
}
|
||||
|
||||
// TODO are we implementing this here??
|
||||
if (!Application_Service_PodcastService::validatePodcastUrl($podcastArray["url"])) {
|
||||
throw new InvalidPodcastException();
|
||||
}
|
||||
|
||||
try {
|
||||
$podcast = new Podcast();
|
||||
$podcast->fromArray($podcastArray, BasePeer::TYPE_FIELDNAME);
|
||||
$podcast->setDbOwner(self::getOwnerId());
|
||||
$podcast->setDbType(IMPORTED_PODCAST);
|
||||
$podcast->save();
|
||||
|
||||
//TODO: fetch podcast episodes and return with podcast object
|
||||
|
||||
return $podcast->toArray(BasePeer::TYPE_FIELDNAME);
|
||||
} catch(Exception $e) {
|
||||
$podcast->delete();
|
||||
throw $e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//TODO move this somewhere where it makes sense
|
||||
private static function getOwnerId()
|
||||
{
|
||||
try {
|
||||
if (Zend_Auth::getInstance()->hasIdentity()) {
|
||||
$service_user = new Application_Service_UserService();
|
||||
return $service_user->getCurrentUser()->getDbId();
|
||||
} else {
|
||||
$defaultOwner = CcSubjsQuery::create()
|
||||
->filterByDbType('A')
|
||||
->orderByDbId()
|
||||
->findOne();
|
||||
if (!$defaultOwner) {
|
||||
// what to do if there is no admin user?
|
||||
// should we handle this case?
|
||||
return null;
|
||||
}
|
||||
return $defaultOwner->getDbId();
|
||||
}
|
||||
} catch(Exception $e) {
|
||||
Logging::info($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue