123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <?php
- class WebstreamController extends Zend_Controller_Action
- {
- public function init()
- {
- $ajaxContext = $this->_helper->getHelper('AjaxContext');
- $ajaxContext->addActionContext('new', 'json')
- ->addActionContext('save', 'json')
- ->addActionContext('edit', 'json')
- ->addActionContext('delete', 'json')
- ->initContext();
- }
- public function newAction()
- {
- $userInfo = Zend_Auth::getInstance()->getStorage()->read();
- if (!$this->isAuthorized(-1)) {
-
- header("Status: 401 Not Authorized");
- return;
- }
- $webstream = new CcWebstream();
-
- $webstream->setDbId(-1);
- $webstream->setDbName(_("Untitled Webstream"));
- $webstream->setDbDescription("");
- $webstream->setDbUrl("http://");
- $webstream->setDbLength("00:30:00");
- $webstream->setDbName(_("Untitled Webstream"));
- $webstream->setDbCreatorId($userInfo->id);
- $webstream->setDbUtime(new DateTime("now", new DateTimeZone('UTC')));
- $webstream->setDbMtime(new DateTime("now", new DateTimeZone('UTC')));
-
- Application_Model_Library::changePlaylist(null, null);
- $this->view->obj = new Application_Model_Webstream($webstream);
- $this->view->action = "new";
- $this->view->html = $this->view->render('webstream/webstream.phtml');
- }
- public function editAction()
- {
- $request = $this->getRequest();
- $id = $request->getParam("id");
- if (is_null($id)) {
- throw new Exception("Missing parameter 'id'");
- }
- $webstream = CcWebstreamQuery::create()->findPK($id);
- if ($webstream) {
- Application_Model_Library::changePlaylist($id, "stream");
- }
- $this->view->obj = new Application_Model_Webstream($webstream);
- $this->view->action = "edit";
- $this->view->html = $this->view->render('webstream/webstream.phtml');
- }
- public function deleteAction()
- {
- $request = $this->getRequest();
- $id = $request->getParam("ids");
- if (!$this->isAuthorized($id)) {
- header("Status: 401 Not Authorized");
- return;
- }
- $type = "stream";
- Application_Model_Library::changePlaylist(null, $type);
- $webstream = CcWebstreamQuery::create()->findPK($id)->delete();
- $this->view->obj = null;
- $this->view->action = "delete";
- $this->view->html = $this->view->render('webstream/webstream.phtml');
- }
-
- public function isAuthorized($webstream_id)
- {
- $user = Application_Model_User::getCurrentUser();
- if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
- return true;
- }
- if ($user->isHost()) {
-
- if ($webstream_id != -1) {
- $webstream = CcWebstreamQuery::create()->findPK($webstream_id);
-
- $user = Application_Model_User::getCurrentUser();
-
- return $webstream->getDbCreatorId() == $user->getId();
- }
-
- return true;
- } else {
- Logging::info( $user );
- }
- return false;
- }
- public function saveAction()
- {
- $request = $this->getRequest();
- $id = $request->getParam("id");
- $parameters = array();
- foreach (array('id','length','name','description','url') as $p) {
- $parameters[$p] = trim($request->getParam($p));
- }
- if (!$this->isAuthorized($id)) {
- header("Status: 401 Not Authorized");
- return;
- }
- list($analysis, $mime, $mediaUrl, $di) = Application_Model_Webstream::analyzeFormData($parameters);
- try {
- if (Application_Model_Webstream::isValid($analysis)) {
- $streamId = Application_Model_Webstream::save($parameters, $mime, $mediaUrl, $di);
- Application_Model_Library::changePlaylist($streamId, "stream");
- $this->view->statusMessage = "<div class='success'>"._("Webstream saved.")."</div>";
- $this->view->streamId = $streamId;
- $this->view->length = $di->format("%Hh %Im");
- } else {
- throw new Exception("isValid returned false");
- }
- } catch (Exception $e) {
- Logging::debug($e->getMessage());
- $this->view->statusMessage = "<div class='errors'>"._("Invalid form values.")."</div>";
- $this->view->streamId = -1;
- $this->view->analysis = $analysis;
- }
- }
- }
|