2013-07-03 21:19:05 +02:00
< ? php
2013-07-03 22:00:48 +02:00
require_once 'formatters/LengthFormatter.php' ;
2013-07-03 21:19:05 +02:00
class Application_Service_HistoryService
{
private $con ;
private $timezone ;
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
const TEMPLATE_TYPE_ITEM = " item " ;
2013-08-02 21:29:39 +02:00
const TEMPLATE_TYPE_FILE = " file " ;
2013-07-18 07:31:20 +02:00
2013-07-03 21:20:40 +02:00
public function __construct ()
{
2013-07-03 21:19:05 +02:00
$this -> con = isset ( $con ) ? $con : Propel :: getConnection ( CcPlayoutHistoryPeer :: DATABASE_NAME );
2013-07-24 00:01:43 +02:00
$this -> timezone = Application_Model_Preference :: GetTimezone ();
2013-07-03 22:00:48 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
public function getSupportedTemplateTypes ()
2013-07-03 22:02:17 +02:00
{
2013-08-02 21:29:39 +02:00
return array ( self :: TEMPLATE_TYPE_ITEM , self :: TEMPLATE_TYPE_FILE );
2013-07-03 22:02:17 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
//opts is from datatables.
2013-08-29 05:30:15 +02:00
public function getPlayedItemData ( $startDT , $endDT , $opts , $instanceId = null )
2013-07-18 07:31:20 +02:00
{
2013-07-31 23:39:45 +02:00
$mainSqlQuery = " " ;
2013-07-31 23:38:48 +02:00
$paramMap = array ();
2013-08-01 22:36:18 +02:00
$sqlTypes = $this -> getSqlTypes ();
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$start = $startDT -> format ( " Y-m-d H:i:s " );
2013-07-31 23:38:48 +02:00
$end = $endDT -> format ( " Y-m-d H:i:s " );
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
$template = $this -> getConfiguredItemTemplate ();
$fields = $template [ " fields " ];
2013-08-20 05:19:13 +02:00
$required = $this -> mandatoryItemFields ();
2013-07-31 23:38:48 +02:00
$fields_filemd = array ();
2013-08-01 23:09:42 +02:00
$filemd_keys = array ();
2013-07-31 23:38:48 +02:00
$fields_general = array ();
2013-08-01 23:09:42 +02:00
$general_keys = array ();
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
foreach ( $fields as $index => $field ) {
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
if ( in_array ( $field [ " name " ], $required )) {
continue ;
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
if ( $field [ " isFileMd " ]) {
$fields_filemd [] = $field ;
2013-08-01 23:09:42 +02:00
$filemd_keys [] = $field [ " name " ];
2013-07-31 23:38:48 +02:00
}
else {
$fields_general [] = $field ;
2013-08-01 23:09:42 +02:00
$general_keys [] = $field [ " name " ];
2013-07-31 23:38:48 +02:00
}
}
2013-08-20 05:19:13 +02:00
2013-08-30 00:32:42 +02:00
//-----------------------------------------------------------------------
//Using the instance_id to filter the data.
2013-07-31 23:39:45 +02:00
$historyRange = " ( " .
2013-08-29 05:30:15 +02:00
" SELECT history.starts, history.ends, history.id AS history_id, history.instance_id " .
2013-08-30 00:32:42 +02:00
" FROM cc_playout_history as history " ;
if ( isset ( $instanceId )) {
$historyRange .= " WHERE history.instance_id = :instance " ;
$paramMap [ " instance " ] = $instanceId ;
}
else {
$historyRange .= " WHERE history.starts >= :starts and history.starts < :ends " ;
$paramMap [ " starts " ] = $start ;
$paramMap [ " ends " ] = $end ;
}
$historyRange .= " ) AS history_range " ;
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$manualMeta = " ( " .
" SELECT %KEY%.value AS %KEY%, %KEY%.history_id " .
" FROM ( " .
" SELECT * from cc_playout_history_metadata AS phm WHERE phm.key = :meta_%KEY% " .
" ) AS %KEY% " .
2013-07-31 23:38:48 +02:00
" ) AS %KEY%_filter " ;
2013-08-20 05:19:13 +02:00
2013-08-29 05:30:15 +02:00
$mainSelect = array (
" history_range.starts " ,
" history_range.ends " ,
" history_range.history_id " ,
" history_range.instance_id "
);
2013-07-31 23:38:48 +02:00
$mdFilters = array ();
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
$numFileMdFields = count ( $fields_filemd );
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
if ( $numFileMdFields > 0 ) {
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
//these 3 selects are only needed if $fields_filemd has some fields.
$fileSelect = array ( " history_file.history_id " );
$nonNullFileSelect = array ( " file.id as file_id " );
$nullFileSelect = array ( " null_file.history_id " );
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
$fileMdFilters = array ();
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
//populate the different dynamic selects with file info.
for ( $i = 0 ; $i < $numFileMdFields ; $i ++ ) {
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
$field = $fields_filemd [ $i ];
$key = $field [ " name " ];
2013-08-01 22:36:18 +02:00
$type = $sqlTypes [ $field [ " type " ]];
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
$fileSelect [] = " file_md. { $key } :: { $type } " ;
$nonNullFileSelect [] = " file. { $key } :: { $type } " ;
$nullFileSelect [] = " { $key } _filter. { $key } :: { $type } " ;
$mainSelect [] = " file_info. { $key } :: { $type } " ;
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
$fileMdFilters [] = str_replace ( " %KEY% " , $key , $manualMeta );
$paramMap [ " meta_ { $key } " ] = $key ;
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
//the files associated with scheduled playback in Airtime.
$historyFile = " ( " .
" SELECT history.id AS history_id, history.file_id " .
" FROM cc_playout_history AS history " .
" WHERE history.file_id IS NOT NULL " .
" ) AS history_file " ;
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$fileMd = " ( " .
" SELECT %NON_NULL_FILE_SELECT% " .
" FROM cc_files AS file " .
2013-07-31 23:38:48 +02:00
" ) AS file_md " ;
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$fileMd = str_replace ( " %NON_NULL_FILE_SELECT% " , join ( " , " , $nonNullFileSelect ), $fileMd );
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
//null files are from manually added data (filling in webstream info etc)
$nullFile = " ( " .
" SELECT history.id AS history_id " .
" FROM cc_playout_history AS history " .
" WHERE history.file_id IS NULL " .
2013-07-31 23:38:48 +02:00
" ) AS null_file " ;
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
//----------------------------------
//building the file inner query
2013-08-20 05:19:13 +02:00
$fileSqlQuery =
2013-07-31 23:38:48 +02:00
" SELECT " . join ( " , " , $fileSelect ) .
" FROM { $historyFile } " .
" LEFT JOIN { $fileMd } USING (file_id) " .
" UNION " .
" SELECT " . join ( " , " , $nullFileSelect ) .
" FROM { $nullFile } " ;
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
foreach ( $fileMdFilters as $filter ) {
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
$fileSqlQuery .=
" LEFT JOIN { $filter } USING(history_id) " ;
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
for ( $i = 0 , $len = count ( $fields_general ); $i < $len ; $i ++ ) {
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$field = $fields_general [ $i ];
2013-07-31 23:38:48 +02:00
$key = $field [ " name " ];
2013-08-01 22:36:18 +02:00
$type = $sqlTypes [ $field [ " type " ]];
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$mdFilters [] = str_replace ( " %KEY% " , $key , $manualMeta );
2013-07-31 23:38:48 +02:00
$paramMap [ " meta_ { $key } " ] = $key ;
2013-08-01 22:36:18 +02:00
$mainSelect [] = " { $key } _filter. { $key } :: { $type } " ;
2013-07-31 23:38:48 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
$mainSqlQuery .=
" SELECT " . join ( " , " , $mainSelect ) .
" FROM { $historyRange } " ;
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
if ( isset ( $fileSqlQuery )) {
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
$mainSqlQuery .=
" LEFT JOIN ( { $fileSqlQuery } ) as file_info USING(history_id) " ;
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
foreach ( $mdFilters as $filter ) {
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$mainSqlQuery .=
" LEFT JOIN { $filter } USING(history_id) " ;
2013-07-31 23:38:48 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 22:15:32 +02:00
//----------------------------------------------------------------------
2013-08-02 17:18:15 +02:00
//need to count the total rows to tell Datatables.
2013-08-02 17:19:46 +02:00
$stmt = $this -> con -> prepare ( $mainSqlQuery );
foreach ( $paramMap as $param => $v ) {
$stmt -> bindValue ( $param , $v );
2013-08-02 17:18:15 +02:00
}
2013-08-30 00:32:42 +02:00
2013-08-02 17:19:46 +02:00
if ( $stmt -> execute ()) {
2013-08-02 17:18:15 +02:00
$totalRows = $stmt -> rowCount ();
2013-08-02 17:19:46 +02:00
}
else {
$msg = implode ( ',' , $stmt -> errorInfo ());
throw new Exception ( " Error: $msg " );
2013-08-02 17:18:15 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-01 23:09:42 +02:00
//------------------------------------------------------------------------
//Using Datatables parameters to sort the data.
2013-08-20 05:19:13 +02:00
2013-08-01 23:09:42 +02:00
$numOrderColumns = $opts [ " iSortingCols " ];
$orderBys = array ();
2013-08-20 05:19:13 +02:00
2013-08-01 23:09:42 +02:00
for ( $i = 0 ; $i < $numOrderColumns ; $i ++ ) {
2013-08-20 05:19:13 +02:00
2013-08-01 23:09:42 +02:00
$colNum = $opts [ " iSortCol_ " . $i ];
$key = $opts [ " mDataProp_ " . $colNum ];
$sortDir = $opts [ " sSortDir_ " . $i ];
2013-08-20 05:19:13 +02:00
2013-08-01 23:09:42 +02:00
if ( in_array ( $key , $required )) {
2013-08-01 23:10:04 +02:00
2013-08-01 23:09:42 +02:00
$orderBys [] = " history_range. { $key } { $sortDir } " ;
}
else if ( in_array ( $key , $filemd_keys )) {
2013-08-20 05:19:13 +02:00
2013-08-01 23:09:42 +02:00
$orderBys [] = " file_info. { $key } { $sortDir } " ;
}
else if ( in_array ( $key , $general_keys )) {
2013-08-01 23:10:04 +02:00
2013-08-01 23:09:42 +02:00
$orderBys [] = " { $key } _filter. { $key } { $sortDir } " ;
}
else {
2013-08-20 05:19:13 +02:00
//throw new Exception("Error: $key is not part of the template.");
2013-08-01 23:09:42 +02:00
}
}
2013-08-20 05:19:13 +02:00
if ( count ( $orderBys ) > 0 ) {
2013-08-01 23:09:42 +02:00
$orders = join ( " , " , $orderBys );
2013-08-20 05:19:13 +02:00
2013-08-01 23:10:04 +02:00
$mainSqlQuery .=
2013-08-01 23:09:42 +02:00
" ORDER BY { $orders } " ;
}
2013-08-20 05:19:13 +02:00
2013-08-02 22:15:32 +02:00
//---------------------------------------------------------------
//using Datatables parameters to add limits/offsets
2013-08-20 05:19:13 +02:00
2013-08-02 17:18:15 +02:00
$displayLength = intval ( $opts [ " iDisplayLength " ]);
2013-08-02 17:19:46 +02:00
//limit the results returned.
if ( $displayLength !== - 1 ) {
2013-08-02 17:18:15 +02:00
$mainSqlQuery .=
" OFFSET :offset LIMIT :limit " ;
2013-08-20 05:19:13 +02:00
$paramMap [ " offset " ] = intval ( $opts [ " iDisplayStart " ]);
2013-08-02 17:19:46 +02:00
$paramMap [ " limit " ] = $displayLength ;
2013-08-02 17:18:15 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$stmt = $this -> con -> prepare ( $mainSqlQuery );
foreach ( $paramMap as $param => $v ) {
$stmt -> bindValue ( $param , $v );
2013-07-31 23:38:48 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
$rows = array ();
if ( $stmt -> execute ()) {
$rows = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
}
else {
$msg = implode ( ',' , $stmt -> errorInfo ());
throw new Exception ( " Error: $msg " );
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:38:48 +02:00
//-----------------------------------------------------------------------
//processing results.
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$timezoneUTC = new DateTimeZone ( " UTC " );
$timezoneLocal = new DateTimeZone ( $this -> timezone );
2013-08-20 05:19:13 +02:00
2013-08-14 22:38:59 +02:00
$boolCast = array ();
2013-08-14 22:39:50 +02:00
foreach ( $fields as $index => $field ) {
2013-08-20 05:19:13 +02:00
2013-08-14 22:38:59 +02:00
if ( $field [ " type " ] == TEMPLATE_BOOLEAN ) {
2013-08-14 22:39:50 +02:00
$boolCast [] = $field [ " name " ];
}
2013-08-14 22:38:59 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
foreach ( $rows as $index => & $result ) {
2013-08-20 05:19:13 +02:00
2013-08-14 22:39:50 +02:00
foreach ( $boolCast as $name ) {
$result [ $name ] = ( bool ) $result [ $name ];
2013-08-14 22:38:59 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-29 21:58:24 +02:00
//need to display the results in the station's timezone.
2013-07-31 23:39:45 +02:00
$dateTime = new DateTime ( $result [ " starts " ], $timezoneUTC );
$dateTime -> setTimezone ( $timezoneLocal );
$result [ " starts " ] = $dateTime -> format ( " Y-m-d H:i:s " );
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
$dateTime = new DateTime ( $result [ " ends " ], $timezoneUTC );
$dateTime -> setTimezone ( $timezoneLocal );
$result [ " ends " ] = $dateTime -> format ( " Y-m-d H:i:s " );
2013-08-20 05:19:13 +02:00
2013-08-13 00:18:33 +02:00
if ( isset ( $result [ MDATA_KEY_DURATION ])) {
$formatter = new LengthFormatter ( $result [ MDATA_KEY_DURATION ]);
$result [ MDATA_KEY_DURATION ] = $formatter -> format ();
}
2013-08-20 05:19:13 +02:00
//need to add a checkbox..
$result [ " checkbox " ] = " " ;
2013-08-13 00:18:58 +02:00
//$unicodeChar = '\u2612';
2013-08-13 00:18:33 +02:00
//$result["new"] = json_decode('"'.$unicodeChar.'"');
//$result["new"] = "U+2612";
2013-07-31 23:38:48 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 23:39:45 +02:00
return array (
" sEcho " => intval ( $opts [ " sEcho " ]),
2013-07-31 23:38:48 +02:00
//"iTotalDisplayRecords" => intval($totalDisplayRows),
2013-07-31 23:39:45 +02:00
" iTotalDisplayRecords " => intval ( $totalRows ),
" iTotalRecords " => intval ( $totalRows ),
" history " => $rows
2013-07-31 23:38:48 +02:00
);
}
2013-07-18 07:31:20 +02:00
2013-08-02 21:29:39 +02:00
public function getFileSummaryData ( $startDT , $endDT , $opts )
2013-07-03 22:02:17 +02:00
{
2013-07-09 00:00:02 +02:00
$select = array (
2013-08-20 05:19:13 +02:00
" summary.played " ,
" summary.file_id " ,
2013-08-02 22:15:32 +02:00
" summary. " . MDATA_KEY_TITLE ,
" summary. " . MDATA_KEY_CREATOR
2013-07-03 22:02:17 +02:00
);
2013-08-20 05:19:13 +02:00
2013-08-02 22:15:32 +02:00
$mainSqlQuery = " " ;
$paramMap = array ();
2013-07-03 22:02:17 +02:00
$start = $startDT -> format ( " Y-m-d H:i:s " );
2013-07-18 07:31:20 +02:00
$end = $endDT -> format ( " Y-m-d H:i:s " );
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$paramMap [ " starts " ] = $start ;
2013-08-02 22:15:32 +02:00
$paramMap [ " ends " ] = $end ;
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$template = $this -> getConfiguredFileTemplate ();
$fields = $template [ " fields " ];
2013-08-02 22:15:32 +02:00
$required = $this -> mandatoryFileFields ();
2013-07-18 07:31:20 +02:00
2013-08-02 22:16:04 +02:00
foreach ( $fields as $index => $field ) {
2013-08-20 05:19:13 +02:00
2013-08-02 22:15:32 +02:00
$key = $field [ " name " ];
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
if ( in_array ( $field [ " name " ], $required )) {
continue ;
2013-08-02 22:15:32 +02:00
}
2013-07-18 07:31:20 +02:00
2013-08-02 22:16:04 +02:00
$select [] = " summary. { $key } " ;
2013-08-02 22:15:32 +02:00
}
$fileSummaryTable = " ((
SELECT COUNT ( history . file_id ) as played , history . file_id as file_id
FROM cc_playout_history AS history
WHERE history . starts >= : starts AND history . starts < : ends
AND history . file_id IS NOT NULL
GROUP BY history . file_id
) AS playout
LEFT JOIN cc_files AS file ON ( file . id = playout . file_id )) AS summary " ;
2013-07-18 07:31:20 +02:00
2013-08-02 22:15:32 +02:00
$mainSqlQuery .=
" SELECT " . join ( " , " , $select ) .
" FROM { $fileSummaryTable } " ;
2013-08-20 05:19:13 +02:00
2013-08-02 22:15:32 +02:00
//-------------------------------------------------------------------------
2013-08-02 22:16:04 +02:00
//need to count the total rows to tell Datatables.
$stmt = $this -> con -> prepare ( $mainSqlQuery );
foreach ( $paramMap as $param => $v ) {
$stmt -> bindValue ( $param , $v );
}
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
if ( $stmt -> execute ()) {
$totalRows = $stmt -> rowCount ();
}
else {
$msg = implode ( ',' , $stmt -> errorInfo ());
throw new Exception ( " Error: $msg " );
}
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
//------------------------------------------------------------------------
//Using Datatables parameters to sort the data.
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$numOrderColumns = $opts [ " iSortingCols " ];
$orderBys = array ();
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
for ( $i = 0 ; $i < $numOrderColumns ; $i ++ ) {
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$colNum = $opts [ " iSortCol_ " . $i ];
$key = $opts [ " mDataProp_ " . $colNum ];
$sortDir = $opts [ " sSortDir_ " . $i ];
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$orderBys [] = " summary. { $key } { $sortDir } " ;
2013-08-02 22:15:32 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
if ( $numOrderColumns > 0 ) {
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$orders = join ( " , " , $orderBys );
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$mainSqlQuery .=
" ORDER BY { $orders } " ;
2013-08-02 22:15:32 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 22:15:32 +02:00
//------------------------------------------------------------
//using datatables params to add limits/offsets
2013-08-02 22:16:04 +02:00
$displayLength = intval ( $opts [ " iDisplayLength " ]);
if ( $displayLength !== - 1 ) {
$mainSqlQuery .=
" OFFSET :offset LIMIT :limit " ;
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$paramMap [ " offset " ] = $opts [ " iDisplayStart " ];
$paramMap [ " limit " ] = $displayLength ;
}
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$stmt = $this -> con -> prepare ( $mainSqlQuery );
foreach ( $paramMap as $param => $v ) {
$stmt -> bindValue ( $param , $v );
}
2013-08-20 05:19:13 +02:00
2013-08-02 22:16:04 +02:00
$rows = array ();
if ( $stmt -> execute ()) {
$rows = $stmt -> fetchAll ( PDO :: FETCH_ASSOC );
}
else {
$msg = implode ( ',' , $stmt -> errorInfo ());
throw new Exception ( " Error: $msg " );
2013-08-02 22:15:32 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 22:15:32 +02:00
//-----------------------------------------------------------------
//processing the results
foreach ( $rows as & $row ) {
2013-07-03 22:02:17 +02:00
$formatter = new LengthFormatter ( $row [ 'length' ]);
$row [ 'length' ] = $formatter -> format ();
}
2013-07-18 07:31:20 +02:00
2013-08-02 22:15:32 +02:00
return array (
" sEcho " => intval ( $opts [ " sEcho " ]),
//"iTotalDisplayRecords" => intval($totalDisplayRows),
" iTotalDisplayRecords " => intval ( $totalRows ),
" iTotalRecords " => intval ( $totalRows ),
" history " => $rows
);
2013-07-03 21:19:05 +02:00
}
2013-08-29 05:30:15 +02:00
2013-08-29 00:25:46 +02:00
public function getShowList ( $startDT , $endDT )
2013-08-28 23:15:36 +02:00
{
2013-08-29 00:25:46 +02:00
$user = Application_Model_User :: getCurrentUser ();
$shows = Application_Model_Show :: getShows ( $startDT , $endDT );
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
Logging :: info ( $startDT -> format ( " Y-m-d H:i:s " ));
Logging :: info ( $endDT -> format ( " Y-m-d H:i:s " ));
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
Logging :: info ( $shows );
2013-08-29 05:30:15 +02:00
2013-08-29 00:25:46 +02:00
//need to filter the list to only their shows
if ( $user -> isHost ()) {
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
$showIds = array ();
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
foreach ( $shows as $show ) {
$showIds [] = $show [ " show_id " ];
}
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
$showIds = array_unique ( $showIds );
Logging :: info ( $showIds );
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
$hostRecords = CcShowHostsQuery :: create ()
-> filterByDbHost ( $user -> getId ())
-> filterByDbShow ( $showIds )
-> find ( $this -> con );
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
$filteredShowIds = array ();
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
foreach ( $hostRecords as $record ) {
$filteredShowIds [] = $record -> getDbShow ();
}
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
Logging :: info ( $filteredShowIds );
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
$filteredShows = array ();
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
foreach ( $shows as $show ) {
if ( in_array ( $show [ " show_id " ], $filteredShowIds )) {
$filteredShows [] = $show ;
}
}
}
else {
$filteredShows = $shows ;
2013-08-29 00:25:46 +02:00
}
2013-08-30 00:32:42 +02:00
2013-08-29 21:58:24 +02:00
$timezoneUTC = new DateTimeZone ( " UTC " );
$timezoneLocal = new DateTimeZone ( $this -> timezone );
2013-08-30 00:32:42 +02:00
2013-08-29 21:58:24 +02:00
foreach ( $filteredShows as & $result ) {
2013-08-30 00:32:42 +02:00
2013-08-29 21:58:24 +02:00
//need to display the results in the station's timezone.
$dateTime = new DateTime ( $result [ " starts " ], $timezoneUTC );
$dateTime -> setTimezone ( $timezoneLocal );
$result [ " starts " ] = $dateTime -> format ( " Y-m-d H:i:s " );
2013-08-30 00:32:42 +02:00
2013-08-29 21:58:24 +02:00
$dateTime = new DateTime ( $result [ " ends " ], $timezoneUTC );
$dateTime -> setTimezone ( $timezoneLocal );
$result [ " ends " ] = $dateTime -> format ( " Y-m-d H:i:s " );
2013-08-30 00:32:42 +02:00
2013-08-29 21:58:24 +02:00
}
2013-08-29 05:30:15 +02:00
2013-08-29 01:37:46 +02:00
return $filteredShows ;
2013-08-28 23:15:36 +02:00
}
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
public function insertPlayedItem ( $schedId ) {
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
$this -> con -> beginTransaction ();
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
try {
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
$item = CcScheduleQuery :: create () -> findPK ( $schedId , $this -> con );
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
//TODO figure out how to combine these all into 1 query.
$showInstance = $item -> getCcShowInstances ( $this -> con );
$show = $showInstance -> getCcShow ( $this -> con );
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
$fileId = $item -> getDbFileId ();
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
//don't add webstreams
if ( isset ( $fileId )) {
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
$metadata = array ();
$metadata [ " showname " ] = $show -> getDbName ();
2013-07-18 07:31:20 +02:00
2013-07-03 21:20:40 +02:00
$history = new CcPlayoutHistory ();
2013-07-03 21:19:05 +02:00
$history -> setDbFileId ( $fileId );
$history -> setDbStarts ( $item -> getDbStarts ( null ));
$history -> setDbEnds ( $item -> getDbEnds ( null ));
2013-08-28 23:15:36 +02:00
$history -> setDbInstanceId ( $item -> getDbInstanceId ());
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
foreach ( $metadata as $key => $val ) {
2013-07-03 21:20:40 +02:00
$meta = new CcPlayoutHistoryMetaData ();
$meta -> setDbKey ( $key );
2013-07-03 21:19:05 +02:00
$meta -> setDbValue ( $val );
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
$history -> addCcPlayoutHistoryMetaData ( $meta );
}
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
$history -> save ( $this -> con );
}
2013-07-18 07:31:20 +02:00
2013-07-03 21:19:05 +02:00
$this -> con -> commit ();
2013-07-18 07:31:20 +02:00
}
2013-07-03 21:20:40 +02:00
catch ( Exception $e ) {
$this -> con -> rollback ();
throw $e ;
2013-07-03 21:19:05 +02:00
}
}
2013-07-18 07:31:20 +02:00
/* id is an id in cc_playout_history */
2013-08-03 00:16:23 +02:00
public function makeHistoryItemForm ( $id , $populate = false ) {
2013-07-26 17:36:58 +02:00
2013-07-23 00:11:44 +02:00
try {
$form = new Application_Form_EditHistoryItem ();
2013-07-31 01:24:05 +02:00
$template = $this -> getConfiguredItemTemplate ();
$required = $this -> mandatoryItemFields ();
$form -> createFromTemplate ( $template [ " fields " ], $required );
2013-07-26 17:36:58 +02:00
2013-08-03 00:16:23 +02:00
if ( $populate ) {
$formValues = array ();
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
$historyRecord = CcPlayoutHistoryQuery :: create () -> findPk ( $id , $this -> con );
$file = $historyRecord -> getCcFiles ();
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
if ( isset ( $file )) {
$f = Application_Model_StoredFile :: createWithFile ( $file , $this -> con );
$filemd = $f -> getDbColMetadata ();
}
$metadata = array ();
$mds = $historyRecord -> getCcPlayoutHistoryMetaDatas ();
foreach ( $mds as $md ) {
$metadata [ $md -> getDbKey ()] = $md -> getDbValue ();
}
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
$prefix = Application_Form_EditHistoryItem :: ID_PREFIX ;
$formValues [ " { $prefix } id " ] = $id ;
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
foreach ( $template [ " fields " ] as $index => $field ) {
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
$key = $field [ " name " ];
2013-08-20 21:31:13 +02:00
$value = " " ;
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
if ( in_array ( $key , $required )) {
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
$method = " getDb " . ucfirst ( $key );
$value = $historyRecord -> $method ();
}
else if ( isset ( $filemd ) && $field [ " isFileMd " ]) {
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
$value = $filemd [ $key ];
}
else if ( isset ( $metadata [ $key ])) {
$value = $metadata [ $key ];
}
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
//need to convert to the station's local time first.
if ( $field [ " type " ] == TEMPLATE_DATETIME ) {
$timezoneUTC = new DateTimeZone ( " UTC " );
$timezoneLocal = new DateTimeZone ( $this -> timezone );
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
$dateTime = new DateTime ( $value , $timezoneUTC );
$dateTime -> setTimezone ( $timezoneLocal );
$value = $dateTime -> format ( " Y-m-d H:i:s " );
}
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
$formValues [ " $prefix { $key } " ] = $value ;
}
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
$form -> populate ( $formValues );
}
2013-08-20 05:19:13 +02:00
2013-07-23 00:11:44 +02:00
return $form ;
}
catch ( Exception $e ) {
Logging :: info ( $e );
throw $e ;
}
2013-07-09 00:00:02 +02:00
}
2013-07-18 07:31:20 +02:00
/* id is an id in cc_files */
2013-07-09 00:00:02 +02:00
public function makeHistoryFileForm ( $id ) {
2013-07-18 07:37:39 +02:00
2013-07-18 07:31:20 +02:00
try {
$form = new Application_Form_EditHistoryFile ();
2013-08-12 21:06:26 +02:00
$template = $this -> getConfiguredFileTemplate ();
$required = $this -> mandatoryFileFields ();
$form -> createFromTemplate ( $template [ " fields " ], $required );
2013-07-18 07:31:20 +02:00
$file = Application_Model_StoredFile :: RecallById ( $id , $this -> con );
$md = $file -> getDbColMetadata ();
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$prefix = Application_Form_EditHistoryFile :: ID_PREFIX ;
2013-08-12 21:08:09 +02:00
$formValues = array ();
$formValues [ " { $prefix } id " ] = $id ;
2013-08-20 05:19:13 +02:00
2013-08-12 21:08:09 +02:00
foreach ( $template [ " fields " ] as $index => $field ) {
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$key = $field [ " name " ];
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
if ( in_array ( $key , $required )) {
continue ;
}
2013-08-20 05:19:13 +02:00
$value = $md [ $key ];
$formValues [ " $prefix { $key } " ] = $value ;
2013-08-12 21:08:09 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-12 21:08:09 +02:00
$form -> populate ( $formValues );
2013-07-18 07:31:20 +02:00
2013-07-18 07:37:39 +02:00
return $form ;
}
catch ( Exception $e ) {
2013-07-22 16:45:39 +02:00
Logging :: info ( $e );
2013-07-23 00:11:44 +02:00
throw $e ;
2013-07-18 07:31:20 +02:00
}
2013-07-26 17:36:58 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
public function populateTemplateFile ( $values , $id ) {
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$this -> con -> beginTransaction ();
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
try {
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$file = Application_Model_StoredFile :: RecallById ( $id , $this -> con );
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$prefix = Application_Form_EditHistoryFile :: ID_PREFIX ;
$prefix_len = strlen ( $prefix );
$templateValues = $values [ $prefix . " template " ];
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$md = array ();
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
foreach ( $templateValues as $index => $value ) {
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$key = substr ( $index , $prefix_len );
$md [ $key ] = $value ;
}
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$file -> setDbColMetadata ( $md );
$this -> con -> commit ();
}
catch ( Exception $e ) {
$this -> con -> rollback ();
throw $e ;
2013-08-20 05:19:13 +02:00
}
2013-08-12 21:06:26 +02:00
}
2013-07-26 17:36:58 +02:00
2013-08-29 23:40:08 +02:00
public function populateTemplateItem ( $values , $id = null , $instance_id = null ) {
2013-07-26 17:36:58 +02:00
2013-07-26 23:33:17 +02:00
$this -> con -> beginTransaction ();
2013-07-29 14:57:31 +02:00
2013-07-26 23:33:17 +02:00
try {
2013-07-31 01:24:05 +02:00
$template = $this -> getConfiguredItemTemplate ();
2013-07-29 14:57:31 +02:00
$prefix = Application_Form_EditHistoryItem :: ID_PREFIX ;
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
if ( isset ( $id )) {
$historyRecord = CcPlayoutHistoryQuery :: create () -> findPk ( $id , $this -> con );
}
else {
$historyRecord = new CcPlayoutHistory ();
}
2013-08-30 00:32:42 +02:00
2013-08-29 23:40:08 +02:00
if ( isset ( $instance_id )) {
$historyRecord -> setDbInstanceId ( $instance_id );
}
2013-08-20 05:19:13 +02:00
2013-07-26 23:33:17 +02:00
$timezoneUTC = new DateTimeZone ( " UTC " );
$timezoneLocal = new DateTimeZone ( $this -> timezone );
2013-07-29 14:57:31 +02:00
$dateTime = new DateTime ( $values [ $prefix . " starts " ], $timezoneLocal );
$dateTime -> setTimezone ( $timezoneUTC );
2013-07-26 23:33:17 +02:00
$historyRecord -> setDbStarts ( $dateTime -> format ( " Y-m-d H:i:s " ));
2013-07-29 14:57:31 +02:00
$dateTime = new DateTime ( $values [ $prefix . " ends " ], $timezoneLocal );
2013-07-26 23:33:17 +02:00
$dateTime -> setTimezone ( $timezoneUTC );
$historyRecord -> setDbEnds ( $dateTime -> format ( " Y-m-d H:i:s " ));
2013-07-29 14:57:31 +02:00
$templateValues = $values [ $prefix . " template " ];
$file = $historyRecord -> getCcFiles ();
2013-07-31 01:24:05 +02:00
$md = array ();
2013-07-29 14:59:04 +02:00
$metadata = array ();
2013-07-31 01:24:05 +02:00
$fields = $template [ " fields " ];
$required = $this -> mandatoryItemFields ();
2013-08-20 23:23:15 +02:00
$phpCasts = $this -> getPhpCasts ();
2013-07-31 01:24:05 +02:00
for ( $i = 0 , $len = count ( $fields ); $i < $len ; $i ++ ) {
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
$field = $fields [ $i ];
$key = $field [ " name " ];
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
//required is delt with before this loop.
if ( in_array ( $key , $required )) {
continue ;
2013-07-29 14:57:31 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
$isFileMd = $field [ " isFileMd " ];
2013-08-20 23:23:15 +02:00
$entry = $phpCasts [ $field [ " type " ]]( $templateValues [ $prefix . $key ]);
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
if ( $isFileMd && isset ( $file )) {
2013-08-20 23:23:15 +02:00
Logging :: info ( " adding metadata associated to a file for { $key } = { $entry } " );
2013-07-31 01:24:05 +02:00
$md [ $key ] = $entry ;
2013-07-29 14:57:31 +02:00
}
else {
2013-08-20 23:23:15 +02:00
Logging :: info ( " adding metadata for { $key } = { $entry } " );
2013-07-31 01:24:05 +02:00
$metadata [ $key ] = $entry ;
2013-07-29 14:57:31 +02:00
}
}
2013-08-20 05:19:13 +02:00
2013-07-31 01:25:06 +02:00
if ( count ( $md ) > 0 ) {
2013-07-31 01:24:05 +02:00
$f = Application_Model_StoredFile :: createWithFile ( $file , $this -> con );
2013-07-31 01:25:06 +02:00
$f -> setDbColMetadata ( $md );
2013-07-29 14:57:31 +02:00
}
2013-07-29 14:59:04 +02:00
2013-08-03 00:16:23 +02:00
//Use this array to update existing values.
$mds = $historyRecord -> getCcPlayoutHistoryMetaDatas ();
foreach ( $mds as $md ) {
$prevmd [ $md -> getDbKey ()] = $md ;
}
2013-07-29 14:59:04 +02:00
foreach ( $metadata as $key => $val ) {
2013-08-03 00:16:23 +02:00
if ( isset ( $prevmd [ $key ])) {
$meta = $prevmd [ $key ];
$meta -> setDbValue ( $val );
}
else {
$meta = new CcPlayoutHistoryMetaData ();
$meta -> setDbKey ( $key );
$meta -> setDbValue ( $val );
2013-08-20 05:19:13 +02:00
2013-08-03 00:16:23 +02:00
$historyRecord -> addCcPlayoutHistoryMetaData ( $meta );
2013-08-20 05:19:13 +02:00
}
2013-07-29 14:59:04 +02:00
}
2013-07-29 14:57:31 +02:00
$historyRecord -> save ( $this -> con );
2013-07-26 23:33:17 +02:00
$this -> con -> commit ();
}
catch ( Exception $e ) {
$this -> con -> rollback ();
throw $e ;
}
2013-07-09 00:00:02 +02:00
}
2013-08-30 00:32:42 +02:00
2013-08-29 23:40:08 +02:00
//start,end timestamp strings in local timezone.
public function populateShowInstances ( $start , $end ) {
$timezoneLocal = new DateTimeZone ( $this -> timezone );
2013-08-30 00:32:42 +02:00
2013-08-29 23:40:08 +02:00
$startDT = new DateTime ( $start , $timezoneLocal );
$endDT = new DateTime ( $end , $timezoneLocal );
2013-08-30 00:32:42 +02:00
2013-08-29 23:40:08 +02:00
$shows = $this -> getShowList ( $startDT , $endDT );
2013-08-30 00:32:42 +02:00
2013-08-29 23:40:08 +02:00
$select = array ();
2013-08-30 00:32:42 +02:00
2013-08-29 23:40:08 +02:00
foreach ( $shows as & $show ) {
$select [ $show [ " instance_id " ]] = $show [ " name " ];
}
2013-08-30 00:32:42 +02:00
2013-08-29 23:40:08 +02:00
return $select ;
}
2013-07-18 07:31:20 +02:00
2013-07-23 00:11:44 +02:00
public function createPlayedItem ( $data ) {
2013-07-22 16:45:39 +02:00
2013-07-23 00:11:44 +02:00
try {
2013-07-24 00:01:43 +02:00
$form = $this -> makeHistoryItemForm ( null );
$history_id = $form -> getElement ( " his_item_id " );
2013-08-29 23:40:08 +02:00
$instance_id = $data [ " instance_id " ];
2013-08-05 21:05:26 +02:00
$json = array ();
2013-07-26 17:36:58 +02:00
2013-07-23 00:11:44 +02:00
if ( $form -> isValid ( $data )) {
2013-07-24 00:01:43 +02:00
$history_id -> setIgnore ( true );
$values = $form -> getValues ();
2013-07-26 17:36:58 +02:00
2013-07-23 00:11:44 +02:00
Logging :: info ( " created list item " );
Logging :: info ( $values );
2013-07-29 14:57:31 +02:00
2013-08-29 23:40:08 +02:00
$this -> populateTemplateItem ( $values , null , $instance_id );
2013-07-23 00:11:44 +02:00
}
2013-07-24 00:01:43 +02:00
else {
Logging :: info ( " created list item NOT VALID " );
2013-08-20 05:19:13 +02:00
2013-08-05 21:05:26 +02:00
$msgs = $form -> getMessages ();
Logging :: info ( $msgs );
2013-08-20 05:19:13 +02:00
2013-08-23 21:52:49 +02:00
$json [ " form " ] = $form ;
2013-08-05 21:05:26 +02:00
$json [ " error " ] = $msgs ;
2013-07-24 00:01:43 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-05 21:05:26 +02:00
return $json ;
2013-07-23 00:11:44 +02:00
}
catch ( Exception $e ) {
2013-07-31 01:24:05 +02:00
throw $e ;
2013-07-23 00:11:44 +02:00
}
2013-07-22 16:45:39 +02:00
}
2013-07-09 00:00:02 +02:00
/* id is an id in cc_playout_history */
2013-07-24 00:01:43 +02:00
public function editPlayedItem ( $data ) {
2013-07-18 07:31:20 +02:00
2013-07-23 00:11:44 +02:00
try {
2013-07-24 00:01:43 +02:00
$id = $data [ " his_item_id " ];
2013-08-29 23:40:08 +02:00
$instance_id = $data [ " instance_id " ];
2013-07-24 00:01:43 +02:00
$form = $this -> makeHistoryItemForm ( $id );
$history_id = $form -> getElement ( " his_item_id " );
$history_id -> setRequired ( true );
2013-07-26 17:36:58 +02:00
2013-08-05 21:05:26 +02:00
Logging :: info ( $data );
$json = array ();
2013-08-20 05:19:13 +02:00
2013-07-23 00:11:44 +02:00
if ( $form -> isValid ( $data )) {
2013-07-26 17:36:58 +02:00
$history_id -> setIgnore ( true );
2013-07-24 00:01:43 +02:00
$values = $form -> getValues ();
Logging :: info ( " edited list item " );
Logging :: info ( $values );
2013-08-20 05:19:13 +02:00
2013-08-29 23:40:08 +02:00
$this -> populateTemplateItem ( $values , $id , $instance_id );
2013-07-24 00:01:43 +02:00
}
else {
Logging :: info ( " edited list item NOT VALID " );
2013-08-20 05:19:13 +02:00
2013-08-05 21:05:26 +02:00
$msgs = $form -> getMessages ();
Logging :: info ( $msgs );
2013-08-20 05:19:13 +02:00
2013-08-23 21:52:49 +02:00
$json [ " form " ] = $form ;
2013-08-05 21:05:26 +02:00
$json [ " error " ] = $msgs ;
2013-07-24 00:01:43 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-05 21:05:26 +02:00
return $json ;
2013-07-23 00:11:44 +02:00
}
catch ( Exception $e ) {
2013-08-05 21:05:26 +02:00
throw $e ;
2013-07-23 00:11:44 +02:00
}
2013-07-09 00:00:02 +02:00
}
2013-07-18 07:31:20 +02:00
2013-07-09 00:00:02 +02:00
/* id is an id in cc_files */
2013-07-18 07:31:20 +02:00
public function editPlayedFile ( $data ) {
2013-07-24 00:01:43 +02:00
try {
2013-08-12 21:06:26 +02:00
$id = $data [ " his_file_id " ];
$form = $form = $this -> makeHistoryFileForm ( $id );
2013-08-12 21:08:09 +02:00
$history_id = $form -> getElement ( " his_file_id " );
2013-08-12 21:06:26 +02:00
$history_id -> setRequired ( true );
2013-07-26 17:36:58 +02:00
2013-08-12 21:06:26 +02:00
Logging :: info ( $data );
$json = array ();
2013-07-26 17:36:58 +02:00
2013-07-24 00:01:43 +02:00
if ( $form -> isValid ( $data )) {
2013-08-12 21:08:09 +02:00
$history_id -> setIgnore ( true );
2013-08-12 21:06:26 +02:00
$values = $form -> getValues ();
2013-07-26 17:36:58 +02:00
2013-08-12 21:08:09 +02:00
Logging :: info ( " edited list item " );
Logging :: info ( $values );
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$this -> populateTemplateFile ( $values , $id );
}
else {
2013-08-12 21:08:09 +02:00
$msgs = $form -> getMessages ();
Logging :: info ( $msgs );
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$json [ " error " ] = $msgs ;
2013-07-24 00:01:43 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
return $json ;
2013-07-26 17:36:58 +02:00
2013-07-24 00:01:43 +02:00
$this -> con -> commit ();
}
catch ( Exception $e ) {
$this -> con -> rollback ();
Logging :: info ( $e );
throw $e ;
}
2013-07-18 07:31:20 +02:00
return $json ;
2013-07-09 00:00:02 +02:00
}
2013-07-26 17:36:58 +02:00
2013-07-24 00:01:43 +02:00
/* id is an id in cc_playout_history */
public function deletePlayedItem ( $id ) {
2013-07-26 17:36:58 +02:00
2013-07-24 00:01:43 +02:00
$this -> con -> beginTransaction ();
2013-07-26 17:36:58 +02:00
2013-07-24 00:01:43 +02:00
try {
2013-07-26 17:36:58 +02:00
2013-07-24 00:01:43 +02:00
$record = CcPlayoutHistoryQuery :: create () -> findPk ( $id , $this -> con );
$record -> delete ( $this -> con );
2013-07-26 17:36:58 +02:00
2013-07-24 00:01:43 +02:00
$this -> con -> commit ();
}
catch ( Exception $e ) {
$this -> con -> rollback ();
Logging :: info ( $e );
throw $e ;
}
}
2013-08-29 05:30:15 +02:00
2013-08-20 23:23:48 +02:00
/* id is an id in cc_playout_history */
public function deletePlayedItems ( $ids ) {
2013-08-29 05:30:15 +02:00
2013-08-20 23:23:48 +02:00
$this -> con -> beginTransaction ();
2013-08-29 05:30:15 +02:00
2013-08-20 23:23:48 +02:00
try {
2013-08-29 05:30:15 +02:00
2013-08-20 23:23:48 +02:00
$records = CcPlayoutHistoryQuery :: create () -> findPks ( $ids , $this -> con );
$records -> delete ( $this -> con );
2013-08-29 05:30:15 +02:00
2013-08-20 23:23:48 +02:00
$this -> con -> commit ();
}
catch ( Exception $e ) {
$this -> con -> rollback ();
Logging :: info ( $e );
throw $e ;
}
2013-08-20 23:23:15 +02:00
}
2013-07-26 17:36:58 +02:00
2013-07-23 00:11:44 +02:00
//---------------- Following code is for History Templates --------------------------//
2013-07-26 17:36:58 +02:00
2013-07-29 14:57:31 +02:00
public function getFieldTypes () {
$fields = array (
2013-08-20 05:19:13 +02:00
//TEMPLATE_DATE,
//TEMPLATE_TIME,
//TEMPLATE_DATETIME,
2013-07-29 14:59:04 +02:00
TEMPLATE_STRING ,
TEMPLATE_BOOLEAN ,
TEMPLATE_INT ,
2013-07-29 14:57:31 +02:00
TEMPLATE_FLOAT ,
);
return $fields ;
}
2013-08-29 05:30:15 +02:00
2013-08-20 23:23:48 +02:00
private function getPhpCasts () {
2013-08-29 05:30:15 +02:00
2013-08-20 23:23:48 +02:00
$fields = array (
TEMPLATE_DATE => " strval " ,
TEMPLATE_TIME => " strval " ,
TEMPLATE_DATETIME => " strval " ,
TEMPLATE_STRING => " strval " ,
TEMPLATE_BOOLEAN => " intval " , //boolval only exists in php 5.5+ wtf?
TEMPLATE_INT => " intval " ,
TEMPLATE_FLOAT => " floatval " ,
);
2013-08-29 05:30:15 +02:00
2013-08-20 23:23:48 +02:00
return $fields ;
2013-08-20 23:23:15 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
private function getSqlTypes () {
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$fields = array (
TEMPLATE_DATE => " date " ,
TEMPLATE_TIME => " time " ,
TEMPLATE_DATETIME => " datetime " ,
TEMPLATE_STRING => " text " ,
TEMPLATE_BOOLEAN => " boolean " ,
TEMPLATE_INT => " integer " ,
TEMPLATE_FLOAT => " float " ,
);
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
return $fields ;
2013-08-01 22:36:18 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-29 22:31:01 +02:00
public function getFileMetadataTypes () {
2013-08-20 05:19:13 +02:00
2013-07-29 22:32:05 +02:00
$fileMD = array (
2013-08-07 23:55:18 +02:00
array ( " name " => MDATA_KEY_TITLE , " label " => _ ( " Title " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_CREATOR , " label " => _ ( " Creator " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_SOURCE , " label " => _ ( " Album " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_DURATION , " label " => _ ( " Length " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_GENRE , " label " => _ ( " Genre " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_MOOD , " label " => _ ( " Mood " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_LABEL , " label " => _ ( " Label " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_COMPOSER , " label " => _ ( " Composer " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_ISRC , " label " => _ ( " ISRC " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_COPYRIGHT , " label " => _ ( " Copyright " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_YEAR , " label " => _ ( " Year " ), " type " => TEMPLATE_INT ),
array ( " name " => MDATA_KEY_TRACKNUMBER , " label " => _ ( " Track " ), " type " => TEMPLATE_INT ),
array ( " name " => MDATA_KEY_CONDUCTOR , " label " => _ ( " Conductor " ), " type " => TEMPLATE_STRING ),
array ( " name " => MDATA_KEY_LANGUAGE , " label " => _ ( " Language " ), " type " => TEMPLATE_STRING ),
2013-07-29 22:31:01 +02:00
);
2013-08-20 05:19:13 +02:00
2013-07-29 22:31:01 +02:00
return $fileMD ;
}
2013-07-29 14:57:31 +02:00
2013-07-31 01:24:05 +02:00
public function mandatoryItemFields () {
2013-07-29 14:57:31 +02:00
2013-07-31 01:24:05 +02:00
$fields = array ( " starts " , " ends " );
2013-07-29 14:57:31 +02:00
return $fields ;
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
public function mandatoryFileFields () {
2013-08-20 05:19:13 +02:00
2013-08-12 21:06:26 +02:00
$fields = array ( " played " );
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
return $fields ;
2013-08-02 21:29:39 +02:00
}
2013-07-26 17:36:58 +02:00
2013-07-23 00:11:44 +02:00
private function defaultItemTemplate () {
2013-07-26 17:36:58 +02:00
2013-07-31 01:24:05 +02:00
$template = array ();
2013-07-23 00:11:44 +02:00
$fields = array ();
2013-07-26 17:36:58 +02:00
2013-08-07 23:55:18 +02:00
$fields [] = array ( " name " => " starts " , " label " => _ ( " Start Time " ), " type " => TEMPLATE_DATETIME , " isFileMd " => false );
$fields [] = array ( " name " => " ends " , " label " => _ ( " End Time " ), " type " => TEMPLATE_DATETIME , " isFileMd " => false );
$fields [] = array ( " name " => MDATA_KEY_TITLE , " label " => _ ( " Title " ), " type " => TEMPLATE_STRING , " isFileMd " => true ); //these fields can be populated from an associated file.
$fields [] = array ( " name " => MDATA_KEY_CREATOR , " label " => _ ( " Creator " ), " type " => TEMPLATE_STRING , " isFileMd " => true );
2013-07-26 17:36:58 +02:00
2013-08-02 21:29:39 +02:00
$template [ " name " ] = " Log Sheet " . date ( " Y-m-d H:i:s " ) . " Template " ;
2013-07-31 01:24:05 +02:00
$template [ " fields " ] = $fields ;
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
return $template ;
2013-07-23 00:11:44 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
/*
* Default File Summary Template . Taken from The Czech radio requirements ( customer requested this in the past ) .
*/
2013-08-02 21:30:35 +02:00
private function defaultFileTemplate () {
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
$template = array ();
$fields = array ();
2013-08-20 05:19:13 +02:00
2013-08-07 23:55:18 +02:00
$fields [] = array ( " name " => MDATA_KEY_TITLE , " label " => _ ( " Title " ), " type " => TEMPLATE_STRING , " isFileMd " => true );
$fields [] = array ( " name " => MDATA_KEY_CREATOR , " label " => _ ( " Creator " ), " type " => TEMPLATE_STRING , " isFileMd " => true );
$fields [] = array ( " name " => " played " , " label " => _ ( " Played " ), " type " => TEMPLATE_INT , " isFileMd " => false );
$fields [] = array ( " name " => MDATA_KEY_DURATION , " label " => _ ( " Length " ), " type " => TEMPLATE_STRING , " isFileMd " => true );
$fields [] = array ( " name " => MDATA_KEY_COMPOSER , " label " => _ ( " Composer " ), " type " => TEMPLATE_STRING , " isFileMd " => true );
$fields [] = array ( " name " => MDATA_KEY_COPYRIGHT , " label " => _ ( " Copyright " ), " type " => TEMPLATE_STRING , " isFileMd " => true );
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
$template [ " name " ] = " File Summary " . date ( " Y-m-d H:i:s " ) . " Template " ;
$template [ " fields " ] = $fields ;
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
return $template ;
2013-08-02 21:29:39 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
public function loadTemplate ( $id ) {
2013-07-26 17:36:58 +02:00
2013-07-31 01:25:06 +02:00
try {
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
if ( ! is_numeric ( $id )) {
throw new Exception ( " Error: $id is not numeric. " );
2013-08-02 21:29:39 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
$template = CcPlayoutHistoryTemplateQuery :: create () -> findPk ( $id , $this -> con );
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
if ( empty ( $template )) {
throw new Exception ( " Error: Template $id does not exist. " );
}
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
$c = new Criteria ();
$c -> addAscendingOrderByColumn ( CcPlayoutHistoryTemplateFieldPeer :: POSITION );
$config = $template -> getCcPlayoutHistoryTemplateFields ( $c , $this -> con );
$fields = array ();
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
foreach ( $config as $item ) {
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
$fields [] = array (
2013-08-07 23:55:18 +02:00
" name " => $item -> getDbName (),
" label " => $item -> getDbLabel (),
2013-07-31 01:24:05 +02:00
" type " => $item -> getDbType (),
" isFileMd " => $item -> getDbIsFileMD (),
" id " => $item -> getDbId ()
);
}
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
$data = array ();
2013-08-03 00:16:23 +02:00
$data [ " id " ] = $template -> getDbId ();
2013-07-31 01:24:05 +02:00
$data [ " name " ] = $template -> getDbName ();
$data [ " fields " ] = $fields ;
2013-08-02 21:29:39 +02:00
$data [ " type " ] = $template -> getDbType ();
2013-08-20 05:19:13 +02:00
2013-07-31 01:25:06 +02:00
return $data ;
}
catch ( Exception $e ) {
throw $e ;
2013-07-31 01:24:05 +02:00
}
}
2013-07-26 17:36:58 +02:00
2013-07-31 01:24:05 +02:00
public function getItemTemplate ( $id ) {
2013-07-26 17:36:58 +02:00
2013-07-31 01:24:05 +02:00
if ( is_numeric ( $id )) {
Logging :: info ( " template id is: $id " );
$template = $this -> loadTemplate ( $id );
2013-07-23 00:11:44 +02:00
}
else {
Logging :: info ( " Using default template " );
$template = $this -> defaultItemTemplate ();
}
2013-07-26 17:36:58 +02:00
2013-07-23 00:11:44 +02:00
return $template ;
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
public function getTemplates ( $type ) {
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
$list = array ();
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
try {
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
$query = CcPlayoutHistoryTemplateQuery :: create ()
-> setFormatter ( ModelCriteria :: FORMAT_ON_DEMAND );
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
if ( isset ( $type )) {
$templates = $query -> findByDbType ( $type );
}
else {
$templates = $query -> find ();
}
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
foreach ( $templates as $template ) {
$list [ $template -> getDbId ()] = $template -> getDbName ();
}
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
return $list ;
2013-07-31 01:25:06 +02:00
}
catch ( Exception $e ) {
throw $e ;
2013-07-31 01:24:05 +02:00
}
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
public function getListItemTemplates () {
return $this -> getTemplates ( self :: TEMPLATE_TYPE_ITEM );
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
public function getFileTemplates () {
return $this -> getTemplates ( self :: TEMPLATE_TYPE_FILE );
2013-08-02 21:29:39 +02:00
}
2013-08-20 05:19:13 +02:00
private function datatablesColumns ( $fields ) {
2013-08-02 21:30:35 +02:00
$columns = array ();
2013-08-20 05:19:13 +02:00
foreach ( $fields as $field ) {
2013-08-07 23:55:18 +02:00
$label = $field [ " label " ];
2013-08-02 21:30:35 +02:00
$key = $field [ " name " ];
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
$columns [] = array (
2013-08-07 23:55:18 +02:00
" sTitle " => $label ,
2013-08-02 21:30:35 +02:00
" mDataProp " => $key ,
2013-08-14 22:38:59 +02:00
" sClass " => " his_ { $key } " ,
" sDataType " => $field [ " type " ]
2013-08-02 21:30:35 +02:00
);
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
return $columns ;
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
public function getDatatablesLogSheetColumns () {
2013-08-20 05:19:13 +02:00
//need to prepend a checkbox column.
$checkbox = array (
" sTitle " => " " ,
" mDataProp " => " checkbox " ,
" sClass " => " his_checkbox " ,
" bSortable " => false
);
2013-07-31 23:38:48 +02:00
try {
2013-08-20 05:19:13 +02:00
$template = $this -> getConfiguredItemTemplate ();
2013-08-20 05:20:26 +02:00
$fields = $template [ " fields " ];
2013-08-20 05:19:13 +02:00
$columns = $this -> datatablesColumns ( $fields );
array_unshift ( $columns , $checkbox );
return $columns ;
2013-07-31 23:39:45 +02:00
}
catch ( Exception $e ) {
throw $e ;
2013-07-31 23:38:48 +02:00
}
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
public function getDatatablesFileSummaryColumns () {
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
try {
$template = $this -> getConfiguredFileTemplate ();
2013-08-20 05:19:13 +02:00
return $this -> datatablesColumns ( $template [ " fields " ]);
2013-08-02 21:30:35 +02:00
}
catch ( Exception $e ) {
throw $e ;
}
2013-08-02 21:29:39 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 01:25:06 +02:00
public function getConfiguredItemTemplate () {
2013-08-20 05:19:13 +02:00
2013-07-31 01:25:06 +02:00
try {
2013-07-31 01:24:05 +02:00
$id = Application_Model_Preference :: GetHistoryItemTemplate ();
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
if ( is_numeric ( $id )) {
$template = $this -> loadTemplate ( $id );
}
else {
$template = $this -> defaultItemTemplate ();
}
return $template ;
2013-07-31 01:25:06 +02:00
}
catch ( Exception $e ) {
throw $e ;
}
2013-07-31 01:24:05 +02:00
}
2013-08-20 05:19:13 +02:00
2013-07-31 01:24:05 +02:00
public function setConfiguredItemTemplate ( $id ) {
try {
Application_Model_Preference :: SetHistoryItemTemplate ( $id );
}
2013-07-31 01:25:06 +02:00
catch ( Exception $e ) {
throw $e ;
2013-07-31 01:24:05 +02:00
}
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
public function getConfiguredFileTemplate () {
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
try {
$id = Application_Model_Preference :: GetHistoryFileTemplate ();
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
if ( is_numeric ( $id )) {
$template = $this -> loadTemplate ( $id );
}
else {
$template = $this -> defaultFileTemplate ();
}
return $template ;
}
catch ( Exception $e ) {
throw $e ;
}
2013-08-02 21:29:39 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
public function setConfiguredFileTemplate ( $id ) {
try {
Application_Model_Preference :: SetHistoryFileTemplate ( $id );
}
catch ( Exception $e ) {
throw $e ;
}
2013-08-02 21:29:39 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
public function setConfiguredTemplate ( $id ) {
try {
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
$template = $this -> loadTemplate ( $id );
$type = $template [ " type " ];
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
$setTemplate = " setConfigured " . ucfirst ( $type ) . " Template " ;
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
$this -> $setTemplate ( $id );
}
catch ( Exception $e ) {
throw $e ;
}
2013-08-02 21:29:39 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
public function getConfiguredTemplateIds () {
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
try {
$id = Application_Model_Preference :: GetHistoryItemTemplate ();
2013-08-02 21:29:39 +02:00
$id2 = Application_Model_Preference :: GetHistoryFileTemplate ();
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
$configured = array ();
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
if ( is_numeric ( $id )) {
$configured [] = $id ;
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:30:35 +02:00
if ( is_numeric ( $id2 )) {
$configured [] = $id2 ;
2013-08-02 21:29:39 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
return $configured ;
2013-08-01 22:37:10 +02:00
}
catch ( Exception $e ) {
throw $e ;
2013-08-01 22:36:18 +02:00
}
}
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
public function createTemplate ( $config ) {
2013-08-20 05:19:13 +02:00
2013-07-29 23:22:44 +02:00
$this -> con -> beginTransaction ();
2013-08-20 05:19:13 +02:00
2013-07-29 23:22:44 +02:00
try {
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
$type = $config [ " type " ];
2013-08-20 05:19:13 +02:00
2013-08-02 21:29:39 +02:00
$method = " default " . ucfirst ( $type ) . " Template " ;
$default = $this -> $method ();
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
$name = isset ( $config [ " name " ]) ? $config [ " name " ] : $default [ " name " ];
$fields = isset ( $config [ " fields " ]) ? $config [ " fields " ] : $default [ " fields " ];
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
$doSetDefault = isset ( $config [ 'setDefault' ]) ? $config [ 'setDefault' ] : false ;
2013-08-20 05:19:13 +02:00
2013-07-29 23:22:44 +02:00
$template = new CcPlayoutHistoryTemplate ();
2013-08-01 22:36:18 +02:00
$template -> setDbName ( $name );
2013-08-02 21:29:39 +02:00
$template -> setDbType ( $type );
2013-08-01 22:36:18 +02:00
2013-07-29 23:35:07 +02:00
foreach ( $fields as $index => $field ) {
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
$isMd = ( $field [ " isFileMd " ] == 'true' ) ? true : false ;
2013-08-20 05:19:13 +02:00
2013-07-29 23:35:07 +02:00
$templateField = new CcPlayoutHistoryTemplateField ();
$templateField -> setDbName ( $field [ " name " ]);
2013-08-07 23:55:18 +02:00
$templateField -> setDbLabel ( $field [ " label " ]);
2013-07-29 23:35:07 +02:00
$templateField -> setDbType ( $field [ " type " ]);
2013-07-31 01:24:05 +02:00
$templateField -> setDbIsFileMD ( $isMd );
2013-07-29 23:35:07 +02:00
$templateField -> setDbPosition ( $index );
2013-08-20 05:19:13 +02:00
2013-07-29 23:35:07 +02:00
$template -> addCcPlayoutHistoryTemplateField ( $templateField );
}
2013-08-20 05:19:13 +02:00
2013-07-29 23:35:07 +02:00
$template -> save ( $this -> con );
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
if ( $doSetDefault ) {
2013-07-31 01:24:05 +02:00
$this -> setConfiguredItemTemplate ( $template -> getDbid ());
}
2013-08-20 05:19:13 +02:00
2013-07-29 23:22:44 +02:00
$this -> con -> commit ();
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
return $template -> getDbid ();
2013-07-29 23:22:44 +02:00
}
2013-07-31 01:25:06 +02:00
catch ( Exception $e ) {
$this -> con -> rollback ();
throw $e ;
2013-08-20 05:19:13 +02:00
}
2013-07-29 23:21:46 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
public function updateItemTemplate ( $id , $name , $fields , $doSetDefault = false ) {
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$this -> con -> beginTransaction ();
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
try {
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$template = CcPlayoutHistoryTemplateQuery :: create () -> findPk ( $id , $this -> con );
2013-08-01 22:36:18 +02:00
$template -> setDbName ( $name );
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
if ( count ( $fields ) === 0 ) {
$t = $this -> defaultItemTemplate ();
2013-08-20 05:19:13 +02:00
$fields = $t [ " fields " ];
2013-08-01 22:36:18 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$template -> getCcPlayoutHistoryTemplateFields () -> delete ( $this -> con );
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
foreach ( $fields as $index => $field ) {
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$isMd = ( $field [ " isFileMd " ] == 'true' ) ? true : false ;
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$templateField = new CcPlayoutHistoryTemplateField ();
$templateField -> setDbName ( $field [ " name " ]);
$templateField -> setDbType ( $field [ " type " ]);
2013-08-07 23:55:18 +02:00
$templateField -> setDbLabel ( $field [ " label " ]);
2013-08-01 22:37:10 +02:00
$templateField -> setDbIsFileMD ( $isMd );
$templateField -> setDbPosition ( $index );
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$template -> addCcPlayoutHistoryTemplateField ( $templateField );
}
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$template -> save ( $this -> con );
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
if ( $doSetDefault ) {
$this -> setConfiguredItemTemplate ( $template -> getDbid ());
}
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$this -> con -> commit ();
}
catch ( Exception $e ) {
$this -> con -> rollback ();
throw $e ;
}
2013-08-01 22:36:18 +02:00
}
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
public function deleteTemplate ( $id ) {
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
$this -> con -> beginTransaction ();
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
try {
2013-08-20 05:19:13 +02:00
2013-08-01 22:36:18 +02:00
$template = CcPlayoutHistoryTemplateQuery :: create () -> findPk ( $id , $this -> con );
$template -> delete ( $this -> con );
2013-08-20 05:19:13 +02:00
2013-08-01 22:37:10 +02:00
$this -> con -> commit ();
}
catch ( Exception $e ) {
$this -> con -> rollback ();
throw $e ;
2013-08-01 22:36:18 +02:00
}
}
2013-07-03 21:19:05 +02:00
}