public function createAction() { if (!$this -> _helper -> requireAuth() -> setAuthParams('ynvideo_playlist', null, 'create') -> isValid()) { return; } $this -> view -> form = $form = new Ynvideo_Form_Playlist_Create(); $this -> view -> playlist_id = $this -> _getParam('playlist_id', '0'); // Check method/data if (!$this -> getRequest() -> isPost()) { return; } if (!$form -> isValid($this -> getRequest() -> getPost())) { return; } $viewer = $this -> view -> viewer; // Process saving the new playlist $values = $form -> getValues(); $values['user_id'] = $viewer -> getIdentity(); $playlistTable = Engine_Api::_() -> getDbtable('playlists', 'ynvideo'); $db = $playlistTable -> getAdapter(); $db -> beginTransaction(); try { $playlist = $playlistTable -> createRow(); $playlist -> setFromArray($values); $playlist -> save(); if (!empty($values['photo'])) { try { $playlist -> setPhoto($form -> photo); } catch (Engine_Image_Adapter_Exception $e) { Zend_Registry::get('Zend_Log') -> log($e -> __toString(), Zend_Log::WARN); } } // Auth $auth = Engine_Api::_() -> authorization() -> context; if (empty($values['auth_view'])) { $values['auth_view'] = 'everyone'; } if (empty($values['auth_comment'])) { $values['auth_comment'] = 'everyone'; } $viewMax = array_search($values['auth_view'], $this -> _roles); $commentMax = array_search($values['auth_comment'], $this -> _roles); foreach ($this->_roles as $i => $role) { $auth -> setAllowed($playlist, $role, 'view', ($i <= $viewMax)); $auth -> setAllowed($playlist, $role, 'comment', ($i <= $commentMax)); } $db -> commit(); } catch (Exception $e) { $db -> rollback(); throw $e; } // add activity feed for creating a new playlist $db -> beginTransaction(); try { $action = Engine_Api::_() -> getDbtable('actions', 'activity') -> addActivity($viewer, $playlist, 'ynvideo_playlist_new'); if ($action != null) { Engine_Api::_() -> getDbtable('actions', 'activity') -> attachActivity($action, $playlist); } // Rebuild privacy $actionTable = Engine_Api::_() -> getDbtable('actions', 'activity'); foreach ($actionTable->getActionsByObject($playlist) as $action) { $actionTable -> resetActivityBindings($action); } $db -> commit(); } catch (Exception $e) { $db -> rollBack(); throw $e; } return $this -> _helper -> redirector -> gotoRoute(array(), 'video_playlist', true); }
public function init() { parent::init(); $this->submit->setLabel('Save changes'); }