when deleting a group following groups in show update their times.

This commit is contained in:
naomiaro 2011-01-15 13:10:10 -05:00
parent 2de6944a20
commit f2560a6aa6
5 changed files with 126 additions and 36 deletions

View file

@ -63,6 +63,7 @@
<actionMethod actionName="scheduleShow"/> <actionMethod actionName="scheduleShow"/>
<actionMethod actionName="clearShow"/> <actionMethod actionName="clearShow"/>
<actionMethod actionName="findPlaylists"/> <actionMethod actionName="findPlaylists"/>
<actionMethod actionName="removeGroup"/>
</controllerFile> </controllerFile>
<controllerFile controllerName="Api"> <controllerFile controllerName="Api">
<actionMethod actionName="index"/> <actionMethod actionName="index"/>
@ -242,6 +243,9 @@
<viewControllerScriptsDirectory forControllerName="Schedule"> <viewControllerScriptsDirectory forControllerName="Schedule">
<viewScriptFile forActionName="findPlaylists"/> <viewScriptFile forActionName="findPlaylists"/>
</viewControllerScriptsDirectory> </viewControllerScriptsDirectory>
<viewControllerScriptsDirectory forControllerName="Schedule">
<viewScriptFile forActionName="removeGroup"/>
</viewControllerScriptsDirectory>
</viewScriptsDirectory> </viewScriptsDirectory>
<viewHelpersDirectory/> <viewHelpersDirectory/>
<viewFiltersDirectory enabled="false"/> <viewFiltersDirectory enabled="false"/>

View file

@ -21,6 +21,7 @@ class ScheduleController extends Zend_Controller_Action
->addActionContext('clear-show', 'json') ->addActionContext('clear-show', 'json')
->addActionContext('get-current-playlist', 'json') ->addActionContext('get-current-playlist', 'json')
->addActionContext('find-playlists', 'html') ->addActionContext('find-playlists', 'html')
->addActionContext('remove-group', 'json')
->initContext(); ->initContext();
} }
@ -126,7 +127,7 @@ class ScheduleController extends Zend_Controller_Action
public function deleteShowAction() public function deleteShowAction()
{ {
$showId = $this->_getParam('showId'); $showId = $this->_getParam('showId');
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$show = new Show(new User($userInfo->id, $userInfo->type)); $show = new Show(new User($userInfo->id, $userInfo->type));
@ -141,11 +142,9 @@ class ScheduleController extends Zend_Controller_Action
public function scheduleShowAction() public function scheduleShowAction()
{ {
$request = $this->getRequest(); $request = $this->getRequest();
$start = $this->_getParam('start'); $start_timestamp = $this->_getParam('start');
$end = $this->_getParam('end');
$showId = $this->_getParam('showId'); $showId = $this->_getParam('showId');
$day = $this->_getParam('day');
$search = $this->_getParam('search', null); $search = $this->_getParam('search', null);
if($search == "") { if($search == "") {
@ -161,11 +160,11 @@ class ScheduleController extends Zend_Controller_Action
$plId = $this->_getParam('plId'); $plId = $this->_getParam('plId');
$show->scheduleShow($start, array($plId)); $show->scheduleShow($start_timestamp, array($plId));
} }
$this->view->playlists = $show->searchPlaylistsForShow($day, $search); $this->view->playlists = $show->searchPlaylistsForShow($start_timestamp, $search);
$this->view->showContent = $show->getShowContent($start); $this->view->showContent = $show->getShowContent($start_timestamp);
$this->view->choice = $this->view->render('schedule/find-playlists.phtml'); $this->view->choice = $this->view->render('schedule/find-playlists.phtml');
$this->view->chosen = $this->view->render('schedule/scheduled-content.phtml'); $this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
@ -173,7 +172,6 @@ class ScheduleController extends Zend_Controller_Action
unset($this->view->showContent); unset($this->view->showContent);
unset($this->view->playlists); unset($this->view->playlists);
} }
public function clearShowAction() public function clearShowAction()
@ -203,15 +201,38 @@ class ScheduleController extends Zend_Controller_Action
public function findPlaylistsAction() public function findPlaylistsAction()
{ {
$search = $this->_getParam('search'); $search = $this->_getParam('search');
$show_id = $this->_getParam('id'); $show_id = $this->_getParam('showId');
$dofw = $this->_getParam('day'); $start_timestamp = $this->_getParam('start');
$userInfo = Zend_Auth::getInstance()->getStorage()->read(); $userInfo = Zend_Auth::getInstance()->getStorage()->read();
$show = new Show(new User($userInfo->id, $userInfo->type), $show_id); $show = new Show(new User($userInfo->id, $userInfo->type), $show_id);
$this->view->playlists = $show->searchPlaylistsForShow($dofw, $search); $this->view->playlists = $show->searchPlaylistsForShow($start_timestamp, $search);
} }
public function removeGroupAction()
{
$group_id = $this->_getParam('groupId');
$start_timestamp = $this->_getParam('start');
$show_id = $this->_getParam('showId');
$search = $this->_getParam('search', null);
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
$show = new Show(new User($userInfo->id, $userInfo->type), $show_id);
$show->removeGroupFromShow($start_timestamp, $group_id);
$this->view->playlists = $show->searchPlaylistsForShow($start_timestamp, $search);
$this->view->showContent = $show->getShowContent($start_timestamp);
$this->view->choice = $this->view->render('schedule/find-playlists.phtml');
$this->view->chosen = $this->view->render('schedule/scheduled-content.phtml');
unset($this->view->showContent);
unset($this->view->playlists);
}
} }
@ -231,6 +252,8 @@ class ScheduleController extends Zend_Controller_Action

View file

@ -248,6 +248,47 @@ class Show {
} }
} }
public function removeGroupFromShow($start_timestamp, $group_id){
global $CC_DBC, $CC_CONFIG;
$timeinfo = explode(" ", $start_timestamp);
$group = CcShowScheduleQuery::create()
->filterByDbShowId($this->_showId)
->filterByDbGroupId($group_id)
->filterByDbShowDay($timeinfo[0])
->findOne();
$position = $group->getDbPosition();
$sql = "SELECT group_id FROM cc_show_schedule
WHERE show_id = '{$this->_showId}' AND show_day = '{$timeinfo[0]}'
AND position > '{$position}'";
$followingGroups = $CC_DBC->GetAll($sql);
$sql = "SELECT SUM(clip_length) FROM ".$CC_CONFIG["scheduleTable"]." WHERE group_id='{$group_id}'";
$group_length = $CC_DBC->GetOne($sql);
$sql = "DELETE FROM ".$CC_CONFIG["scheduleTable"]." WHERE group_id = '{$group_id}'";
$CC_DBC->query($sql);
if(!is_null($followingGroups)) {
$sql_opt = array();
foreach ($followingGroups as $row) {
$sql_opt[] = "group_id = {$row["group_id"]}";
}
$sql_group_ids = join(" OR ", $sql_opt);
$sql = "UPDATE ".$CC_CONFIG["scheduleTable"]."
SET starts = (starts - INTERVAL '{$group_length}'), ends = (ends - INTERVAL '{$group_length}')
WHERE " . $sql_group_ids;
$CC_DBC->query($sql);
}
$group->delete();
}
public function getTimeScheduled($start_timestamp, $end_timestamp) { public function getTimeScheduled($start_timestamp, $end_timestamp) {
$time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp); $time = Schedule::getTimeScheduledInRange($start_timestamp, $end_timestamp);
@ -515,9 +556,12 @@ class Show {
return $event; return $event;
} }
public function searchPlaylistsForShow($day, $search=null){ public function searchPlaylistsForShow($start_timestamp, $search=null){
global $CC_DBC; global $CC_DBC;
$sql = "SELECT EXTRACT(DOW FROM TIMESTAMP '{$start_timestamp}')";
$day = $CC_DBC->GetOne($sql);
$sql = "SELECT * FROM cc_show_days WHERE show_id = '{$this->_showId}' AND day = '{$day}'"; $sql = "SELECT * FROM cc_show_days WHERE show_id = '{$this->_showId}' AND day = '{$day}'";
$row = $CC_DBC->GetAll($sql); $row = $CC_DBC->GetAll($sql);
$row = $row[0]; $row = $row[0];

View file

@ -0,0 +1 @@
<br /><br /><center>View script for controller <b>Schedule</b> and script/action name <b>removeGroup</b></center>

View file

@ -164,13 +164,13 @@ function openShowDialog() {
function makeScheduleDialog(dialog, json, show) { function makeScheduleDialog(dialog, json, show) {
dialog.find("#schedule_playlist_search").keyup(function(){ dialog.find("#schedule_playlist_search").keyup(function(){
var url, string, day; var url, string, start_date;
url = "/Schedule/find-playlists/format/html"; url = "/Schedule/find-playlists/format/html";
string = $(this).val(); string = $(this).val();
day = show.start.getDay(); start_date = makeTimeStamp(show.start);
$.post(url, {search: string, id: show.id, day: day}, function(html){ $.post(url, {search: string, showId: show.id, start: start_date}, function(html){
$("#schedule_playlist_choice") $("#schedule_playlist_choice")
.empty() .empty()
@ -194,20 +194,18 @@ function makeScheduleDialog(dialog, json, show) {
.append(json.chosen) .append(json.chosen)
.droppable({ .droppable({
drop: function(event, ui) { drop: function(event, ui) {
var li, pl_id, url, start_date, end_date, day, search; var li, pl_id, url, start_date, search;
search = $("#schedule_playlist_search").val(); search = $("#schedule_playlist_search").val();
pl_id = $(ui.helper).attr("id").split("_").pop(); pl_id = $(ui.helper).attr("id").split("_").pop();
day = show.start.getDay();
start_date = makeTimeStamp(show.start); start_date = makeTimeStamp(show.start);
end_date = makeTimeStamp(show.end);
url = '/Schedule/schedule-show/format/json'; url = '/Schedule/schedule-show/format/json';
$.post(url, $.post(url,
{plId: pl_id, start: start_date, end: end_date, showId: show.id, day: day, search: search}, {plId: pl_id, start: start_date, showId: show.id, search: search},
function(json){ function(json){
var x; var x;
@ -221,33 +219,53 @@ function makeScheduleDialog(dialog, json, show) {
$("#schedule_playlist_chosen") $("#schedule_playlist_chosen")
.empty() .empty()
.append(json.chosen) .append(json.chosen);
.find("li")
.click(function(){
$(this).find(".group_list").toggle();
});
}); });
} }
}); });
dialog.find("#schedule_playlist_chosen li") dialog.find(".ui-icon-triangle-1-e").parent().click(function(){
.click(function(){ $(this).parent().find(".group_list").toggle();
$(this).find(".group_list").toggle(); });
});
dialog.find(".ui-icon-close").parent().click(function(){
var groupId, url, start_date;
start_date = makeTimeStamp(show.start);
groupId = $(this).parent().attr("id").split("_").pop();
url = '/Schedule/remove-group/format/json';
$.post(url,
{start: start_date, showId: show.id, groupId: groupId},
function(json){
$("#schedule_playlist_choice")
.empty()
.append(json.choice)
.find('li')
.draggable({
helper: 'clone'
});
$("#schedule_playlist_chosen")
.empty()
.append(json.chosen);
});
});
} }
function openScheduleDialog(show) { function openScheduleDialog(show) {
var url, start_date, end_date, day; var url, start_date, end_date;
url = '/Schedule/schedule-show/format/json'; url = '/Schedule/schedule-show/format/json';
day = show.start.getDay();
start_date = makeTimeStamp(show.start); start_date = makeTimeStamp(show.start);
end_date = makeTimeStamp(show.end); end_date = makeTimeStamp(show.end);
$.get(url, $.get(url,
{day: day, start: start_date, end: end_date, showId: show.id}, {start: start_date, end: end_date, showId: show.id},
function(json){ function(json){
var dialog = $(json.dialog); var dialog = $(json.dialog);