Example #1
0
 public function contextMenuAction()
 {
     $id = $this->_getParam('id');
     $type = $this->_getParam('type');
     //playlist||timeline
     $screen = $this->_getParam('screen');
     $request = $this->getRequest();
     $baseUrl = $request->getBaseUrl();
     $menu = array();
     $userInfo = Zend_Auth::getInstance()->getStorage()->read();
     $user = new Application_Model_User($userInfo->id);
     //Open a jPlayer window and play the audio clip.
     $menu["play"] = array("name" => "Preview", "icon" => "play", "disabled" => false);
     $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
     $obj_sess = new Zend_Session_Namespace(UI_PLAYLISTCONTROLLER_OBJ_SESSNAME);
     if ($type === "audioclip") {
         $file = Application_Model_StoredFile::Recall($id);
         $menu["play"]["mime"] = $file->getPropelOrm()->getDbMime();
         if (isset($obj_sess->id) && $screen == "playlist") {
             // if the user is not admin or pm, check the creator and see if this person owns the playlist or Block
             if ($obj_sess->type == 'playlist') {
                 $obj = new Application_Model_Playlist($obj_sess->id);
             } elseif ($obj_sess->type == 'block') {
                 $obj = new Application_Model_Block($obj_sess->id);
             }
             if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
                 if ($obj_sess->type === "playlist") {
                     $menu["pl_add"] = array("name" => "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
                 } elseif ($obj_sess->type === "block") {
                     $menu["pl_add"] = array("name" => "Add to Smart Block", "icon" => "add-playlist", "icon" => "copy");
                 }
             }
         }
         if ($isAdminOrPM) {
             $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/library/delete");
             $menu["edit"] = array("name" => "Edit Metadata", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}");
         }
         $url = $file->getRelativeFileUrl($baseUrl) . '/download/true';
         $menu["download"] = array("name" => "Download", "icon" => "download", "url" => $url);
     } elseif ($type === "playlist" || $type === "block") {
         if ($type === 'playlist') {
             $obj = new Application_Model_Playlist($id);
         } elseif ($type === 'block') {
             $obj = new Application_Model_Block($id);
             if (!$obj->isStatic()) {
                 unset($menu["play"]);
             }
             if (($isAdminOrPM || $obj->getCreatorId() == $user->getId()) && $screen == "playlist") {
                 if ($obj_sess->type === "playlist") {
                     $menu["pl_add"] = array("name" => "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
                 }
             }
         }
         if ($obj_sess->id !== $id && $screen == "playlist") {
             if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
                 $menu["edit"] = array("name" => "Edit", "icon" => "edit");
             }
         }
         if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
             $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/library/delete");
         }
     } elseif ($type == "stream") {
         $webstream = CcWebstreamQuery::create()->findPK($id);
         $obj = new Application_Model_Webstream($webstream);
         if (isset($obj_sess->id) && $screen == "playlist") {
             if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
                 if ($obj_sess->type === "playlist") {
                     $menu["pl_add"] = array("name" => "Add to Playlist", "icon" => "add-playlist", "icon" => "copy");
                 }
             }
         }
         if ($isAdminOrPM || $obj->getCreatorId() == $user->getId()) {
             if ($screen == "playlist") {
                 $menu["edit"] = array("name" => "Edit", "icon" => "edit", "url" => "/library/edit-file-md/id/{$id}");
             }
             $menu["del"] = array("name" => "Delete", "icon" => "delete", "url" => "/library/delete");
         }
     }
     //SOUNDCLOUD MENU OPTIONS
     if ($type === "audioclip" && Application_Model_Preference::GetUploadToSoundcloudOption()) {
         //create a menu separator
         $menu["sep1"] = "-----------";
         //create a sub menu for Soundcloud actions.
         $menu["soundcloud"] = array("name" => "Soundcloud", "icon" => "soundcloud", "items" => array());
         $scid = $file->getSoundCloudId();
         if ($scid > 0) {
             $url = $file->getSoundCloudLinkToFile();
             $menu["soundcloud"]["items"]["view"] = array("name" => "View on Soundcloud", "icon" => "soundcloud", "url" => $url);
         }
         if (!is_null($scid)) {
             $text = "Re-upload to SoundCloud";
         } else {
             $text = "Upload to SoundCloud";
         }
         $menu["soundcloud"]["items"]["upload"] = array("name" => $text, "icon" => "soundcloud", "url" => "/library/upload-file-soundcloud/id/{$id}");
     }
     if (empty($menu)) {
         $menu["noaction"] = array("name" => "No action available");
     }
     $this->view->items = $menu;
 }