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

Conflicts:
	airtime_mvc/application/models/User.php
This commit is contained in:
Martin Konecny 2012-09-06 12:55:24 -04:00
commit a941743ed7
9 changed files with 145 additions and 229 deletions

View File

@ -1,7 +1,8 @@
<?php
class Application_Common_Database
{
public static function prepareAndExecute($sql, array $paramValueMap, $type='all', $fetchType=PDO::FETCH_ASSOC)
public static function prepareAndExecute($sql, array $paramValueMap,
$type='all', $fetchType=PDO::FETCH_ASSOC)
{
$con = Propel::getConnection();
$stmt = $con->prepare($sql);

View File

@ -447,7 +447,7 @@ class PlaylistController extends Zend_Controller_Action
} catch (PlaylistOutDatedException $e) {
$this->playlistOutdated($e);
} catch (PlaylistNotFoundException $e) {
$this->playlistNotFound($type);
$this->playlistNotFound($type, true);
} catch (Exception $e) {
$this->playlistUnknownError($e);
}

View File

@ -781,7 +781,10 @@ class ScheduleController extends Zend_Controller_Action
$data['add_show_record'] = $show->isRecorded();
$origianlShowStartDateTime = Application_Common_DateHelper::ConvertToLocalDateTime($show->getStartDateAndTime());
$success = Application_Model_Schedule::addUpdateShow($data, $this, $validateStartDate, $origianlShowStartDateTime, true, $data['add_show_instance_id']);
$success = Application_Model_Schedule::addUpdateShow($data, $this,
$validateStartDate, $origianlShowStartDateTime, true,
$data['add_show_instance_id']);
if ($success) {
$this->view->addNewShow = true;
@ -810,22 +813,29 @@ class ScheduleController extends Zend_Controller_Action
$data[$j["name"]] = $j["value"];
}
$data['add_show_hosts'] = $this->_getParam('hosts');
$data['add_show_day_check'] = $this->_getParam('days');
$data['add_show_hosts'] = $this->_getParam('hosts');
$data['add_show_day_check'] = $this->_getParam('days');
if ($data['add_show_day_check'] == "") {
$data['add_show_day_check'] = null;
}
$validateStartDate = true;
$success = Application_Model_Schedule::addUpdateShow($data, $this, $validateStartDate);
$success = Application_Model_Schedule::addUpdateShow($data, $this,
$validateStartDate);
if ($success) {
$this->view->addNewShow = true;
$this->view->newForm = $this->view->render('schedule/add-show-form.phtml');
$this->view->newForm = $this->view->render(
'schedule/add-show-form.phtml');
Logging::debug("Show creation succeeded");
Logging::debug_sparse( $data );
} else {
$this->view->addNewShow = true;
$this->view->form = $this->view->render('schedule/add-show-form.phtml');
$this->view->form = $this->view->render(
'schedule/add-show-form.phtml');
Logging::debug("Show creation failed");
Logging::debug_sparse( $data );
}
}

View File

@ -69,6 +69,10 @@ class Logging {
public static function debug($p_msg)
{
if (!(defined('APPLICATION_ENV') && APPLICATION_ENV == "development")) {
return;
}
$bt = debug_backtrace();
$caller = array_shift($bt);
@ -78,11 +82,16 @@ class Logging {
$caller = array_shift($bt);
$function = $caller['function'];
if (defined('APPLICATION_ENV') && APPLICATION_ENV == "development") {
$logger = self::getLogger();
$logger->debug("[$file : $function() : line $line] - ".self::toString($p_msg));
}
$logger = self::getLogger();
$logger->debug("[$file : $function() : line $line] - ".self::toString($p_msg));
}
// kind of like debug but for printing arrays more compactly (skipping
// empty elements
public static function debug_sparse(array $p_msg)
{
Logging::debug("Sparse output:");
Logging::debug( array_filter($p_msg) );
}
public static function enablePropelLogging()

View File

@ -199,16 +199,8 @@ class Application_Model_Block implements Application_Model_LibraryEditable
WHERE pc.block_id = :block_id
ORDER BY pc.position;
EOT;
$con = Propel::getConnection();
$stmt = $con->prepare($sql);
$stmt->bindParam(':block_id', $this->id);
if ($stmt->execute()) {
$rows = $stmt->fetchAll();
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$rows = Application_Common_Database::prepareAndExecute($sql, array(':block_id'=>$this->id));
$offset = 0;
foreach ($rows as &$row) {
@ -332,15 +324,8 @@ EOT;
public function getStaticLength()
{
$sql = "SELECT SUM(cliplength) as length FROM cc_blockcontents WHERE block_id = :block_id";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':block_id', $this->id);
if ($stmt->execute()) {
$result = $stmt->fetchAll(PDO::FETCH_NUM);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("error: $msg");
}
$result = Application_Common_Database::prepareAndExecute($sql, array(':block_id'=>$this->id), 'all', PDO::FETCH_NUM);
Logging::info($result);
return $result[0][0];
}
@ -653,39 +638,31 @@ EOT;
if (!is_null($fadeIn)) {
$sql = "SELECT :fade_in::INTERVAL > :clip_length::INTERVAL";
$params = array(
':fade_in' => $fadeIn,
':clip_length' => $clipLength
);
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':fade_in', $fadeIn);
$stmt->bindParam(':clip_length', $clipLength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
//"Fade In can't be larger than overall playlength.";
$fadeIn = $clipLength;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
if ($result) {
//"Fade In can't be larger than overall playlength.";
$fadeIn = $clipLength;
}
$row->setDbFadein($fadeIn);
}
if (!is_null($fadeOut)) {
$sql = "SELECT :fade_out::INTERVAL > :clip_length::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':fade_out', $fadeOut);
$stmt->bindParam(':clip_length', $clipLength);
$params = array(
':fade_out' => $fadeOut,
':clip_length' => $clipLength
);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
//Fade Out can't be larger than overall playlength.";
$fadeOut = $clipLength;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
if ($result) {
//"Fade Out can't be larger than overall playlength.";
$fadeOut = $clipLength;
}
$row->setDbFadeout($fadeOut);
}
@ -773,52 +750,31 @@ EOT;
$cueOut = $origLength;
}
$sql = "SELECT :cue_in::INTERVAL > :cue_out::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_in', $cueIn);
$stmt->bindParam(':cue_out', $cueOut);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
$sql = "SELECT :cue_out::INTERVAL > :orig_length::INTERVAL";
$params = array(
':cue_out' => $cueOut,
':orig_length' => $origLength
);
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
if ($result) {
$errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray;
}
$sql = "SELECT :cue_out::INTERVAL > INTERVAL :orig_length::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':orig_length', $origLength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
$sql = "SELECT :cue_in::INTERVAL > :cue_out::INTERVAL";
$params = array(
':cue_in' => $cueIn,
':cue_out' => $cueOut
);
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
if ($result) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray;
}
$sql = "SELECT :cue_out::INTERVAL - :cue_in::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':cue_in', $cueIn);
if ($stmt->execute()) {
$cliplength = $stmt->fetchColumn(0);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
$cliplength = $result;
$row->setDbCuein($cueIn);
$row->setDbCueout($cueOut);
@ -827,89 +783,54 @@ EOT;
} elseif (!is_null($cueIn)) {
$sql = "SELECT :cue_in::INTERVAL > :old_cue_out::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_in', $cueIn);
$stmt->bindParam(':old_cue_out', $oldCueOut);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
$params = array(
':cue_in' => $cueIn,
':old_cue_out' => $oldCueOut
);
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
if ($result) {
$errArray["error"] = "Can't set cue in to be larger than cue out.";
return $errArray;
}
$sql = "SELECT :old_cue_out::INTERVAL - :cue_in::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':old_cue_out', $oldCueOut);
$stmt->bindParam(':cue_in', $cueIn);
if ($stmt->execute()) {
$cliplength = $stmt->fetchColumn(0);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
$cliplength = $result;
$row->setDbCuein($cueIn);
$row->setDBCliplength($cliplength);
} elseif (!is_null($cueOut)) {
if ($cueOut === "") {
$cueOut = $origLength;
}
$sql = "SELECT :cue_out::INTERVAL < :old_cue_in::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':old_cue_in', $oldCueIn);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be smaller than cue in.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
$sql = "SELECT :cue_out::INTERVAL > :orig_length::INTERVAL";
$params = array(
':cue_out' => $cueOut,
':orig_length' => $origLength
);
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
if ($result) {
$errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray;
}
$sql = "SELECT :cue_out::INTERVAL > :orig_length::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':orig_length', $origLength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$errArray["error"] = "Can't set cue out to be greater than file length.";
return $errArray;
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
$sql = "SELECT :cue_out::INTERVAL < :old_cue_in::INTERVAL";
$params = array(
':cue_out' => $cueOut,
':old_cue_in' => $oldCueIn
);
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
if ($result) {
$errArray["error"] = "Can't set cue out to be smaller than cue in.";
return $errArray;
}
$sql = "SELECT :cue_out::INTERVAL - :old_cue_in::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':cue_out', $cueOut);
$stmt->bindParam(':old_cue_in', $oldCueIn);
if ($stmt->execute()) {
$cliplength = $stmt->fetchColumn(0);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
$cliplength = $result;
$row->setDbCueout($cueOut);
$row->setDBCliplength($cliplength);
@ -918,35 +839,25 @@ EOT;
$cliplength = $row->getDbCliplength();
$sql = "SELECT :fade_in::INTERVAL > :clip_length::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':fade_in', $fadeIn);
$stmt->bindParam(':clip_length', $cliplength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$fadeIn = $cliplength;
$row->setDbFadein($fadeIn);
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
$params = array(
':fade_in' => $fadeIn,
':clip_length' => $cliplength
);
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
if ($result) {
$fadeIn = $cliplength;
$row->setDbFadein($fadeIn);
}
$sql = "SELECT :fade_out::INTERVAL > :clip_length::INTERVAL";
$stmt = $this->con->prepare($sql);
$stmt->bindParam(':fade_out', $fadeOut);
$stmt->bindParam(':clip_length', $cliplength);
if ($stmt->execute()) {
if ($stmt->fetchColumn(0)) {
$fadeOut = $cliplength;
$row->setDbFadein($fadeOut);
}
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
$params = array(
':fade_out' => $fadeOut,
':clip_length' => $cliplength
);
$result = Application_Common_Database::prepareAndExecute($sql, $params, 'column');
if ($result) {
$fadeOut = $cliplength;
$row->setDbFadein($fadeOut);
}
$row->save($this->con);

View File

@ -164,35 +164,14 @@ class Application_Model_Datatables
$totalRows = $r->fetchColumn(0);
if (isset($sqlTotalDisplayRows)) {
$stmt = $con->prepare($sqlTotalDisplayRows);
foreach($params as $param=>&$value) {
$stmt->bindParam(":$param", $value);
}
if ($stmt->execute()) {
$totalDisplayRows = $stmt->fetchColumn(0);
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$totalDisplayRows = Application_Common_Database::prepareAndExecute($sqlTotalDisplayRows, $params, 'column');
} else {
$totalDisplayRows = $totalRows;
}
//TODO
if ($needToBind) {
$stmt = $con->prepare($sql);
foreach($params as $param=>&$value) {
$stmt->bindParam(":$param", $value);
}
if ($stmt->execute()) {
$stmt->setFetchMode(PDO::FETCH_ASSOC);
$results = $stmt->fetchAll();
} else {
$msg = implode(',', $stmt->errorInfo());
throw new Exception("Error: $msg");
}
$results = Application_Common_Database::prepareAndExecute($sql, $params);
} else {
$stmt = $con->query($sql);
$stmt->setFetchMode(PDO::FETCH_ASSOC);

View File

@ -1063,23 +1063,25 @@ SQL;
* In both cases (new and edit) we only grab shows that
* are scheduled 2 days prior
*/
$se = $show_end->format('Y-m-d H:i:s');
//$se = $show_end->format('Y-m-d H:i:s');
if ($update) {
$sql = "SELECT id, starts, ends FROM ".$CC_CONFIG["showInstances"]."
where (ends <= '{$show_end->format('Y-m-d H:i:s')}'
or starts <= '{$show_end->format('Y-m-d H:i:s')}')
and date(starts) >= (date('{$show_end->format('Y-m-d H:i:s')}') - INTERVAL '2 days')
and modified_instance = false and id != ".$instanceId. " order by ends";
$stmt = $con->prepare("SELECT id, starts, ends FROM :showInstances
$stmt = $con->prepare("SELECT id, starts, ends FROM {$CC_CONFIG['showInstances']}
where (ends <= :show_end1
or starts <= :show_end2)
and date(starts) >= (date(:show_end3) - INTERVAL '2 days')
and modified_instance = false and id != :instanceId order by ends");
$stmt->execute(array(
':showInstances' => $CC_CONFIG['showInstances'],
':show_end1' => $se,
':show_end2' => $se,
':show_end3' => $se,
':show_end1' => $show_end->format('Y-m-d H:i:s'),
':show_end2' => $show_end->format('Y-m-d H:i:s'),
':show_end3' => $show_end->format('Y-m-d H:i:s'),
':instanceId' => $instanceId
));
} else {
@ -1089,16 +1091,17 @@ SQL;
or starts <= '{$show_end->format('Y-m-d H:i:s')}')
and date(starts) >= (date('{$show_end->format('Y-m-d H:i:s')}') - INTERVAL '2 days')
and modified_instance = false order by ends";
$stmt = $con->prepare("SELECT id, starts, ends FROM :showInstances
where (ends <= :show_end1
or starts <= :show_end2)
$stmt = $con->prepare("SELECT id, starts, ends FROM
{$CC_CONFIG['showInstances']}
where (ends <= :show_end1 or starts <= :show_end2)
and date(starts) >= (date(:show_end3) - INTERVAL '2 days')
and modified_instance = false order by ends");
$stmt->execute(array(
':showInstances' => $CC_CONFIG['showInstances'],
':show_end1' => $se,
':show_end2' => $se,
':show_end3' => $se,
':show_end1' => $show_end->format('Y-m-d H:i:s'),
':show_end2' => $show_end->format('Y-m-d H:i:s'),
':show_end3' => $show_end->format('Y-m-d H:i:s')
));
}
//$rows = $con->query($sql);
@ -1106,7 +1109,7 @@ SQL;
foreach ($rows as $row) {
$start = new DateTime($row["starts"], new DateTimeZone('UTC'));
$end = new DateTime($row["ends"], new DateTimeZone('UTC'));
$end = new DateTime($row["ends"], new DateTimeZone('UTC'));
if ($show_start->getTimestamp() < $end->getTimestamp() &&
$show_end->getTimestamp() > $start->getTimestamp()) {

View File

@ -309,13 +309,12 @@ class Application_Model_User
return Application_Common_Database::prepareAndExecute($sql, $params, "all");
}
public static function getUserCount($type=null)
public static function getUserCount()
{
$con = Propel::getConnection();
$sql = '';
$sql_gen = "SELECT count(*) AS cnt FROM cc_subjs";
$query = $con->query($sql)->fetchColumn(0);
$query = $con->query($sql_gen)->fetchColumn(0);
return ($query !== false) ? $query : null;
}

View File

@ -632,6 +632,10 @@ var AIRTIME = (function(AIRTIME){
{format: "json", data: criteria, name: block_name, description: block_desc, obj_id: obj_id, type: obj_type, modified: lastMod},
function(data){
var json = $.parseJSON(data);
if (json.error !== undefined) {
alert(json.error);
}
AIRTIME.playlist.fnOpenPlaylist(json);
setModified(json.modified);
if (obj_type == "block") {
callback(data, "save");