194 lines
6.4 KiB
PHP
194 lines
6.4 KiB
PHP
<?php
|
|
|
|
class Application_Service_ScheduleService
|
|
{
|
|
/*
|
|
* Form stuff begins here
|
|
* Typically I would keep form creation and validation
|
|
* in the controller but since shows require 9 forms,
|
|
* the controller will become too fat.
|
|
* Maybe we should create a special form show service?
|
|
*/
|
|
/**
|
|
*
|
|
* @return array of schedule forms
|
|
*/
|
|
public function createShowForms()
|
|
{
|
|
$formWhat = new Application_Form_AddShowWhat();
|
|
$formWho = new Application_Form_AddShowWho();
|
|
$formWhen = new Application_Form_AddShowWhen();
|
|
$formRepeats = new Application_Form_AddShowRepeats();
|
|
$formStyle = new Application_Form_AddShowStyle();
|
|
$formLive = new Application_Form_AddShowLiveStream();
|
|
$formRecord = new Application_Form_AddShowRR();
|
|
$formAbsoluteRebroadcast = new Application_Form_AddShowAbsoluteRebroadcastDates();
|
|
$formRebroadcast = new Application_Form_AddShowRebroadcastDates();
|
|
|
|
$formWhat->removeDecorator('DtDdWrapper');
|
|
$formWho->removeDecorator('DtDdWrapper');
|
|
$formWhen->removeDecorator('DtDdWrapper');
|
|
$formRepeats->removeDecorator('DtDdWrapper');
|
|
$formStyle->removeDecorator('DtDdWrapper');
|
|
$formLive->removeDecorator('DtDdWrapper');
|
|
$formRecord->removeDecorator('DtDdWrapper');
|
|
$formAbsoluteRebroadcast->removeDecorator('DtDdWrapper');
|
|
$formRebroadcast->removeDecorator('DtDdWrapper');
|
|
|
|
$forms = array();
|
|
$forms["what"] = $formWhat;
|
|
$forms["who"] = $formWho;
|
|
$forms["when"] = $formWhen;
|
|
$forms["repeats"] = $formRepeats;
|
|
$forms["style"] = $formStyle;
|
|
$forms["live"] = $formLive;
|
|
$forms["record"] = $formRecord;
|
|
$forms["abs_rebroadcast"] = $formAbsoluteRebroadcast;
|
|
$forms["rebroadcast"] = $formRebroadcast;
|
|
|
|
return $forms;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Popluates the what, when, and repeat forms
|
|
* with default values
|
|
*/
|
|
public function populateNewShowForms($formWhat, $formWhen, $formRepeats)
|
|
{
|
|
$formWhat->populate(
|
|
array('add_show_id' => '-1',
|
|
'add_show_instance_id' => '-1'));
|
|
|
|
$formWhen->populate(
|
|
array('add_show_start_date' => date("Y-m-d"),
|
|
'add_show_start_time' => '00:00',
|
|
'add_show_end_date_no_repeate' => date("Y-m-d"),
|
|
'add_show_end_time' => '01:00',
|
|
'add_show_duration' => '01h 00m'));
|
|
|
|
$formRepeats->populate(array('add_show_end_date' => date("Y-m-d")));
|
|
}
|
|
|
|
public function populateForm($form, $values)
|
|
{
|
|
$form->populate($values);
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Validates show forms
|
|
*
|
|
* @return boolean
|
|
*/
|
|
public function validateShowForms($forms, $formData, $validateStartDate = true)
|
|
{
|
|
$what = $forms["what"]->isValid($formData);
|
|
$live = $forms["live"]->isValid($formData);
|
|
$record = $forms["record"]->isValid($formData);
|
|
$who = $forms["who"]->isValid($formData);
|
|
$style = $forms["style"]->isValid($formData);
|
|
$when = $forms["when"]->isWhenFormValid($formData, $validateStartDate);
|
|
|
|
$repeats = true;
|
|
if ($formData["add_show_repeats"]) {
|
|
$repeats = $forms["repeats"]->isValid($formData);
|
|
|
|
/*
|
|
* Make the absolute rebroadcast form valid since
|
|
* it does not get used if the show is repeating
|
|
*/
|
|
$forms["abs_rebroadcast"]->reset();
|
|
$absRebroadcast = true;
|
|
|
|
$rebroadcast = true;
|
|
if ($formData["add_show_rebroadcast"]) {
|
|
$formData["add_show_duration"] = $this->formatShowDuration(
|
|
$formData["add_show_duration"]);
|
|
$rebroadcast = $forms["rebroadcast"]->isValid($formData);
|
|
}
|
|
} else {
|
|
/*
|
|
* Make the rebroadcast form valid since it does
|
|
* not get used if the show is not repeating.
|
|
* Instead, we use the absolute rebroadcast form
|
|
*/
|
|
$forms["rebroadcast"]->reset();
|
|
$rebroadcast = true;
|
|
|
|
$absRebroadcast = true;
|
|
if ($formData["add_show_rebroadcast"]) {
|
|
$formData["add_show_duration"] = $this->formatShowDuration(
|
|
$formData["add_show_duration"]);
|
|
$absRebroadcast = $forms["abs_rebroadcast"]->isValid($formData);
|
|
}
|
|
}
|
|
|
|
if ($what && $live && $record && $who && $style && $when &&
|
|
$repeats && $absRebroadcast && $rebroadcast) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
/*
|
|
* Form stuff ends
|
|
*/
|
|
|
|
public function formatShowDuration($duration) {
|
|
$hPos = strpos($duration, 'h');
|
|
$mPos = strpos($duration, 'm');
|
|
|
|
$hValue = 0;
|
|
$mValue = 0;
|
|
|
|
if ($hPos !== false) {
|
|
$hValue = trim(substr($duration, 0, $hPos));
|
|
}
|
|
if ($mPos !== false) {
|
|
$hPos = $hPos === false ? 0 : $hPos+1;
|
|
$mValue = trim(substr($duration, $hPos, -1 ));
|
|
}
|
|
|
|
return $hValue.":".$mValue;
|
|
}
|
|
|
|
/**
|
|
*
|
|
* Creates a new show if form data is valid
|
|
*/
|
|
public function createShow($showData)
|
|
{
|
|
$userInfo = Zend_Auth::getInstance()->getStorage()->read();
|
|
$user = new Application_Model_User($userInfo->id);
|
|
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
|
|
|
|
$repeatType = ($showData['add_show_repeats']) ? $showData['add_show_repeat_type'] : -1;
|
|
$isRecorded = (isset($showData['add_show_record']) && $showData['add_show_record']) ? 1 : 0;
|
|
|
|
$showData["add_show_duration"] = $this->formatShowDuration(
|
|
$showData["add_show_duration"]);
|
|
|
|
if ($isAdminOrPM) {
|
|
$service_show = new Application_Service_ShowService();
|
|
|
|
//create ccShow
|
|
$ccShow = new CcShow();
|
|
$ccShow = $service_show->setShow($ccShow, $showData);
|
|
$showId = $ccShow->getDbId();
|
|
|
|
//create ccShowDay
|
|
$service_show->createShowDays(
|
|
$showData, $showId, $user->getId(), $repeatType, $isRecorded);
|
|
|
|
//create ccShowRebroadcast
|
|
$service_show->createShowRebroadcast($showData, $showId, $repeatType, $isRecorded);
|
|
|
|
//create ccShowHosts
|
|
$service_show->createShowHosts($showData, $showId);
|
|
|
|
//populate ccShowInstances
|
|
}
|
|
}
|
|
|
|
} |