From e5085f0df3b723cb9dd7113657a8e7b712f867ab Mon Sep 17 00:00:00 2001 From: Rudi Grinberg Date: Wed, 19 Sep 2012 16:34:46 -0400 Subject: [PATCH] Cleaned up code. --- airtime_mvc/application/models/Datatables.php | 9 ++-- .../application/models/PlayoutHistory.php | 2 +- airtime_mvc/application/models/Preference.php | 51 ++++++++++++------- 3 files changed, 39 insertions(+), 23 deletions(-) diff --git a/airtime_mvc/application/models/Datatables.php b/airtime_mvc/application/models/Datatables.php index c022f2533..d20092b26 100644 --- a/airtime_mvc/application/models/Datatables.php +++ b/airtime_mvc/application/models/Datatables.php @@ -57,7 +57,9 @@ class Application_Model_Datatables public static function findEntries($con, $displayColumns, $fromTable, $data, $dataProp = "aaData") { - $librarySetting = Application_Model_Preference::getCurrentLibraryTableColumnMap(); + //$librarySetting = Application_Model_Preference::getCurrentLibraryTableColumnMap(); + $librarySetting = + Application_Model_Preference::getCurrentLibraryTableColumnMap(); //$displayColumns[] = 'owner'; // map that maps original column position to db name @@ -95,9 +97,8 @@ class Application_Model_Datatables } $where = array(); - /* Holds the parameters for binding after the - * statement has been prepared - */ + /* Holds the parameters for binding after the statement has been + prepared */ $params = array(); $advancedWhere = self::buildWhereClauseForAdvancedSearch($dbname2searchTerm); diff --git a/airtime_mvc/application/models/PlayoutHistory.php b/airtime_mvc/application/models/PlayoutHistory.php index 3ea640468..ba845fa33 100644 --- a/airtime_mvc/application/models/PlayoutHistory.php +++ b/airtime_mvc/application/models/PlayoutHistory.php @@ -60,7 +60,7 @@ class Application_Model_PlayoutHistory ); $start = $this->startDT->format("Y-m-d H:i:s"); - $end = $this->endDT->format("Y-m-d H:i:s"); + $end = $this->endDT->format("Y-m-d H:i:s"); $historyTable = "( select count(schedule.file_id) as played, schedule.file_id as file_id diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 9984e49bc..8f08e385e 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -1092,26 +1092,41 @@ class Application_Model_Preference } + + public static function getOrderingMap($pref_param) + { + $v = self::getValue($pref_param, true); + + $id = function ($x) { return $x; }; + + if ($v === '') { + return $id; + } + + $ds = unserialize($v); + + if (!array_key_exists('ColReorder', $ds)) { + return $id; + } + + return function ($x) use ($ds) { + if (array_key_exists($x, $ds['ColReorder'])) { + 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*/ + Logging::info("Pref: $pref_param"); + Logging::warn("Index $x does not exist preferences"); + Logging::warn("Defaulting to identity and printing preferences"); + Logging::warn($ds); + return $x; + } + }; + } + public static function getCurrentLibraryTableColumnMap() { - $v = self::getValue("library_datatable", true); - - if ( $v === '' ) { - return function ($x) { return $x; }; - } else { - $ds = unserialize($v); - return function ($x) use ($ds) { - if ( array_key_exists($x, $ds['ColReorder'] ) ) { - return $ds['ColReorder'][$x]; - } else { - Logging::warn("Index $x does not exist preferences"); - Logging::warn("Defaulting to identity and printing - preferences"); - Logging::warn($ds); - return $x; - } - } ; - } + return self::getOrderingMap("library_datatable"); } public static function setCurrentLibraryTableSetting($settings)