diff --git a/application/controllers/ScheduleController.php b/application/controllers/ScheduleController.php index d0fd1e41d..8500453f3 100644 --- a/application/controllers/ScheduleController.php +++ b/application/controllers/ScheduleController.php @@ -143,18 +143,23 @@ class ScheduleController extends Zend_Controller_Action $request = $this->getRequest(); if($request->isPost()) { + $plId = $this->_getParam('plId'); $start = $this->_getParam('start'); + $end = $this->_getParam('end'); $showId = $this->_getParam('showId'); $userInfo = Zend_Auth::getInstance()->getStorage()->read(); $user = new User($userInfo->id, $userInfo->type); $show = new Show($user, $showId); - $show->scheduleShow($start, $plId); + $show->scheduleShow($start, array($plId)); + + $this->view->showContent = $show->getShowContent($start); } else { + $length = $this->_getParam('length'); $this->view->playlists = Playlist::searchPlaylists($length); @@ -174,8 +179,8 @@ class ScheduleController extends Zend_Controller_Action if($user->isHost($showId)) { - $sched = new ScheduleGroup(); - $this->view->res = $sched->removeAtTime($start); + $show = new Show($user, $showId); + $show->clearShow($start); } } diff --git a/application/models/Schedule.php b/application/models/Schedule.php index 98ff1b19c..49040bb3d 100644 --- a/application/models/Schedule.php +++ b/application/models/Schedule.php @@ -164,32 +164,26 @@ class ScheduleGroup { public function addAfter($p_groupId, $p_audioFileId) { global $CC_CONFIG, $CC_DBC; // Get the end time for the given entry - $sql = "SELECT ends FROM ".$CC_CONFIG["scheduleTable"] + $sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"] ." WHERE group_id=$p_groupId"; $startTime = $CC_DBC->GetOne($sql); return $this->add($startTime, $p_audioFileId); } + public function addPlaylistAfter($p_groupId, $p_playlistId) { + global $CC_CONFIG, $CC_DBC; + // Get the end time for the given entry + $sql = "SELECT MAX(ends) FROM ".$CC_CONFIG["scheduleTable"] + ." WHERE group_id=$p_groupId"; + + $startTime = $CC_DBC->GetOne($sql); + return $this->add($startTime, null, $p_playlistId); + } + public function update() { } - public function removeAtTime($p_datetime) { - global $CC_CONFIG, $CC_DBC; - - $id = $this->dateToId($p_datetime); - - $sql = "SELECT group_id FROM ".$CC_CONFIG["scheduleTable"]." WHERE id = ".$id; - $groupId = $CC_DBC->GetOne($sql); - - if($groupId === NULL) - return; - - $sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"] - ." WHERE group_id = ".$groupId; - $CC_DBC->query($sql); - } - /** * Remove the group from the schedule. * Note: does not check if it is in the past, you can remove anything. diff --git a/application/models/Shows.php b/application/models/Shows.php index 7a748acee..857d7f6bf 100644 --- a/application/models/Shows.php +++ b/application/models/Shows.php @@ -189,19 +189,72 @@ class Show { } - public function scheduleShow($start, $plId) { + private function getNextPos($day) { + global $CC_DBC; + + $timeinfo = explode(" ", $day); + + $sql = "SELECT MAX(position)+1 from cc_show_schedule WHERE show_id = '{$this->_showId}' AND show_day = '{$timeinfo[0]}'"; + $res = $CC_DBC->GetOne($sql); + + if(is_null($res)) + return 0; + + return $res; + } + + private function getLastGroupId($start_timestamp) { + global $CC_DBC; + + $timeinfo = explode(" ", $start_timestamp); + + $sql = "SELECT MAX(group_id) from cc_show_schedule WHERE show_id = '{$this->_showId}' AND show_day = '{$timeinfo[0]}'"; + $res = $CC_DBC->GetOne($sql); + + return $res; + } + + public function addPlaylistToShow($start_timestamp, $plId) { + + $sched = new ScheduleGroup(); + $lastGroupId = $this->getLastGroupId($start_timestamp); + + if(is_null($lastGroupId)) { + + $groupId = $sched->add($start_timestamp, null, $plId); + } + else { + $groupId = $sched->addPlaylistAfter($lastGroupId, $plId); + } + + $timeinfo = explode(" ", $start_timestamp); + $day = $timeinfo[0]; + $pos = $this->getNextPos($day); + + $groupsched = new CcShowSchedule(); + $groupsched->setDbShowId($this->_showId); + $groupsched->setDbGroupId($groupId); + $groupsched->setDbShowDay($day); + $groupsched->setDbPosition($pos); + $groupsched->save(); + } + + public function scheduleShow($start_timestamp, $plIds) { if($this->_user->isHost($this->_showId)) { - $sched = new ScheduleGroup(); - $groupId = $sched->add($start, null, $plId); - - $groupsched = new CcShowSchedule(); - $groupsched->setDbShowId($this->_showId); - $groupsched->setDbGroupId($groupId); - $groupsched->save(); + foreach($plIds as $plId) { + $this->addPlaylistToShow($start_timestamp, $plId); + } } } + public function getTimeScheduled($start_timestamp, $end_timestamp) { + + $time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp); + + return $time; + } + public function getTimeUnScheduled($start_date, $end_date, $start_time, $end_time) { $start_timestamp = $start_date ." ".$start_time; @@ -222,6 +275,39 @@ class Show { return !Schedule::isScheduleEmptyInRange($start_timestamp, $length); } + public function getShowContent($day) { + global $CC_DBC; + + $timeinfo = explode(" ", $day); + + $sql = "SELECT * + FROM (cc_show_schedule AS ss LEFT JOIN cc_schedule AS s USING(group_id) + LEFT JOIN cc_files AS f ON f.id = s.file_id + LEFT JOIN cc_playlist AS p ON p.id = s.playlist_id ) + + WHERE ss.show_day = '{$timeinfo[0]}' AND ss.show_id = '{$this->_showId}'"; + + return $CC_DBC->GetAll($sql); + } + + public function clearShow($day) { + $timeinfo = explode(" ", $day); + + $groups = CcShowScheduleQuery::create() + ->filterByDbShowId($this->_showId) + ->filterByDbShowDay($timeinfo[0]) + ->find(); + + foreach($groups as $group) { + $groupId = $group->getDbGroupId(); + CcScheduleQuery::create() + ->filterByDbGroupId($groupId) + ->delete(); + + $group->delete(); + } + } + public function deleteShow($showId, $dayId=NULL) { $groups = CcShowScheduleQuery::create()->filterByDbShowId($showId)->find(); diff --git a/application/views/scripts/schedule/scheduled-content-partial.phtml b/application/views/scripts/schedule/scheduled-content-partial.phtml new file mode 100644 index 000000000..6e2d847d7 --- /dev/null +++ b/application/views/scripts/schedule/scheduled-content-partial.phtml @@ -0,0 +1,2 @@ +