Created show service
This commit is contained in:
parent
9f0baba4f8
commit
2717c0845b
|
@ -1229,7 +1229,7 @@ SQL;
|
||||||
//adding rows to cc_show_rebroadcast
|
//adding rows to cc_show_rebroadcast
|
||||||
/* TODO: Document magic constant 10 and define it properly somewhere
|
/* TODO: Document magic constant 10 and define it properly somewhere
|
||||||
--RG */
|
--RG */
|
||||||
if (($isRecorded && $data['add_show_rebroadcast']) && ($repeatType != -1)) {
|
/*if (($isRecorded && $data['add_show_rebroadcast']) && ($repeatType != -1)) {
|
||||||
for ($i=1; $i<=10; $i++) {
|
for ($i=1; $i<=10; $i++) {
|
||||||
if ($data['add_show_rebroadcast_date_'.$i]) {
|
if ($data['add_show_rebroadcast_date_'.$i]) {
|
||||||
$showRebroad = new CcShowRebroadcast();
|
$showRebroad = new CcShowRebroadcast();
|
||||||
|
@ -1266,14 +1266,14 @@ SQL;
|
||||||
$showRebroad->save();
|
$showRebroad->save();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
//check if we are adding or updating a show, and if updating
|
//check if we are adding or updating a show, and if updating
|
||||||
//erase all the show's show_rebroadcast information first.
|
//erase all the show's show_rebroadcast information first.
|
||||||
if ($data['add_show_id'] != -1) {
|
if ($data['add_show_id'] != -1) {
|
||||||
CcShowHostsQuery::create()->filterByDbShow($data['add_show_id'])->delete();
|
CcShowHostsQuery::create()->filterByDbShow($data['add_show_id'])->delete();
|
||||||
}
|
}
|
||||||
if (is_array($data['add_show_hosts'])) {
|
/*if (is_array($data['add_show_hosts'])) {
|
||||||
//add selected hosts to cc_show_hosts table.
|
//add selected hosts to cc_show_hosts table.
|
||||||
foreach ($data['add_show_hosts'] as $host) {
|
foreach ($data['add_show_hosts'] as $host) {
|
||||||
$showHost = new CcShowHosts();
|
$showHost = new CcShowHosts();
|
||||||
|
@ -1281,7 +1281,7 @@ SQL;
|
||||||
$showHost->setDbHost($host);
|
$showHost->setDbHost($host);
|
||||||
$showHost->save();
|
$showHost->save();
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
if ($data['add_show_id'] != -1) {
|
if ($data['add_show_id'] != -1) {
|
||||||
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
|
$con = Propel::getConnection(CcSchedulePeer::DATABASE_NAME);
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -175,15 +175,18 @@ class Application_Service_ScheduleService
|
||||||
//create ccShow
|
//create ccShow
|
||||||
$ccShow = new CcShow();
|
$ccShow = new CcShow();
|
||||||
$ccShow = $service_show->setShow($ccShow, $showData);
|
$ccShow = $service_show->setShow($ccShow, $showData);
|
||||||
|
$showId = $ccShow->getDbId();
|
||||||
|
|
||||||
//create ccShowDay
|
//create ccShowDay
|
||||||
$service_show->createShowDays(
|
$service_show->createShowDays(
|
||||||
$showData, $ccShow->getDbId(), $user->getId(), $repeatType, $isRecorded);
|
$showData, $showId, $user->getId(), $repeatType, $isRecorded);
|
||||||
|
|
||||||
|
//create ccShowRebroadcast
|
||||||
|
$service_show->createShowRebroadcast($showData, $showId, $repeatType, $isRecorded);
|
||||||
|
|
||||||
//create ccShowHosts
|
//create ccShowHosts
|
||||||
|
$service_show->createShowHosts($showData, $showId);
|
||||||
//create ccShowRebroadcast
|
|
||||||
|
|
||||||
//populate ccShowInstances
|
//populate ccShowInstances
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,145 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
class Application_Service_ShowService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Sets a cc_show entry
|
||||||
|
*/
|
||||||
|
public function setShow($ccShow, $showData)
|
||||||
|
{
|
||||||
|
$ccShow->setDbName($showData['add_show_name']);
|
||||||
|
$ccShow->setDbDescription($showData['add_show_description']);
|
||||||
|
$ccShow->setDbUrl($showData['add_show_url']);
|
||||||
|
$ccShow->setDbGenre($showData['add_show_genre']);
|
||||||
|
$ccShow->setDbColor($showData['add_show_color']);
|
||||||
|
$ccShow->setDbBackgroundColor($showData['add_show_background_color']);
|
||||||
|
$ccShow->setDbLiveStreamUsingAirtimeAuth($showData['cb_airtime_auth'] == 1);
|
||||||
|
$ccShow->setDbLiveStreamUsingCustomAuth($showData['cb_custom_auth'] == 1);
|
||||||
|
$ccShow->setDbLiveStreamUser($showData['custom_username']);
|
||||||
|
$ccShow->setDbLiveStreamPass($showData['custom_password']);
|
||||||
|
|
||||||
|
$ccShow->save();
|
||||||
|
return $ccShow;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new cc_show_days entries
|
||||||
|
*/
|
||||||
|
public function createShowDays($showData, $showId, $userId, $repeatType, $isRecorded)
|
||||||
|
{
|
||||||
|
$startDateTime = new DateTime($showData['add_show_start_date']." ".$showData['add_show_start_time']);
|
||||||
|
|
||||||
|
if ($showData['add_show_no_end']) {
|
||||||
|
$endDate = NULL;
|
||||||
|
} elseif ($showData['add_show_repeats']) {
|
||||||
|
$endDateTime = new DateTime($showData['add_show_end_date']);
|
||||||
|
$endDateTime->add(new DateInterval("P1D"));
|
||||||
|
$endDate = $endDateTime->format("Y-m-d");
|
||||||
|
} else {
|
||||||
|
$endDateTime = new DateTime($showData['add_show_start_date']);
|
||||||
|
$endDateTime->add(new DateInterval("P1D"));
|
||||||
|
$endDate = $endDateTime->format("Y-m-d");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* What we are doing here is checking if the show repeats or if
|
||||||
|
* any repeating days have been checked. If not, then by default
|
||||||
|
* the "selected" DOW is the initial day.
|
||||||
|
* DOW in local time.
|
||||||
|
*/
|
||||||
|
$startDow = date("w", $startDateTime->getTimestamp());
|
||||||
|
if (!$showData['add_show_repeats']) {
|
||||||
|
$showData['add_show_day_check'] = array($startDow);
|
||||||
|
} elseif ($showData['add_show_repeats'] && $showData['add_show_day_check'] == "") {
|
||||||
|
$showData['add_show_day_check'] = array($startDow);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Don't set day for monthly repeat type, it's invalid
|
||||||
|
if ($showData['add_show_repeats'] && $showData['add_show_repeat_type'] == 2) {
|
||||||
|
$showDay = new CcShowDays();
|
||||||
|
$showDay->setDbFirstShow($startDateTime->format("Y-m-d"));
|
||||||
|
$showDay->setDbLastShow($endDate);
|
||||||
|
$showDay->setDbStartTime($startDateTime->format("H:i:s"));
|
||||||
|
$showDay->setDbTimezone(Application_Model_Preference::GetUserTimezone($userId));
|
||||||
|
$showDay->setDbDuration($showData['add_show_duration']);
|
||||||
|
$showDay->setDbRepeatType($repeatType);
|
||||||
|
$showDay->setDbShowId($showId);
|
||||||
|
$showDay->setDbRecord($isRecorded);
|
||||||
|
$showDay->save();
|
||||||
|
} else {
|
||||||
|
foreach ($showData['add_show_day_check'] as $day) {
|
||||||
|
$daysAdd=0;
|
||||||
|
$startDateTimeClone = clone $startDateTime;
|
||||||
|
if ($startDow !== $day) {
|
||||||
|
if ($startDow > $day)
|
||||||
|
$daysAdd = 6 - $startDow + 1 + $day;
|
||||||
|
else
|
||||||
|
$daysAdd = $day - $startDow;
|
||||||
|
|
||||||
|
$startDateTimeClone->add(new DateInterval("P".$daysAdd."D"));
|
||||||
|
}
|
||||||
|
if (is_null($endDate) || $startDateTimeClone->getTimestamp() <= $endDateTime->getTimestamp()) {
|
||||||
|
$showDay = new CcShowDays();
|
||||||
|
$showDay->setDbFirstShow($startDateTimeClone->format("Y-m-d"));
|
||||||
|
$showDay->setDbLastShow($endDate);
|
||||||
|
$showDay->setDbStartTime($startDateTimeClone->format("H:i"));
|
||||||
|
$showDay->setDbTimezone(Application_Model_Preference::GetUserTimezone($userId));
|
||||||
|
$showDay->setDbDuration($showData['add_show_duration']);
|
||||||
|
$showDay->setDbDay($day);
|
||||||
|
$showDay->setDbRepeatType($repeatType);
|
||||||
|
$showDay->setDbShowId($showId);
|
||||||
|
$showDay->setDbRecord($isRecorded);
|
||||||
|
$showDay->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates new cc_show_rebroadcast entries
|
||||||
|
*/
|
||||||
|
public function createShowRebroadcast($showData, $showId, $repeatType, $isRecorded)
|
||||||
|
{
|
||||||
|
define("MAX_REBROADCAST_DATES", 10);
|
||||||
|
|
||||||
|
if (($isRecorded && $showData['add_show_rebroadcast']) && ($repeatType != -1)) {
|
||||||
|
for ($i=1; $i<=MAX_REBROADCAST_DATES; $i++) {
|
||||||
|
if ($showData['add_show_rebroadcast_date_'.$i]) {
|
||||||
|
$showRebroad = new CcShowRebroadcast();
|
||||||
|
$showRebroad->setDbDayOffset($showData['add_show_rebroadcast_date_'.$i]);
|
||||||
|
$showRebroad->setDbStartTime($showData['add_show_rebroadcast_time_'.$i]);
|
||||||
|
$showRebroad->setDbShowId($showId);
|
||||||
|
$showRebroad->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} elseif ($isRecorded && $showData['add_show_rebroadcast'] && ($repeatType == -1)) {
|
||||||
|
for ($i=1; $i<=MAX_REBROADCAST_DATES; $i++) {
|
||||||
|
if ($showData['add_show_rebroadcast_date_absolute_'.$i]) {
|
||||||
|
$rebroadcastDate = new DateTime($showData["add_show_rebroadcast_date_absolute_$i"]);
|
||||||
|
$startDate = new DateTime($showData['add_show_start_date']);
|
||||||
|
$offsetDays = $startDate->diff($rebroadcastDate);
|
||||||
|
|
||||||
|
$showRebroad = new CcShowRebroadcast();
|
||||||
|
$showRebroad->setDbDayOffset($offsetDays->format("%a days"));
|
||||||
|
$showRebroad->setDbStartTime($showData['add_show_rebroadcast_time_absolute_'.$i]);
|
||||||
|
$showRebroad->setDbShowId($showId);
|
||||||
|
$showRebroad->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates cc_show_hosts entries
|
||||||
|
*/
|
||||||
|
public function createShowHosts($showData, $showId)
|
||||||
|
{
|
||||||
|
if (is_array($showData['add_show_hosts'])) {
|
||||||
|
foreach ($showData['add_show_hosts'] as $host) {
|
||||||
|
$showHost = new CcShowHosts();
|
||||||
|
$showHost->setDbShow($showId);
|
||||||
|
$showHost->setDbHost($host);
|
||||||
|
$showHost->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue