ScheduleController.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. <?php
  2. class ScheduleController extends Zend_Controller_Action
  3. {
  4. protected $sched_sess = null;
  5. public function init()
  6. {
  7. $ajaxContext = $this->_helper->getHelper('AjaxContext');
  8. $ajaxContext->addActionContext('event-feed', 'json')
  9. ->addActionContext('event-feed-preload', 'json')
  10. ->addActionContext('make-context-menu', 'json')
  11. ->addActionContext('add-show-dialog', 'json')
  12. ->addActionContext('add-show', 'json')
  13. ->addActionContext('edit-show', 'json')
  14. ->addActionContext('move-show', 'json')
  15. ->addActionContext('resize-show', 'json')
  16. ->addActionContext('delete-show-instance', 'json')
  17. ->addActionContext('show-content-dialog', 'json')
  18. ->addActionContext('clear-show', 'json')
  19. ->addActionContext('get-current-playlist', 'json')
  20. ->addActionContext('remove-group', 'json')
  21. ->addActionContext('populate-show-form', 'json')
  22. ->addActionContext('populate-repeating-show-instance-form', 'json')
  23. ->addActionContext('delete-show', 'json')
  24. ->addActionContext('cancel-current-show', 'json')
  25. ->addActionContext('get-form', 'json')
  26. ->addActionContext('upload-to-sound-cloud', 'json')
  27. ->addActionContext('content-context-menu', 'json')
  28. ->addActionContext('set-time-scale', 'json')
  29. ->addActionContext('set-time-interval', 'json')
  30. ->addActionContext('edit-repeating-show-instance', 'json')
  31. ->addActionContext('dj-edit-show', 'json')
  32. ->addActionContext('calculate-duration', 'json')
  33. ->addActionContext('get-current-show', 'json')
  34. ->addActionContext('update-future-is-scheduled', 'json')
  35. ->addActionContext('localize-start-end-time', 'json')
  36. ->initContext();
  37. $this->sched_sess = new Zend_Session_Namespace("schedule");
  38. }
  39. public function indexAction()
  40. {
  41. $CC_CONFIG = Config::getConfig();
  42. $baseUrl = Application_Common_OsPath::getBaseDir();
  43. $this->view->headScript()->appendScript(
  44. "var calendarPref = {};\n".
  45. "calendarPref.weekStart = ".Application_Model_Preference::GetWeekStartDay().";\n".
  46. "calendarPref.timestamp = ".time().";\n".
  47. "calendarPref.timezoneOffset = ".Application_Common_DateHelper::getUserTimezoneOffset().";\n".
  48. "calendarPref.timeScale = '".Application_Model_Preference::GetCalendarTimeScale()."';\n".
  49. "calendarPref.timeInterval = ".Application_Model_Preference::GetCalendarTimeInterval().";\n".
  50. "calendarPref.weekStartDay = ".Application_Model_Preference::GetWeekStartDay().";\n".
  51. "var calendarEvents = null;"
  52. );
  53. $this->view->headScript()->appendFile($baseUrl.'js/contextmenu/jquery.contextMenu.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  54. //full-calendar-functions.js requires this variable, so that datePicker widget can be offset to server time instead of client time
  55. //this should be as a default, however with our new drop down timezone changing for shows, we should reset this offset then??
  56. $this->view->headScript()->appendScript("var timezoneOffset = ".Application_Common_DateHelper::getStationTimezoneOffset()."; //in seconds");
  57. //set offset to ensure it loads last
  58. $this->view->headScript()->offsetSetFile(90, $baseUrl.'js/airtime/schedule/full-calendar-functions.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  59. $this->view->headScript()->appendFile($baseUrl.'js/fullcalendar/fullcalendar.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  60. $this->view->headScript()->appendFile($baseUrl.'js/timepicker/jquery.ui.timepicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  61. $this->view->headScript()->appendFile($baseUrl.'js/colorpicker/js/colorpicker.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  62. $this->view->headScript()->appendFile($baseUrl.'js/airtime/schedule/add-show.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  63. $this->view->headScript()->offsetSetFile(100, $baseUrl.'js/airtime/schedule/schedule.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  64. $this->view->headScript()->appendFile($baseUrl.'js/blockui/jquery.blockUI.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  65. $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.ui.timepicker.css?'.$CC_CONFIG['airtime_version']);
  66. $this->view->headLink()->appendStylesheet($baseUrl.'css/fullcalendar.css?'.$CC_CONFIG['airtime_version']);
  67. $this->view->headLink()->appendStylesheet($baseUrl.'css/colorpicker/css/colorpicker.css?'.$CC_CONFIG['airtime_version']);
  68. $this->view->headLink()->appendStylesheet($baseUrl.'css/add-show.css?'.$CC_CONFIG['airtime_version']);
  69. $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.contextMenu.css?'.$CC_CONFIG['airtime_version']);
  70. //Start Show builder JS/CSS requirements
  71. $this->view->headScript()->appendFile($baseUrl.'js/datatables/js/jquery.dataTables.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  72. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.pluginAPI.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  73. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.fnSetFilteringDelay.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  74. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.ColVis.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  75. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.ColReorder.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  76. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.FixedColumns.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  77. $this->view->headScript()->appendFile($baseUrl.'js/datatables/plugin/dataTables.columnFilter.js?'.$CC_CONFIG['airtime_version'], 'text/javascript');
  78. $this->view->headScript()->appendFile($baseUrl.'js/airtime/buttons/buttons.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  79. $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/events/library_showbuilder.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  80. $this->view->headScript()->appendFile($baseUrl.'js/airtime/library/library.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  81. $this->view->headScript()->appendFile($baseUrl.'js/airtime/showbuilder/builder.js?'.$CC_CONFIG['airtime_version'],'text/javascript');
  82. $this->view->headLink()->appendStylesheet($baseUrl.'css/media_library.css?'.$CC_CONFIG['airtime_version']);
  83. $this->view->headLink()->appendStylesheet($baseUrl.'css/jquery.contextMenu.css?'.$CC_CONFIG['airtime_version']);
  84. $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/ColVis.css?'.$CC_CONFIG['airtime_version']);
  85. $this->view->headLink()->appendStylesheet($baseUrl.'css/datatables/css/ColReorder.css?'.$CC_CONFIG['airtime_version']);
  86. $this->view->headLink()->appendStylesheet($baseUrl.'css/showbuilder.css?'.$CC_CONFIG['airtime_version']);
  87. //End Show builder JS/CSS requirements
  88. $this->createShowFormAction(true);
  89. $user = Application_Model_User::getCurrentUser();
  90. if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
  91. $this->view->preloadShowForm = true;
  92. }
  93. $this->view->addNewShow = true;
  94. }
  95. public function eventFeedAction()
  96. {
  97. $service_user = new Application_Service_UserService();
  98. $currentUser = $service_user->getCurrentUser();
  99. $userTimezone = new DateTimeZone(Application_Model_Preference::GetUserTimezone());
  100. $start = new DateTime($this->_getParam('start', null), $userTimezone);
  101. $start->setTimezone(new DateTimeZone("UTC"));
  102. $end = new DateTime($this->_getParam('end', null), $userTimezone);
  103. $end->setTimezone(new DateTimeZone("UTC"));
  104. $events = &Application_Model_Show::getFullCalendarEvents($start, $end,
  105. $currentUser->isAdminOrPM());
  106. $this->view->events = $events;
  107. }
  108. public function eventFeedPreloadAction()
  109. {
  110. $userInfo = Zend_Auth::getInstance()->getStorage()->read();
  111. $user = new Application_Model_User($userInfo->id);
  112. $editable = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
  113. $calendar_interval = Application_Model_Preference::GetCalendarTimeScale();
  114. if ($calendar_interval == "agendaDay") {
  115. list($start, $end) = Application_Model_Show::getStartEndCurrentDayView();
  116. } else if ($calendar_interval == "agendaWeek") {
  117. list($start, $end) = Application_Model_Show::getStartEndCurrentWeekView();
  118. } else if ($calendar_interval == "month") {
  119. list($start, $end) = Application_Model_Show::getStartEndCurrentMonthView();
  120. } else {
  121. Logging::error("Invalid Calendar Interval '$calendar_interval'");
  122. }
  123. $events = &Application_Model_Show::getFullCalendarEvents($start, $end, $editable);
  124. $this->view->events = $events;
  125. }
  126. public function getCurrentShowAction()
  127. {
  128. $currentShow = Application_Model_Show::getCurrentShow();
  129. if (!empty($currentShow)) {
  130. $this->view->si_id = $currentShow[0]["instance_id"];
  131. $this->view->current_show = true;
  132. } else {
  133. $this->view->current_show = false;
  134. }
  135. }
  136. public function moveShowAction()
  137. {
  138. $deltaDay = $this->_getParam('day');
  139. $deltaMin = $this->_getParam('min');
  140. try {
  141. $service_calendar = new Application_Service_CalendarService(
  142. $this->_getParam('showInstanceId'));
  143. } catch (Exception $e) {
  144. $this->view->show_error = true;
  145. return false;
  146. }
  147. $error = $service_calendar->moveShow($deltaDay, $deltaMin);
  148. if (isset($error)) {
  149. $this->view->error = $error;
  150. }
  151. }
  152. public function resizeShowAction()
  153. {
  154. $deltaDay = $this->_getParam('day');
  155. $deltaMin = $this->_getParam('min');
  156. $showId = $this->_getParam('showId');
  157. $instanceId = $this->_getParam('instanceId');
  158. $userInfo = Zend_Auth::getInstance()->getStorage()->read();
  159. $user = new Application_Model_User($userInfo->id);
  160. if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
  161. try {
  162. $show = new Application_Model_Show($showId);
  163. } catch (Exception $e) {
  164. $this->view->show_error = true;
  165. return false;
  166. }
  167. $error = $show->resizeShow($deltaDay, $deltaMin, $instanceId);
  168. }
  169. if (isset($error)) {
  170. $this->view->error = $error;
  171. }
  172. }
  173. public function deleteShowInstanceAction()
  174. {
  175. $instanceId = $this->_getParam('id');
  176. $service_show = new Application_Service_ShowService();
  177. $showId = $service_show->deleteShow($instanceId, true);
  178. if (!$showId) {
  179. $this->view->show_error = true;
  180. }
  181. $this->view->show_id = $showId;
  182. }
  183. public function uploadToSoundCloudAction()
  184. {
  185. $show_instance = $this->_getParam('id');
  186. try {
  187. $show_inst = new Application_Model_ShowInstance($show_instance);
  188. } catch (Exception $e) {
  189. $this->view->show_error = true;
  190. return false;
  191. }
  192. $file = $show_inst->getRecordedFile();
  193. $id = $file->getId();
  194. Application_Model_Soundcloud::uploadSoundcloud($id);
  195. // we should die with ui info
  196. $this->_helper->json->sendJson(null);
  197. }
  198. public function makeContextMenuAction()
  199. {
  200. $instanceId = $this->_getParam('instanceId');
  201. $service_calendar = new Application_Service_CalendarService($instanceId);
  202. $this->view->items = $service_calendar->makeContextMenu();
  203. }
  204. public function clearShowAction()
  205. {
  206. $instanceId = $this->_getParam('id');
  207. $service_scheduler = new Application_Service_SchedulerService();
  208. if (!$service_scheduler->emptyShowContent($instanceId)) {
  209. $this->view->show_error = true;
  210. return false;
  211. }
  212. }
  213. public function getCurrentPlaylistAction()
  214. {
  215. $range = Application_Model_Schedule::GetPlayOrderRangeOld();
  216. $show = Application_Model_Show::getCurrentShow();
  217. /* Convert all UTC times to localtime before sending back to user. */
  218. $range["schedulerTime"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["schedulerTime"]);
  219. if (isset($range["previous"])) {
  220. $range["previous"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["previous"]["starts"]);
  221. $range["previous"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["previous"]["ends"]);
  222. }
  223. if (isset($range["current"])) {
  224. $range["current"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["current"]["starts"]);
  225. $range["current"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["current"]["ends"]);
  226. }
  227. if (isset($range["next"])) {
  228. $range["next"]["starts"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["next"]["starts"]);
  229. $range["next"]["ends"] = Application_Common_DateHelper::UTCStringToUserTimezoneString($range["next"]["ends"]);
  230. }
  231. Application_Common_DateHelper::convertTimestamps(
  232. $range["currentShow"],
  233. array("starts", "ends", "start_timestamp", "end_timestamp"),
  234. "user"
  235. );
  236. Application_Common_DateHelper::convertTimestamps(
  237. $range["nextShow"],
  238. array("starts", "ends", "start_timestamp", "end_timestamp"),
  239. "user"
  240. );
  241. //TODO: Add timezone and timezoneOffset back into the ApiController's results.
  242. $range["timezone"] = Application_Common_DateHelper::getUserTimezoneAbbreviation();
  243. $range["timezoneOffset"] = Application_Common_DateHelper::getUserTimezoneOffset();
  244. $source_status = array();
  245. $switch_status = array();
  246. $live_dj = Application_Model_Preference::GetSourceStatus("live_dj");
  247. $master_dj = Application_Model_Preference::GetSourceStatus("master_dj");
  248. $scheduled_play_switch = Application_Model_Preference::GetSourceSwitchStatus("scheduled_play");
  249. $live_dj_switch = Application_Model_Preference::GetSourceSwitchStatus("live_dj");
  250. $master_dj_switch = Application_Model_Preference::GetSourceSwitchStatus("master_dj");
  251. //might not be the correct place to implement this but for now let's just do it here
  252. $source_status['live_dj_source'] = $live_dj;
  253. $source_status['master_dj_source'] = $master_dj;
  254. $this->view->source_status = $source_status;
  255. $switch_status['live_dj_source'] = $live_dj_switch;
  256. $switch_status['master_dj_source'] = $master_dj_switch;
  257. $switch_status['scheduled_play'] = $scheduled_play_switch;
  258. $this->view->switch_status = $switch_status;
  259. $this->view->entries = $range;
  260. $this->view->show_name = isset($show[0])?$show[0]["name"]:"";
  261. }
  262. public function showContentDialogAction()
  263. {
  264. $showInstanceId = $this->_getParam('id');
  265. try {
  266. $show = new Application_Model_ShowInstance($showInstanceId);
  267. } catch (Exception $e) {
  268. $this->view->show_error = true;
  269. return false;
  270. }
  271. $originalShowId = $show->isRebroadcast();
  272. if (!is_null($originalShowId)) {
  273. try {
  274. $originalShow = new Application_Model_ShowInstance($originalShowId);
  275. } catch (Exception $e) {
  276. $this->view->show_error = true;
  277. return false;
  278. }
  279. $originalShowName = $originalShow->getName();
  280. $originalShowStart = $originalShow->getShowInstanceStart();
  281. //convert from UTC to user's timezone for display.
  282. $displayTimeZone = new DateTimeZone(Application_Model_Preference::GetTimezone());
  283. $originalDateTime = new DateTime($originalShowStart, new DateTimeZone("UTC"));
  284. $originalDateTime->setTimezone($displayTimeZone);
  285. $this->view->additionalShowInfo =
  286. sprintf(_("Rebroadcast of show %s from %s at %s"),
  287. $originalShowName,
  288. $originalDateTime->format("l, F jS"),
  289. $originalDateTime->format("G:i"));
  290. }
  291. $this->view->showLength = $show->getShowLength();
  292. $this->view->timeFilled = $show->getTimeScheduled();
  293. $this->view->percentFilled = $show->getPercentScheduled();
  294. $this->view->showContent = $show->getShowListContent();
  295. $this->view->dialog = $this->view->render('schedule/show-content-dialog.phtml');
  296. $this->view->showTitle = htmlspecialchars($show->getName());
  297. unset($this->view->showContent);
  298. }
  299. public function populateRepeatingShowInstanceFormAction()
  300. {
  301. $showId = $this->_getParam('showId');
  302. $instanceId = $this->_getParam('instanceId');
  303. $service_showForm = new Application_Service_ShowFormService($showId, $instanceId);
  304. $forms = $this->createShowFormAction();
  305. $service_showForm->delegateShowInstanceFormPopulation($forms);
  306. $this->view->addNewShow = false;
  307. $this->view->action = "edit-repeating-show-instance";
  308. $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
  309. }
  310. public function populateShowFormAction()
  311. {
  312. $service_user = new Application_Service_UserService();
  313. $currentUser = $service_user->getCurrentUser();
  314. $showId = $this->_getParam('showId');
  315. $instanceId = $this->_getParam('instanceId');
  316. $service_showForm = new Application_Service_ShowFormService($showId, $instanceId);
  317. $isAdminOrPM = $currentUser->isAdminOrPM();
  318. $forms = $this->createShowFormAction();
  319. $service_showForm->delegateShowFormPopulation($forms);
  320. if (!$isAdminOrPM) {
  321. foreach ($forms as $form) {
  322. $form->disable();
  323. }
  324. }
  325. $this->view->action = "edit-show";
  326. $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
  327. $this->view->entries = 5;
  328. }
  329. public function getFormAction()
  330. {
  331. $service_user = new Application_Service_UserService();
  332. $currentUser = $service_user->getCurrentUser();
  333. if ($currentUser->isAdminOrPM()) {
  334. $this->createShowFormAction(true);
  335. $this->view->addNewShow = true;
  336. $this->view->form = $this->view->render('schedule/add-show-form.phtml');
  337. }
  338. }
  339. public function editRepeatingShowInstanceAction(){
  340. $js = $this->_getParam('data');
  341. $data = array();
  342. //need to convert from serialized jQuery array.
  343. foreach ($js as $j) {
  344. $data[$j["name"]] = $j["value"];
  345. }
  346. $data['add_show_hosts'] = $this->_getParam('hosts');
  347. $service_showForm = new Application_Service_ShowFormService(
  348. $data["add_show_id"], $data["add_show_instance_id"]);
  349. $service_show = new Application_Service_ShowService(null, $data);
  350. $forms = $this->createShowFormAction();
  351. list($data, $validateStartDate, $validateStartTime, $originalShowStartDateTime) =
  352. $service_showForm->preEditShowValidationCheck($data);
  353. if ($service_showForm->validateShowForms($forms, $data, $validateStartDate,
  354. $originalShowStartDateTime, true, $data["add_show_instance_id"])) {
  355. $service_show->editRepeatingShowInstance($data);
  356. $this->view->addNewShow = true;
  357. $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
  358. } else {
  359. if (!$validateStartDate) {
  360. $this->view->when->getElement('add_show_start_date')->setOptions(array('disabled' => true));
  361. }
  362. if (!$validateStartTime) {
  363. $this->view->when->getElement('add_show_start_time')->setOptions(array('disabled' => true));
  364. }
  365. $this->view->rr->getElement('add_show_record')->setOptions(array('disabled' => true));
  366. $this->view->addNewShow = false;
  367. $this->view->action = "edit-repeating-show-instance";
  368. $this->view->form = $this->view->render('schedule/add-show-form.phtml');
  369. }
  370. }
  371. public function editShowAction()
  372. {
  373. $js = $this->_getParam('data');
  374. $data = array();
  375. //need to convert from serialized jQuery array.
  376. foreach ($js as $j) {
  377. $data[$j["name"]] = $j["value"];
  378. }
  379. $service_showForm = new Application_Service_ShowFormService(
  380. $data["add_show_id"]);
  381. $service_show = new Application_Service_ShowService(null, $data, true);
  382. //TODO: move this to js
  383. $data['add_show_hosts'] = $this->_getParam('hosts');
  384. $data['add_show_day_check'] = $this->_getParam('days');
  385. if ($data['add_show_day_check'] == "") {
  386. $data['add_show_day_check'] = null;
  387. }
  388. $forms = $this->createShowFormAction();
  389. list($data, $validateStartDate, $validateStartTime, $originalShowStartDateTime) =
  390. $service_showForm->preEditShowValidationCheck($data);
  391. if ($service_showForm->validateShowForms($forms, $data, $validateStartDate,
  392. $originalShowStartDateTime, true, $data["add_show_instance_id"])) {
  393. $service_show->addUpdateShow($data);
  394. $this->view->addNewShow = true;
  395. $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
  396. } else {
  397. if (!$validateStartDate) {
  398. $this->view->when->getElement('add_show_start_date')->setOptions(array('disabled' => true));
  399. }
  400. if (!$validateStartTime) {
  401. $this->view->when->getElement('add_show_start_time')->setOptions(array('disabled' => true));
  402. }
  403. $this->view->rr->getElement('add_show_record')->setOptions(array('disabled' => true));
  404. $this->view->addNewShow = false;
  405. $this->view->action = "edit-show";
  406. $this->view->form = $this->view->render('schedule/add-show-form.phtml');
  407. }
  408. }
  409. public function addShowAction()
  410. {
  411. $service_showForm = new Application_Service_ShowFormService(null);
  412. //$service_show = new Application_Service_ShowService();
  413. $js = $this->_getParam('data');
  414. $data = array();
  415. //need to convert from serialized jQuery array.
  416. foreach ($js as $j) {
  417. $data[$j["name"]] = $j["value"];
  418. }
  419. $service_show = new Application_Service_ShowService(null, $data);
  420. // TODO: move this to js
  421. $data['add_show_hosts'] = $this->_getParam('hosts');
  422. $data['add_show_day_check'] = $this->_getParam('days');
  423. if ($data['add_show_day_check'] == "") {
  424. $data['add_show_day_check'] = null;
  425. }
  426. $forms = $this->createShowFormAction();
  427. $this->view->addNewShow = true;
  428. if ($service_showForm->validateShowForms($forms, $data)) {
  429. $service_show->addUpdateShow($data);
  430. //send new show forms to the user
  431. $this->createShowFormAction(true);
  432. $this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
  433. Logging::debug("Show creation succeeded");
  434. } else {
  435. $this->view->form = $this->view->render('schedule/add-show-form.phtml');
  436. Logging::debug("Show creation failed");
  437. }
  438. }
  439. public function createShowFormAction($populateDefaults=false)
  440. {
  441. $service_showForm = new Application_Service_ShowFormService();
  442. $forms = $service_showForm->createShowForms();
  443. // populate forms with default values
  444. if ($populateDefaults) {
  445. $service_showForm->populateNewShowForms(
  446. $forms["what"], $forms["when"], $forms["repeats"]);
  447. }
  448. $this->view->what = $forms["what"];
  449. $this->view->when = $forms["when"];
  450. $this->view->repeats = $forms["repeats"];
  451. $this->view->live = $forms["live"];
  452. $this->view->rr = $forms["record"];
  453. $this->view->absoluteRebroadcast = $forms["abs_rebroadcast"];
  454. $this->view->rebroadcast = $forms["rebroadcast"];
  455. $this->view->who = $forms["who"];
  456. $this->view->style = $forms["style"];
  457. return $forms;
  458. }
  459. public function deleteShowAction()
  460. {
  461. $instanceId = $this->_getParam('id');
  462. $service_show = new Application_Service_ShowService();
  463. $showId = $service_show->deleteShow($instanceId);
  464. if (!$showId) {
  465. $this->view->show_error = true;
  466. }
  467. $this->view->show_id = $showId;
  468. }
  469. public function cancelCurrentShowAction()
  470. {
  471. $user = Application_Model_User::getCurrentUser();
  472. if ($user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER))) {
  473. $id = $this->_getParam('id');
  474. try {
  475. $scheduler = new Application_Model_Scheduler();
  476. $scheduler->cancelShow($id);
  477. Application_Model_StoredFile::updatePastFilesIsScheduled();
  478. // send kick out source stream signal to pypo
  479. $data = array("sourcename"=>"live_dj");
  480. Application_Model_RabbitMq::SendMessageToPypo("disconnect_source", $data);
  481. } catch (Exception $e) {
  482. $this->view->error = $e->getMessage();
  483. Logging::info($e->getMessage());
  484. }
  485. }
  486. }
  487. public function contentContextMenuAction()
  488. {
  489. $id = $this->_getParam('id');
  490. $params = '/format/json/id/#id#/';
  491. $paramsPop = str_replace('#id#', $id, $params);
  492. // added for downlaod
  493. $id = $this->_getParam('id');
  494. $file_id = $this->_getParam('id', null);
  495. $file = Application_Model_StoredFile::RecallById($file_id);
  496. $baseUrl = $this->getRequest()->getBaseUrl();
  497. $url = $file->getRelativeFileUrl($baseUrl).'download/true';
  498. $menu = array();
  499. $menu[] = array('action' => array('type' => 'gourl', 'url' => $url),
  500. 'title' => _('Download'));
  501. //returns format jjmenu is looking for.
  502. $this->_helper->json->sendJson($menu);
  503. }
  504. /**
  505. * Sets the user specific preference for which time scale to use in Calendar.
  506. * This is only being used by schedule.js at the moment.
  507. */
  508. public function setTimeScaleAction()
  509. {
  510. Application_Model_Preference::SetCalendarTimeScale($this->_getParam('timeScale'));
  511. }
  512. /**
  513. * Sets the user specific preference for which time interval to use in Calendar.
  514. * This is only being used by schedule.js at the moment.
  515. */
  516. public function setTimeIntervalAction()
  517. {
  518. Application_Model_Preference::SetCalendarTimeInterval($this->_getParam('timeInterval'));
  519. }
  520. public function calculateDurationAction()
  521. {
  522. $start = $this->_getParam('startTime');
  523. $end = $this->_getParam('endTime');
  524. $timezone = $this->_getParam('timezone');
  525. $service_showForm = new Application_Service_ShowFormService();
  526. $result = $service_showForm->calculateDuration($start, $end, $timezone);
  527. echo Zend_Json::encode($result);
  528. exit();
  529. }
  530. public function updateFutureIsScheduledAction()
  531. {
  532. $schedId = $this->_getParam('schedId');
  533. $scheduleService = new Application_Service_SchedulerService();
  534. $redrawLibTable = $scheduleService->updateFutureIsScheduled($schedId, false);
  535. $this->_helper->json->sendJson(array("redrawLibTable" => $redrawLibTable));
  536. }
  537. public function localizeStartEndTimeAction()
  538. {
  539. $newTimezone = $this->_getParam('newTimezone');
  540. $oldTimezone = $this->_getParam('oldTimezone');
  541. $localTime = array();
  542. $localTime["start"] = Application_Service_ShowFormService::localizeDateTime(
  543. $this->_getParam('startDate'), $this->_getParam('startTime'), $newTimezone, $oldTimezone);
  544. $localTime["end"] = Application_Service_ShowFormService::localizeDateTime(
  545. $this->_getParam('endDate'), $this->_getParam('endTime'), $newTimezone, $oldTimezone);
  546. $this->_helper->json->sendJson($localTime);
  547. }
  548. }