Merge branch '2.5.x' into 2.5.x-saas
Conflicts: airtime_mvc/application/forms/AddShowWhen.php airtime_mvc/application/forms/LiveStreamingPreferences.php airtime_mvc/application/models/Schedule.php airtime_mvc/application/views/scripts/form/preferences.phtml airtime_mvc/application/views/scripts/form/preferences_livestream.phtml airtime_mvc/application/views/scripts/form/support-setting.phtml airtime_mvc/application/views/scripts/schedule/add-show-form.phtml
This commit is contained in:
commit
49474ab5c4
214 changed files with 57623 additions and 61229 deletions
|
@ -1,26 +1,43 @@
|
|||
<?php
|
||||
|
||||
require_once 'Cache.php';
|
||||
|
||||
class Application_Model_Preference
|
||||
{
|
||||
|
||||
|
||||
private static function getUserId()
|
||||
{
|
||||
//called from a daemon process
|
||||
if (!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
|
||||
$userId = null;
|
||||
}
|
||||
else {
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$userId = $auth->getIdentity()->id;
|
||||
}
|
||||
|
||||
return $userId;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param integer $userId is not null when we are setting a locale for a specific user
|
||||
* @param boolean $isUserValue is true when we are setting a value for the current user
|
||||
*/
|
||||
private static function setValue($key, $value, $isUserValue = false, $userId = null)
|
||||
private static function setValue($key, $value, $isUserValue = false)
|
||||
{
|
||||
$cache = new Cache();
|
||||
|
||||
try {
|
||||
$con = Propel::getConnection(CcPrefPeer::DATABASE_NAME);
|
||||
$con->beginTransaction();
|
||||
|
||||
//called from a daemon process
|
||||
if (!class_exists("Zend_Auth", false) || !Zend_Auth::getInstance()->hasIdentity()) {
|
||||
$id = NULL;
|
||||
} else {
|
||||
$auth = Zend_Auth::getInstance();
|
||||
$id = $auth->getIdentity()->id;
|
||||
$userId = self::getUserId();
|
||||
|
||||
if ($isUserValue && is_null($userId)) {
|
||||
throw new Exception("User id can't be null for a user preference {$key}.");
|
||||
}
|
||||
|
||||
Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref");
|
||||
|
||||
//Check if key already exists
|
||||
$sql = "SELECT COUNT(*) FROM cc_pref"
|
||||
|
@ -30,15 +47,10 @@ class Application_Model_Preference
|
|||
$paramMap[':key'] = $key;
|
||||
|
||||
//For user specific preference, check if id matches as well
|
||||
if ($isUserValue && is_null($userId)) {
|
||||
if ($isUserValue) {
|
||||
$sql .= " AND subjid = :id";
|
||||
$paramMap[':id'] = $id;
|
||||
} else if (!is_null($userId)) {
|
||||
$sql .= " AND subjid= :id";
|
||||
$paramMap[':id'] = $userId;
|
||||
}
|
||||
|
||||
Application_Common_Database::prepareAndExecute("LOCK TABLE cc_pref");
|
||||
}
|
||||
|
||||
$result = Application_Common_Database::prepareAndExecute($sql,
|
||||
$paramMap,
|
||||
|
@ -51,39 +63,39 @@ class Application_Model_Preference
|
|||
//this case should not happen.
|
||||
throw new Exception("Invalid number of results returned. Should be ".
|
||||
"0 or 1, but is '$result' instead");
|
||||
} elseif ($result == 1) {
|
||||
}
|
||||
elseif ($result == 1) {
|
||||
|
||||
// result found
|
||||
if (is_null($id) || !$isUserValue) {
|
||||
if (!$isUserValue) {
|
||||
// system pref
|
||||
$sql = "UPDATE cc_pref"
|
||||
." SET subjid = NULL, valstr = :value"
|
||||
." WHERE keystr = :key";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// user pref
|
||||
$sql = "UPDATE cc_pref"
|
||||
. " SET valstr = :value"
|
||||
. " WHERE keystr = :key AND subjid = :id";
|
||||
if (is_null($userId)) {
|
||||
$paramMap[':id'] = $id;
|
||||
} else {
|
||||
$paramMap[':id'] = $userId;
|
||||
}
|
||||
|
||||
$paramMap[':id'] = $userId;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
|
||||
// result not found
|
||||
if (is_null($id) || !$isUserValue) {
|
||||
if (!$isUserValue) {
|
||||
// system pref
|
||||
$sql = "INSERT INTO cc_pref (keystr, valstr)"
|
||||
." VALUES (:key, :value)";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
// user pref
|
||||
$sql = "INSERT INTO cc_pref (subjid, keystr, valstr)"
|
||||
." VALUES (:id, :key, :value)";
|
||||
if (is_null($userId)) {
|
||||
$paramMap[':id'] = $id;
|
||||
} else {
|
||||
$paramMap[':id'] = $userId;
|
||||
}
|
||||
|
||||
$paramMap[':id'] = $userId;
|
||||
}
|
||||
}
|
||||
$paramMap[':key'] = $key;
|
||||
|
@ -96,18 +108,35 @@ class Application_Model_Preference
|
|||
$con);
|
||||
|
||||
$con->commit();
|
||||
} catch (Exception $e) {
|
||||
}
|
||||
catch (Exception $e) {
|
||||
$con->rollback();
|
||||
header('HTTP/1.0 503 Service Unavailable');
|
||||
Logging::info("Database error: ".$e->getMessage());
|
||||
exit;
|
||||
}
|
||||
|
||||
$cache->store($key, $value, $isUserValue, $userId);
|
||||
//Logging::info("SAVING {$key} {$userId} into cache. = {$value}");
|
||||
}
|
||||
|
||||
private static function getValue($key, $isUserValue = false)
|
||||
{
|
||||
$cache = new Cache();
|
||||
|
||||
try {
|
||||
|
||||
$userId = self::getUserId();
|
||||
|
||||
if ($isUserValue && is_null($userId)) {
|
||||
throw new Exception("User id can't be null for a user preference.");
|
||||
}
|
||||
|
||||
$res = $cache->fetch($key, $isUserValue, $userId);
|
||||
if ($res !== false) {
|
||||
//Logging::info("returning {$key} {$userId} from cache. = {$res}");
|
||||
return $res;
|
||||
}
|
||||
|
||||
//Check if key already exists
|
||||
$sql = "SELECT COUNT(*) FROM cc_pref"
|
||||
|
@ -117,20 +146,16 @@ class Application_Model_Preference
|
|||
$paramMap[':key'] = $key;
|
||||
|
||||
//For user specific preference, check if id matches as well
|
||||
if ($isUserValue) {
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if ($auth->hasIdentity()) {
|
||||
$id = $auth->getIdentity()->id;
|
||||
|
||||
$sql .= " AND subjid = :id";
|
||||
$paramMap[':id'] = $id;
|
||||
}
|
||||
if ($isUserValue) {
|
||||
$sql .= " AND subjid = :id";
|
||||
$paramMap[':id'] = $userId;
|
||||
}
|
||||
|
||||
$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN);
|
||||
|
||||
//return an empty string if the result doesn't exist.
|
||||
if ($result == 0) {
|
||||
return "";
|
||||
$res = "";
|
||||
}
|
||||
else {
|
||||
$sql = "SELECT valstr FROM cc_pref"
|
||||
|
@ -140,16 +165,20 @@ class Application_Model_Preference
|
|||
$paramMap[':key'] = $key;
|
||||
|
||||
//For user specific preference, check if id matches as well
|
||||
if ($isUserValue && $auth->hasIdentity()) {
|
||||
if ($isUserValue) {
|
||||
$sql .= " AND subjid = :id";
|
||||
$paramMap[':id'] = $id;
|
||||
$paramMap[':id'] = $userId;
|
||||
}
|
||||
|
||||
$result = Application_Common_Database::prepareAndExecute($sql, $paramMap, Application_Common_Database::COLUMN);
|
||||
|
||||
return ($result !== false) ? $result : "";
|
||||
$res = ($result !== false) ? $result : "";
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
|
||||
$cache->store($key, $res, $isUserValue, $userId);
|
||||
return $res;
|
||||
}
|
||||
catch (Exception $e) {
|
||||
header('HTTP/1.0 503 Service Unavailable');
|
||||
Logging::info("Could not connect to database: ".$e->getMessage());
|
||||
exit;
|
||||
|
@ -505,44 +534,48 @@ class Application_Model_Preference
|
|||
return self::getValue("description");
|
||||
}
|
||||
|
||||
// Sets station default timezone (from preferences)
|
||||
public static function SetDefaultTimezone($timezone)
|
||||
{
|
||||
self::setValue("timezone", $timezone);
|
||||
date_default_timezone_set($timezone);
|
||||
}
|
||||
|
||||
// Returns station default timezone (from preferences)
|
||||
public static function GetDefaultTimezone()
|
||||
{
|
||||
return self::getValue("timezone");
|
||||
}
|
||||
|
||||
public static function SetUserTimezone($userId, $timezone = null)
|
||||
public static function SetUserTimezone($timezone = null)
|
||||
{
|
||||
// When a new user is created they will get the default timezone
|
||||
// setting which the admin sets on preferences page
|
||||
if (is_null($timezone)) {
|
||||
$timezone = self::GetDefaultTimezone();
|
||||
}
|
||||
self::setValue("user_timezone", $timezone, true, $userId);
|
||||
self::setValue("user_timezone", $timezone, true);
|
||||
}
|
||||
|
||||
public static function GetUserTimezone($id)
|
||||
public static function GetUserTimezone()
|
||||
{
|
||||
$timezone = self::getValue("user_timezone", true);
|
||||
if (!$timezone) {
|
||||
return self::GetDefaultTimezone();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return $timezone;
|
||||
}
|
||||
}
|
||||
|
||||
// Always attempts to returns the current user's personal timezone setting
|
||||
public static function GetTimezone()
|
||||
{
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if ($auth->hasIdentity()) {
|
||||
$id = $auth->getIdentity()->id;
|
||||
return self::GetUserTimezone($id);
|
||||
} else {
|
||||
$userId = self::getUserId();
|
||||
|
||||
if (!is_null($userId)) {
|
||||
return self::GetUserTimezone();
|
||||
}
|
||||
else {
|
||||
return self::GetDefaultTimezone();
|
||||
}
|
||||
}
|
||||
|
@ -558,33 +591,35 @@ class Application_Model_Preference
|
|||
return self::getValue("locale");
|
||||
}
|
||||
|
||||
public static function GetUserLocale($id)
|
||||
public static function GetUserLocale()
|
||||
{
|
||||
$locale = self::getValue("user_locale", true);
|
||||
if (!$locale) {
|
||||
return self::GetDefaultLocale();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return $locale;
|
||||
}
|
||||
}
|
||||
|
||||
public static function SetUserLocale($userId, $locale = null)
|
||||
public static function SetUserLocale($locale = null)
|
||||
{
|
||||
// When a new user is created they will get the default locale
|
||||
// setting which the admin sets on preferences page
|
||||
if (is_null($locale)) {
|
||||
$locale = self::GetDefaultLocale();
|
||||
}
|
||||
self::setValue("user_locale", $locale, true, $userId);
|
||||
self::setValue("user_locale", $locale, true);
|
||||
}
|
||||
|
||||
public static function GetLocale()
|
||||
{
|
||||
$auth = Zend_Auth::getInstance();
|
||||
if ($auth->hasIdentity()) {
|
||||
$id = $auth->getIdentity()->id;
|
||||
return self::GetUserLocale($id);
|
||||
} else {
|
||||
$userId = self::getUserId();
|
||||
|
||||
if (!is_null($userId)) {
|
||||
return self::GetUserLocale();
|
||||
}
|
||||
else {
|
||||
return self::GetDefaultLocale();
|
||||
}
|
||||
}
|
||||
|
@ -1270,7 +1305,7 @@ class Application_Model_Preference
|
|||
return $ds['ColReorder'][$x];
|
||||
} else {
|
||||
/*For now we just have this hack for debugging. We should not
|
||||
rely on this crappy behaviour in case of failure*/
|
||||
rely on this behaviour in case of failure*/
|
||||
Logging::warn("Index $x does not exist preferences");
|
||||
Logging::warn("Defaulting to identity and printing preferences");
|
||||
Logging::warn($ds);
|
||||
|
@ -1286,15 +1321,8 @@ class Application_Model_Preference
|
|||
|
||||
public static function setCurrentLibraryTableSetting($settings)
|
||||
{
|
||||
$num_columns = count(Application_Model_StoredFile::getLibraryColumns());
|
||||
$new_columns_num = count($settings['abVisCols']);
|
||||
|
||||
/*if ($num_columns != $new_columns_num) {
|
||||
throw new Exception("Trying to write a user column preference with incorrect number of columns!");
|
||||
}*/
|
||||
|
||||
$data = serialize($settings);
|
||||
$v = self::setValue("library_datatable", $data, true);
|
||||
self::setValue("library_datatable", $data, true);
|
||||
}
|
||||
|
||||
public static function getCurrentLibraryTableSetting()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue