function setup() { global $CC_CONFIG, $CC_DBC; // Clear the files table $sql = "DELETE FROM " . $CC_CONFIG["filesTable"]; $CC_DBC->query($sql); // Add a file $values = array("filepath" => dirname(__FILE__) . "/test10001.mp3"); $this->storedFile = StoredFile::Insert($values, false); // Add a file $values = array("filepath" => dirname(__FILE__) . "/test10002.mp3"); $this->storedFile2 = StoredFile::Insert($values, false); // Clear the schedule table $sql = "DELETE FROM " . $CC_CONFIG["scheduleTable"]; $CC_DBC->query($sql); // Create a playlist $playlist = new Playlist(); $playlist->create("Scheduler Unit Test"); $result = $playlist->addAudioClip($this->storedFile->getId()); $result = $playlist->addAudioClip($this->storedFile2->getId()); $result = $playlist->addAudioClip($this->storedFile2->getId()); // Schedule it $i = new ScheduleGroup(); $this->groupIdCreated = $i->add('2010-11-11 01:30:23', null, $playlist->getId()); }
function testIsScheduleEmptyInRange() { $i = new ScheduleGroup(); $this->groupIdCreated = $i->add('2011-10-10 01:30:23', $this->storedFile->getId()); if (PEAR::isError($this->groupIdCreated)) { $this->fail($this->groupIdCreated->getMessage()); return; } if (Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:12.555')) { $this->fail("Reporting empty schedule when it isnt."); return; } // echo "groupid: ".$this->groupIdCreated."\n"; $success = $i->remove(); if ($success === false) { $this->fail("Failed to delete schedule group."); return; } if (!Schedule::isScheduleEmptyInRange('2011-10-10 01:30:23', '00:00:12.555')) { $this->fail("Reporting booked schedule when it isnt."); return; } }
/** * Export the schedule in json formatted for pypo (the liquidsoap scheduler) * * @param string $p_fromDateTime * In the format "YYYY-MM-DD-HH-mm-SS" * @param string $p_toDateTime * In the format "YYYY-MM-DD-HH-mm-SS" */ public static function GetScheduledPlaylists($p_fromDateTime = null, $p_toDateTime = null) { global $CC_CONFIG, $CC_DBC; if (is_null($p_fromDateTime)) { $t1 = new DateTime(); $range_start = $t1->format("Y-m-d H:i:s"); } else { $range_start = Schedule::PypoTimeToAirtimeTime($p_fromDateTime); } if (is_null($p_fromDateTime)) { $t2 = new DateTime(); $t2->add(new DateInterval("PT24H")); $range_end = $t2->format("Y-m-d H:i:s"); } else { $range_end = Schedule::PypoTimeToAirtimeTime($p_toDateTime); } // Scheduler wants everything in a playlist $data = Schedule::GetItems($range_start, $range_end, true); $playlists = array(); if (is_array($data)) { foreach ($data as $dx) { $start = $dx['start']; //chop off subseconds $start = substr($start, 0, 19); //Start time is the array key, needs to be in the format "YYYY-MM-DD-HH-mm-ss" $pkey = Schedule::AirtimeTimeToPypoTime($start); $timestamp = strtotime($start); $playlists[$pkey]['source'] = "PLAYLIST"; $playlists[$pkey]['x_ident'] = $dx['group_id']; //$playlists[$pkey]['subtype'] = '1'; // Just needs to be between 1 and 4 inclusive $playlists[$pkey]['timestamp'] = $timestamp; $playlists[$pkey]['duration'] = $dx['clip_length']; $playlists[$pkey]['played'] = '0'; $playlists[$pkey]['schedule_id'] = $dx['group_id']; $playlists[$pkey]['show_name'] = $dx['show_name']; $playlists[$pkey]['show_start'] = Schedule::AirtimeTimeToPypoTime($dx['show_start']); $playlists[$pkey]['show_end'] = Schedule::AirtimeTimeToPypoTime($dx['show_end']); $playlists[$pkey]['user_id'] = 0; $playlists[$pkey]['id'] = $dx['group_id']; $playlists[$pkey]['start'] = Schedule::AirtimeTimeToPypoTime($dx["start"]); $playlists[$pkey]['end'] = Schedule::AirtimeTimeToPypoTime($dx["end"]); } } foreach ($playlists as &$playlist) { $scheduleGroup = new ScheduleGroup($playlist["schedule_id"]); $items = $scheduleGroup->getItems(); $medias = array(); foreach ($items as $item) { $storedFile = StoredFile::Recall($item["file_id"]); $uri = $storedFile->getFileUrl(); $starts = Schedule::AirtimeTimeToPypoTime($item["starts"]); $medias[$starts] = array('row_id' => $item["id"], 'id' => $storedFile->getGunid(), 'uri' => $uri, 'fade_in' => Schedule::WallTimeToMillisecs($item["fade_in"]), 'fade_out' => Schedule::WallTimeToMillisecs($item["fade_out"]), 'fade_cross' => 0, 'cue_in' => DateHelper::CalculateLengthInSeconds($item["cue_in"]), 'cue_out' => DateHelper::CalculateLengthInSeconds($item["cue_out"]), 'export_source' => 'scheduler', 'start' => $starts, 'end' => Schedule::AirtimeTimeToPypoTime($item["ends"])); } $playlist['medias'] = $medias; } $result = array(); $result['status'] = array('range' => array('start' => $range_start, 'end' => $range_end), 'version' => AIRTIME_REST_VERSION); $result['playlists'] = $playlists; $result['check'] = 1; $result['stream_metadata'] = array(); $result['stream_metadata']['format'] = Application_Model_Preference::GetStreamLabelFormat(); $result['stream_metadata']['station_name'] = Application_Model_Preference::GetStationName(); $result['server_timezone'] = date('O'); return $result; }
/** * Add a media file as the last item in the show. * * @param int $file_id */ public function addFileToShow($file_id) { $sched = new ScheduleGroup(); $lastGroupId = $this->getLastGroupId(); if (is_null($lastGroupId)) { $groupId = $sched->add($this->_instanceId, $this->getShowStart(), $file_id); } else { $groupId = $sched->addFileAfter($this->_instanceId, $lastGroupId, $file_id); } RabbitMq::PushSchedule(); $this->updateScheduledTime(); }
public function notifyScheduleGroupPlayAction() { global $CC_CONFIG; // disable the view and the layout $this->view->layout()->disableLayout(); $this->_helper->viewRenderer->setNoRender(true); $api_key = $this->_getParam('api_key'); if (!in_array($api_key, $CC_CONFIG["apiKey"])) { header('HTTP/1.0 401 Unauthorized'); print 'You are not allowed to access this resource.'; exit; } PEAR::setErrorHandling(PEAR_ERROR_RETURN); $schedule_group_id = $this->_getParam("schedule_id"); if (is_numeric($schedule_group_id)) { $sg = new ScheduleGroup($schedule_group_id); if ($sg->exists()) { $result = $sg->notifyGroupStartPlay(); if (!PEAR::isError($result)) { echo json_encode(array("status" => 1, "message" => "")); exit; } else { echo json_encode(array("status" => 0, "message" => "DB Error:" . $result->getMessage())); exit; } } else { echo json_encode(array("status" => 0, "message" => "Schedule group does not exist: " . $schedule_group_id)); exit; } } else { echo json_encode(array("status" => 0, "message" => "Incorrect or non-numeric arguments given.")); exit; } }