SAAS-1062 - Podcast skeleton work; slight rework to backend functionality
This commit is contained in:
parent
6934bcfdab
commit
6de6e2767c
6 changed files with 140 additions and 14 deletions
20
airtime_mvc/application/controllers/RenderController.php
Normal file
20
airtime_mvc/application/controllers/RenderController.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
class RenderController extends Zend_Controller_Action {
|
||||
|
||||
public function init() {
|
||||
$this->view->layout()->disableLayout();
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
|
||||
$csrf_namespace = new Zend_Session_Namespace('csrf_namespace');
|
||||
$csrf_element = new Zend_Form_Element_Hidden('csrf_token');
|
||||
$csrf_element->setValue($csrf_namespace->authtoken)->setRequired('true')->removeDecorator('HtmlTag')->removeDecorator('Label');
|
||||
$this->view->csrf = $csrf_element;
|
||||
}
|
||||
|
||||
public function podcastUrlDialogAction() {
|
||||
$path = 'podcast/podcast_url_dialog.phtml';
|
||||
$this->_helper->json->sendJson(array("html"=>$this->view->render($path)));
|
||||
}
|
||||
|
||||
}
|
|
@ -226,7 +226,6 @@ class Zend_Controller_Plugin_Acl extends Zend_Controller_Plugin_Abstract
|
|||
$current_namespace = new Zend_Session_Namespace('csrf_namespace');
|
||||
$observed_csrf_token = $token;
|
||||
$expected_csrf_token = $current_namespace->authtoken;
|
||||
|
||||
return ($observed_csrf_token == $expected_csrf_token);
|
||||
}
|
||||
|
||||
|
|
|
@ -51,20 +51,28 @@ class Podcast extends BasePodcast
|
|||
}
|
||||
|
||||
try {
|
||||
// Kind of a pain; since the rss fields are SimpleXMLElements,
|
||||
// we need to explicitly cast them to strings
|
||||
$podcast = new Podcast();
|
||||
$podcast->setDbUrl($podcastArray["url"]);
|
||||
$podcast->setDbTitle($rss->title);
|
||||
$podcast->setDbCreator($rss->author);
|
||||
$podcast->setDbDescription($rss->description);
|
||||
$podcast->setDbTitle((string)$rss->title);
|
||||
$podcast->setDbCreator((string)$rss->author);
|
||||
$podcast->setDbDescription((string)$rss->description);
|
||||
$podcast->setDbOwner(self::getOwnerId());
|
||||
$podcast->setDbType(IMPORTED_PODCAST);
|
||||
$podcast->save();
|
||||
|
||||
$podcastArray = array();
|
||||
array_push($podcastArray, $podcast->toArray(BasePeer::TYPE_FIELDNAME));
|
||||
// $podcastArray = array();
|
||||
// array_push($podcastArray, $podcast->toArray(BasePeer::TYPE_FIELDNAME));
|
||||
|
||||
$podcastArray = $podcast->toArray(BasePeer::TYPE_FIELDNAME);
|
||||
|
||||
$podcastArray["episodes"] = array();
|
||||
foreach ($rss->item as $item) {
|
||||
// Same as above, we need to explicitly cast the SimpleXMLElement 'array' into an actual array
|
||||
foreach($item as $k => $v) {
|
||||
$array[$k] = (string)$v;
|
||||
}
|
||||
array_push($podcastArray["episodes"], $item);
|
||||
}
|
||||
return $podcastArray;
|
||||
|
@ -96,11 +104,15 @@ class Podcast extends BasePodcast
|
|||
throw new PodcastNotFoundException();
|
||||
}
|
||||
|
||||
$podcastArray = array();
|
||||
array_push($podcastArray, $podcast->toArray(BasePeer::TYPE_FIELDNAME));
|
||||
// FIXME: Get rid of this duplication and move into a new function (serializer/deserializer)
|
||||
$podcastArray = $podcast->toArray(BasePeer::TYPE_FIELDNAME);
|
||||
|
||||
$podcastArray["episodes"] = array();
|
||||
foreach ($rss->item as $item) {
|
||||
// Same as above, we need to explicitly cast the SimpleXMLElement 'array' into an actual array
|
||||
foreach($item as $k => $v) {
|
||||
$array[$k] = (string)$v;
|
||||
}
|
||||
array_push($podcastArray["episodes"], $item);
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,16 @@ class Rest_Bootstrap extends Zend_Application_Module_Bootstrap
|
|||
'rest'=> array('media', 'show-image', 'podcast', 'podcast-episodes')));
|
||||
assert($router->addRoute('rest', $restRoute));
|
||||
|
||||
$podcastBulkRoute = new Zend_Controller_Router_Route(
|
||||
'rest/podcast/bulk',
|
||||
array(
|
||||
'controller' => 'podcast',
|
||||
'action' => 'bulk',
|
||||
'module' => 'rest'
|
||||
)
|
||||
);
|
||||
$router->addRoute('podcast-bulk', $podcastBulkRoute);
|
||||
|
||||
$route = new Rest_RouteController($front,
|
||||
'rest/podcast/:id/episodes',
|
||||
array(
|
||||
|
@ -38,7 +48,6 @@ class Rest_Bootstrap extends Zend_Application_Module_Bootstrap
|
|||
);
|
||||
$router->addRoute('podcast-episodes', $route);
|
||||
|
||||
|
||||
/** MediaController Routes **/
|
||||
$downloadRoute = new Zend_Controller_Router_Route(
|
||||
'rest/media/:id/download',
|
||||
|
|
|
@ -8,6 +8,7 @@ class Rest_PodcastController extends Zend_Rest_Controller
|
|||
|
||||
// Remove reliance on .phtml files to render requests
|
||||
$this->_helper->viewRenderer->setNoRender(true);
|
||||
$this->view->setScriptPath(APPLICATION_PATH . 'views/scripts/');
|
||||
}
|
||||
|
||||
public function indexAction()
|
||||
|
@ -73,12 +74,23 @@ class Rest_PodcastController extends Zend_Rest_Controller
|
|||
}
|
||||
|
||||
try {
|
||||
$requestData = json_decode($this->getRequest()->getRawBody(), true);
|
||||
// $requestData = json_decode($this->getRequest()->getRawBody(), true);
|
||||
$requestData = $this->getRequest()->getPost();
|
||||
$podcast = Podcast::create($requestData);
|
||||
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(201)
|
||||
->appendBody(json_encode($podcast));
|
||||
$path = 'podcast/podcast.phtml';
|
||||
$this->view->podcast = $podcast;
|
||||
$this->_helper->json->sendJson(array(
|
||||
"podcast"=>json_encode($podcast),
|
||||
"html"=>$this->view->render($path),
|
||||
"type"=>"podcast", // TODO: get rid of these extraneous fields
|
||||
"id"=>$podcast["id"]
|
||||
// "id"=>$podcast->getDbId()
|
||||
));
|
||||
|
||||
// $this->getResponse()
|
||||
// ->setHttpResponseCode(201)
|
||||
// ->appendBody(json_encode($podcast));
|
||||
}
|
||||
catch (PodcastLimitReachedException $e) {
|
||||
$this->getResponse()
|
||||
|
@ -145,6 +157,46 @@ class Rest_PodcastController extends Zend_Rest_Controller
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint for performing bulk actions (deleting multiple podcasts, opening multiple editors)
|
||||
*/
|
||||
public function bulkAction() {
|
||||
if ($this->_request->getMethod() != "POST") {
|
||||
$this->getResponse()
|
||||
->setHttpResponseCode(405)
|
||||
->appendBody("ERROR: Method not accepted");
|
||||
return;
|
||||
}
|
||||
|
||||
$ids = $this->_getParam('ids', []);
|
||||
$method = $this->_getParam('method', 'GET');
|
||||
$path = 'podcast/podcast.phtml';
|
||||
$responseBody = [];
|
||||
|
||||
switch($method) {
|
||||
case "DELETE":
|
||||
foreach($ids as $id) {
|
||||
Podcast::deleteById($id);
|
||||
$responseBody = "Success"; // TODO
|
||||
}
|
||||
break;
|
||||
case "GET":
|
||||
foreach($ids as $id) {
|
||||
$podcast = Podcast::getPodcastById($id);
|
||||
$responseBody[] = array(
|
||||
"podcast"=>json_encode($podcast),
|
||||
"html"=>$this->view->render($path),
|
||||
"type"=>"podcast", // TODO: get rid of these extraneous fields
|
||||
"id"=>$podcast["id"]
|
||||
// "id"=>$podcast->getDbId()
|
||||
);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
$this->_helper->json->sendJson($responseBody);
|
||||
}
|
||||
|
||||
private function getId()
|
||||
{
|
||||
if (!$id = $this->_getParam('id', false)) {
|
||||
|
|
34
airtime_mvc/application/views/scripts/podcast/podcast.phtml
Normal file
34
airtime_mvc/application/views/scripts/podcast/podcast.phtml
Normal file
|
@ -0,0 +1,34 @@
|
|||
<div id="podcast-wrapper" ng-controller="RestController">
|
||||
<div class="inner_editor_title">
|
||||
<h2>
|
||||
<?php echo _("Editing ") ?>"<span ng-bind="podcast.title" class="title_obj_name"></span>"
|
||||
</h2>
|
||||
</div>
|
||||
<div class="inner_editor_wrapper">
|
||||
<input ng-value="podcast.id" class="obj_id" type="hidden"/>
|
||||
<label>
|
||||
<?php echo _("Podcast Name") ?>
|
||||
<input disabled ng-model="podcast.title" type="text"/>
|
||||
</label>
|
||||
<label>
|
||||
<?php echo _("Podcast URL") ?>
|
||||
<input disabled ng-model="podcast.url" type="text"/>
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<table class="podcast_episodes datatable" cellpadding="0" cellspacing="0"></table>
|
||||
|
||||
<div class="btn-toolbar clearfix">
|
||||
<div class="btn-group pull-right">
|
||||
<button ng-click="discard()" class="btn" type="button" name="cancel">
|
||||
<?php echo _("Cancel") ?>
|
||||
</button>
|
||||
</div>
|
||||
<div class='btn-group pull-right'>
|
||||
<button ng-click="put()" class="btn" title='<?php echo _("Save podcast") ?>' type="button">
|
||||
<?php echo _("Save") ?>
|
||||
</button>
|
||||
</div>
|
||||
<div id='sp-success' class='success' style='display:none'></span></div>
|
||||
</div>
|
||||
</div>
|
Loading…
Add table
Add a link
Reference in a new issue