Merge branch 'devel' of dev.sourcefabric.org:airtime into devel

This commit is contained in:
denise 2012-04-13 18:06:16 -04:00
commit c61f74b06f
8 changed files with 86 additions and 39 deletions

View File

@ -1,6 +1,6 @@
<?php <?php
class Application_Model_DateHelper class Application_Common_DateHelper
{ {
private $_dateTime; private $_dateTime;
@ -83,8 +83,8 @@ class Application_Model_DateHelper
} }
public static function GetDayEndTimestampInUtc($time = "") { public static function GetDayEndTimestampInUtc($time = "") {
$dayEndTimestamp = Application_Model_DateHelper::GetDayEndTimestamp($time); $dayEndTimestamp = Application_Common_DateHelper::GetDayEndTimestamp($time);
return Application_Model_DateHelper::ConvertToUtcDateTimeString($dayEndTimestamp); return Application_Common_DateHelper::ConvertToUtcDateTimeString($dayEndTimestamp);
} }
/** /**

View File

@ -0,0 +1,45 @@
<?php
class Application_Common_OsPath{
// this function is from http://stackoverflow.com/questions/2670299/is-there-a-php-equivalent-function-to-the-python-os-path-normpath
public static function normpath($path)
{
if (empty($path))
return '.';
if (strpos($path, '/') === 0)
$initial_slashes = true;
else
$initial_slashes = false;
if (
($initial_slashes) &&
(strpos($path, '//') === 0) &&
(strpos($path, '///') === false)
)
$initial_slashes = 2;
$initial_slashes = (int) $initial_slashes;
$comps = explode('/', $path);
$new_comps = array();
foreach ($comps as $comp)
{
if (in_array($comp, array('', '.')))
continue;
if (
($comp != '..') ||
(!$initial_slashes && !$new_comps) ||
($new_comps && (end($new_comps) == '..'))
)
array_push($new_comps, $comp);
elseif ($new_comps)
array_pop($new_comps);
}
$comps = $new_comps;
$path = implode('/', $comps);
if ($initial_slashes)
$path = str_repeat('/', $initial_slashes) . $path;
if ($path)
return $path;
else
return '.';
}
}

View File

@ -258,7 +258,7 @@ class ApiController extends Zend_Controller_Action
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
$date = new Application_Model_DateHelper; $date = new Application_Common_DateHelper;
$utcTimeNow = $date->getUtcTimestamp(); $utcTimeNow = $date->getUtcTimestamp();
$utcTimeEnd = ""; // if empty, GetNextShows will use interval instead of end of day $utcTimeEnd = ""; // if empty, GetNextShows will use interval instead of end of day
@ -266,7 +266,7 @@ class ApiController extends Zend_Controller_Action
$type = $request->getParam('type'); $type = $request->getParam('type');
if($type == "endofday") { if($type == "endofday") {
// make GetNextShows use end of day // make GetNextShows use end of day
$utcTimeEnd = Application_Model_DateHelper::GetDayEndTimestampInUtc(); $utcTimeEnd = Application_Common_DateHelper::GetDayEndTimestampInUtc();
} }
$limit = $request->getParam('limit'); $limit = $request->getParam('limit');
@ -298,15 +298,15 @@ class ApiController extends Zend_Controller_Action
$this->view->layout()->disableLayout(); $this->view->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true); $this->_helper->viewRenderer->setNoRender(true);
$date = new Application_Model_DateHelper; $date = new Application_Common_DateHelper;
$dayStart = $date->getWeekStartDate(); $dayStart = $date->getWeekStartDate();
$utcDayStart = Application_Model_DateHelper::ConvertToUtcDateTimeString($dayStart); $utcDayStart = Application_Common_DateHelper::ConvertToUtcDateTimeString($dayStart);
$dow = array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday"); $dow = array("sunday", "monday", "tuesday", "wednesday", "thursday", "friday", "saturday");
$result = array(); $result = array();
for ($i=0; $i<7; $i++){ for ($i=0; $i<7; $i++){
$utcDayEnd = Application_Model_DateHelper::GetDayEndTimestamp($utcDayStart); $utcDayEnd = Application_Common_DateHelper::GetDayEndTimestamp($utcDayStart);
$shows = Application_Model_Show::GetNextShows($utcDayStart, "0", $utcDayEnd); $shows = Application_Model_Show::GetNextShows($utcDayStart, "0", $utcDayEnd);
$utcDayStart = $utcDayEnd; $utcDayStart = $utcDayEnd;
@ -394,8 +394,8 @@ class ApiController extends Zend_Controller_Action
$end_timestamp = $now->add(new DateInterval("PT2H")); $end_timestamp = $now->add(new DateInterval("PT2H"));
$end_timestamp = $end_timestamp->format("Y-m-d H:i:s"); $end_timestamp = $end_timestamp->format("Y-m-d H:i:s");
$this->view->shows = Application_Model_Show::getShows(Application_Model_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()), $this->view->shows = Application_Model_Show::getShows(Application_Common_DateHelper::ConvertToUtcDateTime($today_timestamp, date_default_timezone_get()),
Application_Model_DateHelper::ConvertToUtcDateTime($end_timestamp, date_default_timezone_get()), Application_Common_DateHelper::ConvertToUtcDateTime($end_timestamp, date_default_timezone_get()),
$excludeInstance=NULL, $onlyRecord=TRUE); $excludeInstance=NULL, $onlyRecord=TRUE);
@ -467,7 +467,7 @@ class ApiController extends Zend_Controller_Action
$show_inst->setRecordedFile($file_id); $show_inst->setRecordedFile($file_id);
$show_name = $show_inst->getName(); $show_name = $show_inst->getName();
$show_genre = $show_inst->getGenre(); $show_genre = $show_inst->getGenre();
$show_start_time = Application_Model_DateHelper::ConvertToLocalDateTimeString($show_inst->getShowInstanceStart()); $show_start_time = Application_Common_DateHelper::ConvertToLocalDateTimeString($show_inst->getShowInstanceStart());
} catch (Exception $e){ } catch (Exception $e){
//we've reached here probably because the show was //we've reached here probably because the show was

View File

@ -224,8 +224,8 @@ class ScheduleController extends Zend_Controller_Action
$isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER)); $isAdminOrPM = $user->isUserType(array(UTYPE_ADMIN, UTYPE_PROGRAM_MANAGER));
$isDJ = $user->isHost($instance->getShowId()); $isDJ = $user->isHost($instance->getShowId());
$showStartLocalDT = Application_Model_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceStart()); $showStartLocalDT = Application_Common_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceStart());
$showEndLocalDT = Application_Model_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceEnd()); $showEndLocalDT = Application_Common_DateHelper::ConvertToLocalDateTime($instance->getShowInstanceEnd());
if ($epochNow < $showStartLocalDT->getTimestamp()) { if ($epochNow < $showStartLocalDT->getTimestamp()) {
@ -338,16 +338,16 @@ class ScheduleController extends Zend_Controller_Action
/* Convert all UTC times to localtime before sending back to user. */ /* Convert all UTC times to localtime before sending back to user. */
if (isset($range["previous"])){ if (isset($range["previous"])){
$range["previous"]["starts"] = Application_Model_DateHelper::ConvertToLocalDateTimeString($range["previous"]["starts"]); $range["previous"]["starts"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["previous"]["starts"]);
$range["previous"]["ends"] = Application_Model_DateHelper::ConvertToLocalDateTimeString($range["previous"]["ends"]); $range["previous"]["ends"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["previous"]["ends"]);
} }
if (isset($range["current"])){ if (isset($range["current"])){
$range["current"]["starts"] = Application_Model_DateHelper::ConvertToLocalDateTimeString($range["current"]["starts"]); $range["current"]["starts"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["current"]["starts"]);
$range["current"]["ends"] = Application_Model_DateHelper::ConvertToLocalDateTimeString($range["current"]["ends"]); $range["current"]["ends"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["current"]["ends"]);
} }
if (isset($range["next"])){ if (isset($range["next"])){
$range["next"]["starts"] = Application_Model_DateHelper::ConvertToLocalDateTimeString($range["next"]["starts"]); $range["next"]["starts"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["next"]["starts"]);
$range["next"]["ends"] = Application_Model_DateHelper::ConvertToLocalDateTimeString($range["next"]["ends"]); $range["next"]["ends"] = Application_Common_DateHelper::ConvertToLocalDateTimeString($range["next"]["ends"]);
} }
Application_Model_Show::ConvertToLocalTimeZone($range["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp")); Application_Model_Show::ConvertToLocalTimeZone($range["currentShow"], array("starts", "ends", "start_timestamp", "end_timestamp"));
@ -425,7 +425,7 @@ class ScheduleController extends Zend_Controller_Action
//convert from UTC to user's timezone for display. //convert from UTC to user's timezone for display.
$originalDateTime = new DateTime($originalShowStart, new DateTimeZone("UTC")); $originalDateTime = new DateTime($originalShowStart, new DateTimeZone("UTC"));
$originalDateTime->setTimezone(new DateTimeZone(date_default_timezone_get())); $originalDateTime->setTimezone(new DateTimeZone(date_default_timezone_get()));
//$timestamp = Application_Model_DateHelper::ConvertToLocalDateTimeString($originalDateTime->format("Y-m-d H:i:s")); //$timestamp = Application_Common_DateHelper::ConvertToLocalDateTimeString($originalDateTime->format("Y-m-d H:i:s"));
$this->view->additionalShowInfo = $this->view->additionalShowInfo =
"Rebroadcast of show \"$originalShowName\" from " "Rebroadcast of show \"$originalShowName\" from "
.$originalDateTime->format("l, F jS")." at ".$originalDateTime->format("G:i"); .$originalDateTime->format("l, F jS")." at ".$originalDateTime->format("G:i");
@ -643,7 +643,7 @@ class ScheduleController extends Zend_Controller_Action
$i = 1; $i = 1;
foreach ($rebroadcastsRelative as $rebroadcast){ foreach ($rebroadcastsRelative as $rebroadcast){
$rebroadcastFormValues["add_show_rebroadcast_date_$i"] = $rebroadcast['day_offset']; $rebroadcastFormValues["add_show_rebroadcast_date_$i"] = $rebroadcast['day_offset'];
$rebroadcastFormValues["add_show_rebroadcast_time_$i"] = Application_Model_DateHelper::removeSecondsFromTime($rebroadcast['start_time']); $rebroadcastFormValues["add_show_rebroadcast_time_$i"] = Application_Common_DateHelper::removeSecondsFromTime($rebroadcast['start_time']);
$i++; $i++;
} }
$formRebroadcast->populate($rebroadcastFormValues); $formRebroadcast->populate($rebroadcastFormValues);
@ -761,7 +761,7 @@ class ScheduleController extends Zend_Controller_Action
//Changing the start date was disabled, since the //Changing the start date was disabled, since the
//array key does not exist. We need to repopulate this entry from the db. //array key does not exist. We need to repopulate this entry from the db.
//The start date will be returned in UTC time, so lets convert it to local time. //The start date will be returned in UTC time, so lets convert it to local time.
$dt = Application_Model_DateHelper::ConvertToLocalDateTime($show->getStartDate()); $dt = Application_Common_DateHelper::ConvertToLocalDateTime($show->getStartDate());
$data['add_show_start_date'] = $dt->format("Y-m-d"); $data['add_show_start_date'] = $dt->format("Y-m-d");
$validateStartDate = false; $validateStartDate = false;
} }

View File

@ -175,7 +175,7 @@ class Application_Model_MusicDir {
if(!is_dir($p_path)){ if(!is_dir($p_path)){
return array("code"=>2, "error"=>"'$p_path' is not a valid directory."); return array("code"=>2, "error"=>"'$p_path' is not a valid directory.");
} }
$real_path = realpath($p_path)."/"; $real_path = Application_Common_OsPath::normpath($p_path)."/";
if($real_path != "/"){ if($real_path != "/"){
$p_path = $real_path; $p_path = $real_path;
} }
@ -190,7 +190,7 @@ class Application_Model_MusicDir {
} }
$dir->setType($p_type); $dir->setType($p_type);
$p_path = realpath($p_path)."/"; $p_path = Application_Common_OsPath::normpath($p_path)."/";
try { try {
@ -245,7 +245,7 @@ class Application_Model_MusicDir {
//newly added watched directory object //newly added watched directory object
$propel_new_watch = CcMusicDirsQuery::create() $propel_new_watch = CcMusicDirsQuery::create()
->filterByDirectory(realpath($p_path)."/") ->filterByDirectory(Application_Common_OsPath::normpath($p_path)."/")
->findOne(); ->findOne();
//any files of the deprecated "link" type. //any files of the deprecated "link" type.
@ -344,7 +344,7 @@ class Application_Model_MusicDir {
{ {
// we want to be consistent when storing dir path. // we want to be consistent when storing dir path.
// path should always ends with trailing '/' // path should always ends with trailing '/'
$p_dir = realpath($p_dir)."/"; $p_dir = Application_Common_OsPath::normpath($p_dir)."/";
if(!is_dir($p_dir)){ if(!is_dir($p_dir)){
return array("code"=>2, "error"=>"'$p_dir' is not a valid directory."); return array("code"=>2, "error"=>"'$p_dir' is not a valid directory.");
}else if(Application_Model_Preference::GetImportTimestamp()+10 > time()){ }else if(Application_Model_Preference::GetImportTimestamp()+10 > time()){
@ -396,7 +396,7 @@ class Application_Model_MusicDir {
* otherwise, it will set "Exists" flag to true * otherwise, it will set "Exists" flag to true
**/ **/
public static function removeWatchedDir($p_dir, $userAddedWatchedDir=true){ public static function removeWatchedDir($p_dir, $userAddedWatchedDir=true){
$real_path = realpath($p_dir)."/"; $real_path = Application_Common_OsPath::normpath($p_dir)."/";
if($real_path != "/"){ if($real_path != "/"){
$p_dir = $real_path; $p_dir = $real_path;
} }

View File

@ -34,7 +34,7 @@ class Application_Model_Schedule {
return array(); return array();
} }
$date = new Application_Model_DateHelper; $date = new Application_Common_DateHelper;
$timeNow = $date->getTimestamp(); $timeNow = $date->getTimestamp();
$utcTimeNow = $date->getUtcTimestamp(); $utcTimeNow = $date->getUtcTimestamp();
@ -563,8 +563,8 @@ class Application_Model_Schedule {
'uri' => $uri, 'uri' => $uri,
'fade_in' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_in"]), 'fade_in' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_in"]),
'fade_out' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_out"]), 'fade_out' => Application_Model_Schedule::WallTimeToMillisecs($item["fade_out"]),
'cue_in' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_in"]), 'cue_in' => Application_Common_DateHelper::CalculateLengthInSeconds($item["cue_in"]),
'cue_out' => Application_Model_DateHelper::CalculateLengthInSeconds($item["cue_out"]), 'cue_out' => Application_Common_DateHelper::CalculateLengthInSeconds($item["cue_out"]),
'start' => $start, 'start' => $start,
'end' => Application_Model_Schedule::AirtimeTimeToPypoTime($item["end"]), 'end' => Application_Model_Schedule::AirtimeTimeToPypoTime($item["end"]),
'show_name' => $showName 'show_name' => $showName

View File

@ -520,7 +520,7 @@ class Application_Model_Show {
$timestamp = gmdate("Y-m-d H:i:s"); $timestamp = gmdate("Y-m-d H:i:s");
if(is_null($p_date)) { if(is_null($p_date)) {
$date = new Application_Model_DateHelper; $date = new Application_Common_DateHelper;
$p_date = $date->getDate(); $p_date = $date->getDate();
} }
@ -663,7 +663,7 @@ class Application_Model_Show {
* true if the StartDate is in the past, false otherwise * true if the StartDate is in the past, false otherwise
*/ */
public function isStartDateTimeInPast(){ public function isStartDateTimeInPast(){
$date = new Application_Model_DateHelper; $date = new Application_Common_DateHelper;
$current_timestamp = $date->getUtcTimestamp(); $current_timestamp = $date->getUtcTimestamp();
return ($current_timestamp > ($this->getStartDate()." ".$this->getStartTime())); return ($current_timestamp > ($this->getStartDate()." ".$this->getStartTime()));
} }
@ -678,7 +678,7 @@ class Application_Model_Show {
public function getAllFutureInstanceIds(){ public function getAllFutureInstanceIds(){
global $CC_DBC; global $CC_DBC;
$date = new Application_Model_DateHelper; $date = new Application_Common_DateHelper;
$timestamp = $date->getTimestamp(); $timestamp = $date->getTimestamp();
$showId = $this->getId(); $showId = $this->getId();
@ -708,7 +708,7 @@ class Application_Model_Show {
global $CC_DBC; global $CC_DBC;
$date = new Application_Model_DateHelper; $date = new Application_Common_DateHelper;
$timestamp = $date->getTimestamp(); $timestamp = $date->getTimestamp();
$sql = "UPDATE cc_show_days " $sql = "UPDATE cc_show_days "
@ -729,7 +729,7 @@ class Application_Model_Show {
global $CC_DBC; global $CC_DBC;
$date = new Application_Model_DateHelper; $date = new Application_Common_DateHelper;
$timestamp = $date->getTimestamp(); $timestamp = $date->getTimestamp();
//TODO fix this from overwriting info. //TODO fix this from overwriting info.
@ -1313,9 +1313,9 @@ class Application_Model_Show {
$start = $first_show." ".$start_time; $start = $first_show." ".$start_time;
} }
$utcStartDateTime = Application_Model_DateHelper::ConvertToUtcDateTime($start, $timezone); $utcStartDateTime = Application_Common_DateHelper::ConvertToUtcDateTime($start, $timezone);
//convert $last_show into a UTC DateTime object, or null if there is no last show. //convert $last_show into a UTC DateTime object, or null if there is no last show.
$utcLastShowDateTime = $last_show ? Application_Model_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null; $utcLastShowDateTime = $last_show ? Application_Common_DateHelper::ConvertToUtcDateTime($last_show, $timezone) : null;
$sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}"; $sql = "SELECT * FROM cc_show_rebroadcast WHERE show_id={$show_id}";
$rebroadcasts = $CC_DBC->GetAll($sql); $rebroadcasts = $CC_DBC->GetAll($sql);
@ -1736,7 +1736,7 @@ class Application_Model_Show {
{ {
global $CC_CONFIG, $CC_DBC; global $CC_CONFIG, $CC_DBC;
if($timeNow == null){ if($timeNow == null){
$date = new Application_Model_DateHelper; $date = new Application_Common_DateHelper;
$timeNow = $date->getUtcTimestamp(); $timeNow = $date->getUtcTimestamp();
} }
//TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin //TODO, returning starts + ends twice (once with an alias). Unify this after the 2.0 release. --Martin
@ -1896,7 +1896,7 @@ class Application_Model_Show {
} }
foreach($rows as &$row) { foreach($rows as &$row) {
foreach($columnsToConvert as $column) { foreach($columnsToConvert as $column) {
$row[$column] = Application_Model_DateHelper::ConvertToLocalDateTimeString($row[$column]); $row[$column] = Application_Common_DateHelper::ConvertToLocalDateTimeString($row[$column]);
} }
} }
} }

View File

@ -18,6 +18,8 @@ set_include_path(implode(PATH_SEPARATOR, array(
realpath(APPLICATION_PATH . '/../library') realpath(APPLICATION_PATH . '/../library')
))); )));
set_include_path(APPLICATION_PATH . '/common' . PATH_SEPARATOR . get_include_path());
//Propel classes. //Propel classes.
set_include_path(APPLICATION_PATH . '/models' . PATH_SEPARATOR . get_include_path()); set_include_path(APPLICATION_PATH . '/models' . PATH_SEPARATOR . get_include_path());