Merge branch 'master' of dev.sourcefabric.org:airtime

This commit is contained in:
denise 2013-05-09 15:53:24 -04:00
commit b7337d0df3
4 changed files with 77 additions and 49 deletions

View file

@ -418,7 +418,6 @@ SQL;
public static function UpdateMediaPlayedStatus($p_id) public static function UpdateMediaPlayedStatus($p_id)
{ {
$con = Propel::getConnection();
$sql = "UPDATE cc_schedule" $sql = "UPDATE cc_schedule"
." SET media_item_played=TRUE"; ." SET media_item_played=TRUE";
// we need to update 'broadcasted' column as well // we need to update 'broadcasted' column as well
@ -431,11 +430,11 @@ SQL;
$sql .= ", broadcasted=1"; $sql .= ", broadcasted=1";
} }
$sql .= " WHERE id=$p_id"; $sql .= " WHERE id=:pid";
$map = array(":pid" => $p_id);
$retVal = $con->exec($sql); Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
return $retVal;
} }
public static function UpdateBrodcastedStatus($dateTime, $value) public static function UpdateBrodcastedStatus($dateTime, $value)
@ -952,8 +951,9 @@ SQL;
public static function deleteAll() public static function deleteAll()
{ {
$con = Propel::getConnection(); $sql = "TRUNCATE TABLE cc_schedule";
$con->exec("TRUNCATE TABLE cc_schedule"); Application_Common_Database::prepareAndExecute($sql, array(),
Application_Common_Database::EXECUTE);
} }
public static function deleteWithFileId($fileId) public static function deleteWithFileId($fileId)

View file

@ -602,8 +602,6 @@ SQL;
Application_Common_Database::prepareAndExecute( $sql, Application_Common_Database::prepareAndExecute( $sql,
array( ':showId' => $this->getId(), array( ':showId' => $this->getId(),
':timestamp' => gmdate("Y-m-d H:i:s")), 'execute'); ':timestamp' => gmdate("Y-m-d H:i:s")), 'execute');
$con->exec($sql);
} }
/** /**
@ -617,8 +615,6 @@ SQL;
*/ */
public function removeAllInstancesFromDate($p_date=null) public function removeAllInstancesFromDate($p_date=null)
{ {
$con = Propel::getConnection();
$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)) {
@ -628,12 +624,16 @@ SQL;
$showId = $this->getId(); $showId = $this->getId();
$sql = "DELETE FROM cc_show_instances " $sql = "DELETE FROM cc_show_instances "
." WHERE date(starts) >= DATE '$p_date'" ." WHERE date(starts) >= :date::date"
." AND starts > TIMESTAMP '$timestamp'" ." AND starts > :timestamp::timestamp"
." AND show_id = $showId"; ." AND show_id = :showId";
$con->exec($sql); $map = array(":date"=>$p_date,
':timestamp'=>$timestamp,
':showId'=>$showId);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
} }
/** /**
@ -650,17 +650,20 @@ SQL;
*/ */
public function removeAllInstancesBeforeDate($p_date) public function removeAllInstancesBeforeDate($p_date)
{ {
$con = Propel::getConnection();
$timestamp = gmdate("Y-m-d H:i:s"); $timestamp = gmdate("Y-m-d H:i:s");
$showId = $this->getId(); $showId = $this->getId();
$sql = "DELETE FROM cc_show_instances " $sql = "DELETE FROM cc_show_instances "
." WHERE date(starts) < DATE '$p_date'" ." WHERE date(starts) < :date::date"
." AND starts > TIMESTAMP '$timestamp'" ." AND starts > :timestamp::timestamp"
." AND show_id = $showId"; ." AND show_id = :showId";
$con->exec($sql); $map = array(":date"=>$p_date,
":timestamp"=>$timestamp,
":showId"=>$showId);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
} }
public function getNextFutureRepeatShowTime() public function getNextFutureRepeatShowTime()
@ -870,43 +873,62 @@ SQL;
private function updateStartDateTime($p_data, $p_endDate) private function updateStartDateTime($p_data, $p_endDate)
{ {
//need to update cc_schedule, cc_show_instances, cc_show_days
$con = Propel::getConnection();
$date = new Application_Common_DateHelper; $date = new Application_Common_DateHelper;
$timestamp = $date->getTimestamp(); $timestamp = $date->getTimestamp();
//TODO fix this from overwriting info. //TODO fix this from overwriting info.
$sql = "UPDATE cc_show_days " $sql = "UPDATE cc_show_days "
."SET start_time = TIME '$p_data[add_show_start_time]', " ."SET start_time = :start_time::time, "
."first_show = DATE '$p_data[add_show_start_date]', "; ."first_show = :start_date::date, ";
if (strlen ($p_endDate) == 0) { if (strlen ($p_endDate) == 0) {
$sql .= "last_show = NULL "; $sql .= "last_show = NULL ";
} else { } else {
$sql .= "last_show = DATE '$p_endDate' "; $sql .= "last_show = :end_date::date";
} }
$sql .= "WHERE show_id = $p_data[add_show_id]"; $sql .= "WHERE show_id = :show_id";
$con->exec($sql);
$map = array(":start_time" => $p_data['add_show_start_time'],
':start_date' => $p_data['add_show_start_date'],
':end_date' => $p_endDate,
':show_id' => $p_data['add_show_id'],
);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
$dtOld = new DateTime($this->getStartDate()." ".$this->getStartTime(), new DateTimeZone("UTC")); $dtOld = new DateTime($this->getStartDate()." ".$this->getStartTime(), new DateTimeZone("UTC"));
$dtNew = new DateTime($p_data['add_show_start_date']." ".$p_data['add_show_start_time'], new DateTimeZone(date_default_timezone_get())); $dtNew = new DateTime($p_data['add_show_start_date']." ".$p_data['add_show_start_time'],
new DateTimeZone(date_default_timezone_get()));
$diff = $dtOld->getTimestamp() - $dtNew->getTimestamp(); $diff = $dtOld->getTimestamp() - $dtNew->getTimestamp();
$sql = "UPDATE cc_show_instances " $sql = "UPDATE cc_show_instances "
."SET starts = starts + INTERVAL '$diff sec', " ."SET starts = starts + :diff1::interval, "
."ends = ends + INTERVAL '$diff sec' " ."ends = ends + :diff2::interval "
."WHERE show_id = $p_data[add_show_id] " ."WHERE show_id = :show_id "
."AND starts > TIMESTAMP '$timestamp'"; ."AND starts > :timestamp::timestamp";
$con->exec($sql); $map = array(
":diff1"=>"$diff sec",
":diff2"=>"$diff sec",
":show_id"=>$p_data['add_show_id'],
":timestamp"=>$timestamp,
);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
$showInstanceIds = $this->getAllFutureInstanceIds(); $showInstanceIds = $this->getAllFutureInstanceIds();
if (count($showInstanceIds) > 0 && $diff != 0) { if (count($showInstanceIds) > 0 && $diff != 0) {
$showIdsImploded = implode(",", $showInstanceIds); $showIdsImploded = implode(",", $showInstanceIds);
$sql = "UPDATE cc_schedule " $sql = "UPDATE cc_schedule "
."SET starts = starts + INTERVAL '$diff sec', " ."SET starts = starts + :diff1::interval, "
."ends = ends + INTERVAL '$diff sec' " ."ends = ends + :diff2::interval "
."WHERE instance_id IN ($showIdsImploded)"; ."WHERE instance_id IN (:show_ids)";
$con->exec($sql); $map = array(
":diff1"=>"$diff sec",
":diff2"=>"$diff sec",
":show_ids"=>$showIdsImploded,
);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
} }
} }

View file

@ -265,11 +265,12 @@ class Application_Model_StreamSetting
*/ */
public static function setIndividualStreamSetting($data) public static function setIndividualStreamSetting($data)
{ {
$con = Propel::getConnection();
foreach ($data as $keyname => $v) { foreach ($data as $keyname => $v) {
$sql = "UPDATE cc_stream_setting SET value='$v' WHERE keyname='$keyname'"; $sql = "UPDATE cc_stream_setting SET value=:v WHERE keyname=:keyname";
$con->exec($sql); $map = array(":v" => $v, ":keyname"=>$keyname);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
} }
} }

View file

@ -20,20 +20,25 @@ class Application_Model_Subjects
public static function increaseLoginAttempts($login) public static function increaseLoginAttempts($login)
{ {
$con = Propel::getConnection();
$sql = "UPDATE cc_subjs SET login_attempts = login_attempts+1" $sql = "UPDATE cc_subjs SET login_attempts = login_attempts+1"
." WHERE login='$login'"; ." WHERE login=:login";
$res = $con->exec($sql);
$map = array(":login" => $login);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
return (intval($res) > 0); return (intval($res) > 0);
} }
public static function resetLoginAttempts($login) public static function resetLoginAttempts($login)
{ {
$con = Propel::getConnection();
$sql = "UPDATE cc_subjs SET login_attempts = '0'" $sql = "UPDATE cc_subjs SET login_attempts = '0'"
." WHERE login='$login'"; ." WHERE login=:login";
$res = $con->exec($sql); $map = array(":login" => $login);
$res = Application_Common_Database::prepareAndExecute($sql, $map,
Application_Common_Database::EXECUTE);
return true; return true;
} }