diff --git a/airtime_mvc/application/controllers/PlayouthistoryController.php b/airtime_mvc/application/controllers/PlayouthistoryController.php index c0c323932..0f50a4f04 100644 --- a/airtime_mvc/application/controllers/PlayouthistoryController.php +++ b/airtime_mvc/application/controllers/PlayouthistoryController.php @@ -17,8 +17,7 @@ class PlayouthistoryController extends Zend_Controller_Action ->addActionContext('create-template', 'json') ->addActionContext('edit-template', 'json') ->addActionContext('delete-template', 'json') - ->addActionContext('create-template-field', 'json') - ->addActionContext('delete-template-field', 'json') + ->addActionContext('set-item-template-default', 'json') ->initContext(); } @@ -130,12 +129,18 @@ class PlayouthistoryController extends Zend_Controller_Action public function createListItemAction() { - $request = $this->getRequest(); - $params = $request->getPost(); - Logging::info($params); - - $historyService = new Application_Service_HistoryService(); - $historyService->createPlayedItem($params); + try { + $request = $this->getRequest(); + $params = $request->getPost(); + Logging::info($params); + + $historyService = new Application_Service_HistoryService(); + $historyService->createPlayedItem($params); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } } public function editListItemAction() @@ -190,20 +195,34 @@ class PlayouthistoryController extends Zend_Controller_Action public function configureItemTemplateAction() { - $CC_CONFIG = Config::getConfig(); - $baseUrl = Application_Common_OsPath::getBaseDir(); - - $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/template.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); - - $template_id = $this->_getParam('id', null); - - $historyService = new Application_Service_HistoryService(); - $mandatoryFields = $historyService->mandatoryItemTemplate(); - - $this->view->template_id = $template_id; - $this->view->fileMD = $historyService->getFileMetadataTypes(); - $this->view->fields = $historyService->getFieldTypes(); - $this->view->required = $mandatoryFields; + $request = $this->getRequest(); + $params = $request->getPost(); + Logging::info($params); + + try { + $CC_CONFIG = Config::getConfig(); + $baseUrl = Application_Common_OsPath::getBaseDir(); + + $this->view->headScript()->appendFile($baseUrl.'js/airtime/playouthistory/template.js?'.$CC_CONFIG['airtime_version'],'text/javascript'); + + $template_id = $this->_getParam('id', null); + + $historyService = new Application_Service_HistoryService(); + $mandatoryFields = $historyService->mandatoryItemFields(); + $template = $historyService->getItemTemplate($template_id); + + $this->view->template_id = $template_id; + $this->view->template_name = $template["name"]; + $this->view->template_fields = $template["fields"]; + $this->view->template_list = $historyService->getListItemTemplates(); + $this->view->fileMD = $historyService->getFileMetadataTypes(); + $this->view->fields = $historyService->getFieldTypes(); + $this->view->required_fields = $mandatoryFields; + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } } public function createTemplateAction() @@ -212,8 +231,36 @@ class PlayouthistoryController extends Zend_Controller_Action $params = $request->getPost(); Logging::info($params); - $historyService = new Application_Service_HistoryService(); - $historyService->createItemTemplate($params); + try { + $historyService = new Application_Service_HistoryService(); + $historyService->createItemTemplate($params); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } + } + + public function setItemTemplateDefaultAction() + { + $request = $this->getRequest(); + $params = $request->getPost(); + Logging::info($params); + + $template_id = $this->_getParam('id', null); + + if (empty($template_id)) { + return; + } + + try { + $historyService = new Application_Service_HistoryService(); + $historyService->setConfiguredItemTemplate($template_id); + } + catch (Exception $e) { + Logging::info($e); + Logging::info($e->getMessage()); + } } public function editTemplateAction() @@ -225,14 +272,4 @@ class PlayouthistoryController extends Zend_Controller_Action { } - - public function createTemplateFieldAction() - { - - } - - public function deleteTemplateFieldAction() - { - - } } diff --git a/airtime_mvc/application/forms/EditHistoryItem.php b/airtime_mvc/application/forms/EditHistoryItem.php index e165a009c..0e63c3e9b 100644 --- a/airtime_mvc/application/forms/EditHistoryItem.php +++ b/airtime_mvc/application/forms/EditHistoryItem.php @@ -173,13 +173,17 @@ class Application_Form_EditHistoryItem extends Zend_Form )); } - public function createFromTemplate($template) { + public function createFromTemplate($template, $required) { $templateSubForm = $this->getSubForm(self::ID_PREFIX.'template'); for ($i = 0, $len = count($template); $i < $len; $i++) { $item = $template[$i]; + //don't dynamically add this as it should be included in the init() function already. + if (in_array($item["name"], $required)) { + continue; + } $formElType = $this->formElTypes[$item[self::ITEM_TYPE]]; diff --git a/airtime_mvc/application/models/airtime/map/CcPlayoutHistoryTemplateTableMap.php b/airtime_mvc/application/models/airtime/map/CcPlayoutHistoryTemplateTableMap.php index 26af8679b..e5aea573d 100644 --- a/airtime_mvc/application/models/airtime/map/CcPlayoutHistoryTemplateTableMap.php +++ b/airtime_mvc/application/models/airtime/map/CcPlayoutHistoryTemplateTableMap.php @@ -39,7 +39,8 @@ class CcPlayoutHistoryTemplateTableMap extends TableMap { $this->setPrimaryKeyMethodInfo('cc_playout_history_template_id_seq'); // columns $this->addPrimaryKey('ID', 'DbId', 'INTEGER', true, null, null); - $this->addColumn('TEMPLATE_NAME', 'DbName', 'VARCHAR', true, 128, null); + $this->addColumn('NAME', 'DbName', 'VARCHAR', true, 128, null); + $this->addColumn('TYPE', 'DbType', 'VARCHAR', true, 35, null); // validators } // initialize() diff --git a/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplate.php b/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplate.php index 6d4804d32..222227af6 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplate.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplate.php @@ -31,10 +31,16 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi protected $id; /** - * The value for the template_name field. + * The value for the name field. * @var string */ - protected $template_name; + protected $name; + + /** + * The value for the type field. + * @var string + */ + protected $type; /** * @var array CcPlayoutHistoryTemplateField[] Collection to store aggregation of CcPlayoutHistoryTemplateField objects. @@ -66,13 +72,23 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi } /** - * Get the [template_name] column value. + * Get the [name] column value. * * @return string */ public function getDbName() { - return $this->template_name; + return $this->name; + } + + /** + * Get the [type] column value. + * + * @return string + */ + public function getDbType() + { + return $this->type; } /** @@ -96,7 +112,7 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi } // setDbId() /** - * Set the value of [template_name] column. + * Set the value of [name] column. * * @param string $v new value * @return CcPlayoutHistoryTemplate The current object (for fluent API support) @@ -107,14 +123,34 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi $v = (string) $v; } - if ($this->template_name !== $v) { - $this->template_name = $v; - $this->modifiedColumns[] = CcPlayoutHistoryTemplatePeer::TEMPLATE_NAME; + if ($this->name !== $v) { + $this->name = $v; + $this->modifiedColumns[] = CcPlayoutHistoryTemplatePeer::NAME; } return $this; } // setDbName() + /** + * Set the value of [type] column. + * + * @param string $v new value + * @return CcPlayoutHistoryTemplate The current object (for fluent API support) + */ + public function setDbType($v) + { + if ($v !== null) { + $v = (string) $v; + } + + if ($this->type !== $v) { + $this->type = $v; + $this->modifiedColumns[] = CcPlayoutHistoryTemplatePeer::TYPE; + } + + return $this; + } // setDbType() + /** * Indicates whether the columns in this object are only set to default values. * @@ -148,7 +184,8 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi try { $this->id = ($row[$startcol + 0] !== null) ? (int) $row[$startcol + 0] : null; - $this->template_name = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null; + $this->name = ($row[$startcol + 1] !== null) ? (string) $row[$startcol + 1] : null; + $this->type = ($row[$startcol + 2] !== null) ? (string) $row[$startcol + 2] : null; $this->resetModified(); $this->setNew(false); @@ -157,7 +194,7 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi $this->ensureConsistency(); } - return $startcol + 2; // 2 = CcPlayoutHistoryTemplatePeer::NUM_COLUMNS - CcPlayoutHistoryTemplatePeer::NUM_LAZY_LOAD_COLUMNS). + return $startcol + 3; // 3 = CcPlayoutHistoryTemplatePeer::NUM_COLUMNS - CcPlayoutHistoryTemplatePeer::NUM_LAZY_LOAD_COLUMNS). } catch (Exception $e) { throw new PropelException("Error populating CcPlayoutHistoryTemplate object", $e); @@ -480,6 +517,9 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi case 1: return $this->getDbName(); break; + case 2: + return $this->getDbType(); + break; default: return null; break; @@ -505,6 +545,7 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi $result = array( $keys[0] => $this->getDbId(), $keys[1] => $this->getDbName(), + $keys[2] => $this->getDbType(), ); return $result; } @@ -542,6 +583,9 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi case 1: $this->setDbName($value); break; + case 2: + $this->setDbType($value); + break; } // switch() } @@ -568,6 +612,7 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi if (array_key_exists($keys[0], $arr)) $this->setDbId($arr[$keys[0]]); if (array_key_exists($keys[1], $arr)) $this->setDbName($arr[$keys[1]]); + if (array_key_exists($keys[2], $arr)) $this->setDbType($arr[$keys[2]]); } /** @@ -580,7 +625,8 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi $criteria = new Criteria(CcPlayoutHistoryTemplatePeer::DATABASE_NAME); if ($this->isColumnModified(CcPlayoutHistoryTemplatePeer::ID)) $criteria->add(CcPlayoutHistoryTemplatePeer::ID, $this->id); - if ($this->isColumnModified(CcPlayoutHistoryTemplatePeer::TEMPLATE_NAME)) $criteria->add(CcPlayoutHistoryTemplatePeer::TEMPLATE_NAME, $this->template_name); + if ($this->isColumnModified(CcPlayoutHistoryTemplatePeer::NAME)) $criteria->add(CcPlayoutHistoryTemplatePeer::NAME, $this->name); + if ($this->isColumnModified(CcPlayoutHistoryTemplatePeer::TYPE)) $criteria->add(CcPlayoutHistoryTemplatePeer::TYPE, $this->type); return $criteria; } @@ -642,7 +688,8 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi */ public function copyInto($copyObj, $deepCopy = false) { - $copyObj->setDbName($this->template_name); + $copyObj->setDbName($this->name); + $copyObj->setDbType($this->type); if ($deepCopy) { // important: temporarily setNew(false) because this affects the behavior of @@ -815,7 +862,8 @@ abstract class BaseCcPlayoutHistoryTemplate extends BaseObject implements Persi public function clear() { $this->id = null; - $this->template_name = null; + $this->name = null; + $this->type = null; $this->alreadyInSave = false; $this->alreadyInValidation = false; $this->clearAllReferences(); diff --git a/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplatePeer.php b/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplatePeer.php index 58a3da223..9e1d216f1 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplatePeer.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplatePeer.php @@ -26,7 +26,7 @@ abstract class BaseCcPlayoutHistoryTemplatePeer { const TM_CLASS = 'CcPlayoutHistoryTemplateTableMap'; /** The total number of columns. */ - const NUM_COLUMNS = 2; + const NUM_COLUMNS = 3; /** The number of lazy-loaded columns. */ const NUM_LAZY_LOAD_COLUMNS = 0; @@ -34,8 +34,11 @@ abstract class BaseCcPlayoutHistoryTemplatePeer { /** the column name for the ID field */ const ID = 'cc_playout_history_template.ID'; - /** the column name for the TEMPLATE_NAME field */ - const TEMPLATE_NAME = 'cc_playout_history_template.TEMPLATE_NAME'; + /** the column name for the NAME field */ + const NAME = 'cc_playout_history_template.NAME'; + + /** the column name for the TYPE field */ + const TYPE = 'cc_playout_history_template.TYPE'; /** * An identiy map to hold any loaded instances of CcPlayoutHistoryTemplate objects. @@ -53,12 +56,12 @@ abstract class BaseCcPlayoutHistoryTemplatePeer { * e.g. self::$fieldNames[self::TYPE_PHPNAME][0] = 'Id' */ private static $fieldNames = array ( - BasePeer::TYPE_PHPNAME => array ('DbId', 'DbName', ), - BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbName', ), - BasePeer::TYPE_COLNAME => array (self::ID, self::TEMPLATE_NAME, ), - BasePeer::TYPE_RAW_COLNAME => array ('ID', 'TEMPLATE_NAME', ), - BasePeer::TYPE_FIELDNAME => array ('id', 'template_name', ), - BasePeer::TYPE_NUM => array (0, 1, ) + BasePeer::TYPE_PHPNAME => array ('DbId', 'DbName', 'DbType', ), + BasePeer::TYPE_STUDLYPHPNAME => array ('dbId', 'dbName', 'dbType', ), + BasePeer::TYPE_COLNAME => array (self::ID, self::NAME, self::TYPE, ), + BasePeer::TYPE_RAW_COLNAME => array ('ID', 'NAME', 'TYPE', ), + BasePeer::TYPE_FIELDNAME => array ('id', 'name', 'type', ), + BasePeer::TYPE_NUM => array (0, 1, 2, ) ); /** @@ -68,12 +71,12 @@ abstract class BaseCcPlayoutHistoryTemplatePeer { * e.g. self::$fieldNames[BasePeer::TYPE_PHPNAME]['Id'] = 0 */ private static $fieldKeys = array ( - BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbName' => 1, ), - BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbName' => 1, ), - BasePeer::TYPE_COLNAME => array (self::ID => 0, self::TEMPLATE_NAME => 1, ), - BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'TEMPLATE_NAME' => 1, ), - BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'template_name' => 1, ), - BasePeer::TYPE_NUM => array (0, 1, ) + BasePeer::TYPE_PHPNAME => array ('DbId' => 0, 'DbName' => 1, 'DbType' => 2, ), + BasePeer::TYPE_STUDLYPHPNAME => array ('dbId' => 0, 'dbName' => 1, 'dbType' => 2, ), + BasePeer::TYPE_COLNAME => array (self::ID => 0, self::NAME => 1, self::TYPE => 2, ), + BasePeer::TYPE_RAW_COLNAME => array ('ID' => 0, 'NAME' => 1, 'TYPE' => 2, ), + BasePeer::TYPE_FIELDNAME => array ('id' => 0, 'name' => 1, 'type' => 2, ), + BasePeer::TYPE_NUM => array (0, 1, 2, ) ); /** @@ -146,10 +149,12 @@ abstract class BaseCcPlayoutHistoryTemplatePeer { { if (null === $alias) { $criteria->addSelectColumn(CcPlayoutHistoryTemplatePeer::ID); - $criteria->addSelectColumn(CcPlayoutHistoryTemplatePeer::TEMPLATE_NAME); + $criteria->addSelectColumn(CcPlayoutHistoryTemplatePeer::NAME); + $criteria->addSelectColumn(CcPlayoutHistoryTemplatePeer::TYPE); } else { $criteria->addSelectColumn($alias . '.ID'); - $criteria->addSelectColumn($alias . '.TEMPLATE_NAME'); + $criteria->addSelectColumn($alias . '.NAME'); + $criteria->addSelectColumn($alias . '.TYPE'); } } diff --git a/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplateQuery.php b/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplateQuery.php index 58c91dc09..ca2f84229 100644 --- a/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplateQuery.php +++ b/airtime_mvc/application/models/airtime/om/BaseCcPlayoutHistoryTemplateQuery.php @@ -7,10 +7,12 @@ * * * @method CcPlayoutHistoryTemplateQuery orderByDbId($order = Criteria::ASC) Order by the id column - * @method CcPlayoutHistoryTemplateQuery orderByDbName($order = Criteria::ASC) Order by the template_name column + * @method CcPlayoutHistoryTemplateQuery orderByDbName($order = Criteria::ASC) Order by the name column + * @method CcPlayoutHistoryTemplateQuery orderByDbType($order = Criteria::ASC) Order by the type column * * @method CcPlayoutHistoryTemplateQuery groupByDbId() Group by the id column - * @method CcPlayoutHistoryTemplateQuery groupByDbName() Group by the template_name column + * @method CcPlayoutHistoryTemplateQuery groupByDbName() Group by the name column + * @method CcPlayoutHistoryTemplateQuery groupByDbType() Group by the type column * * @method CcPlayoutHistoryTemplateQuery leftJoin($relation) Adds a LEFT JOIN clause to the query * @method CcPlayoutHistoryTemplateQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query @@ -24,10 +26,12 @@ * @method CcPlayoutHistoryTemplate findOneOrCreate(PropelPDO $con = null) Return the first CcPlayoutHistoryTemplate matching the query, or a new CcPlayoutHistoryTemplate object populated from the query conditions when no match is found * * @method CcPlayoutHistoryTemplate findOneByDbId(int $id) Return the first CcPlayoutHistoryTemplate filtered by the id column - * @method CcPlayoutHistoryTemplate findOneByDbName(string $template_name) Return the first CcPlayoutHistoryTemplate filtered by the template_name column + * @method CcPlayoutHistoryTemplate findOneByDbName(string $name) Return the first CcPlayoutHistoryTemplate filtered by the name column + * @method CcPlayoutHistoryTemplate findOneByDbType(string $type) Return the first CcPlayoutHistoryTemplate filtered by the type column * * @method array findByDbId(int $id) Return CcPlayoutHistoryTemplate objects filtered by the id column - * @method array findByDbName(string $template_name) Return CcPlayoutHistoryTemplate objects filtered by the template_name column + * @method array findByDbName(string $name) Return CcPlayoutHistoryTemplate objects filtered by the name column + * @method array findByDbType(string $type) Return CcPlayoutHistoryTemplate objects filtered by the type column * * @package propel.generator.airtime.om */ @@ -155,7 +159,7 @@ abstract class BaseCcPlayoutHistoryTemplateQuery extends ModelCriteria } /** - * Filter the query on the template_name column + * Filter the query on the name column * * @param string $dbName The value to use as filter. * Accepts wildcards (* and % trigger a LIKE) @@ -173,7 +177,29 @@ abstract class BaseCcPlayoutHistoryTemplateQuery extends ModelCriteria $comparison = Criteria::LIKE; } } - return $this->addUsingAlias(CcPlayoutHistoryTemplatePeer::TEMPLATE_NAME, $dbName, $comparison); + return $this->addUsingAlias(CcPlayoutHistoryTemplatePeer::NAME, $dbName, $comparison); + } + + /** + * Filter the query on the type column + * + * @param string $dbType The value to use as filter. + * Accepts wildcards (* and % trigger a LIKE) + * @param string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL + * + * @return CcPlayoutHistoryTemplateQuery The current query, for fluid interface + */ + public function filterByDbType($dbType = null, $comparison = null) + { + if (null === $comparison) { + if (is_array($dbType)) { + $comparison = Criteria::IN; + } elseif (preg_match('/[\%\*]/', $dbType)) { + $dbType = str_replace('*', '%', $dbType); + $comparison = Criteria::LIKE; + } + } + return $this->addUsingAlias(CcPlayoutHistoryTemplatePeer::TYPE, $dbType, $comparison); } /** diff --git a/airtime_mvc/application/services/HistoryService.php b/airtime_mvc/application/services/HistoryService.php index f7653bcad..d3e829232 100644 --- a/airtime_mvc/application/services/HistoryService.php +++ b/airtime_mvc/application/services/HistoryService.php @@ -6,6 +6,9 @@ class Application_Service_HistoryService { private $con; private $timezone; + + const TEMPLATE_TYPE_ITEM = "item"; + const TEMPLATE_TYPE_AGGREGATE = "aggregate"; private $mDataPropMap = array ( "artist" => "artist_name", @@ -39,6 +42,43 @@ class Application_Service_HistoryService public function getListView($startDT, $endDT, $opts) { + /* + +select * from ( + +select track_title.value as track_title, track_title.history_id +from (select * from cc_playout_history_metadata as phm +where key = 'track_title') +as track_title + +) as track_filter + +INNER JOIN + +( +select artist_name.value as artist_name, artist_name.history_id +from (select * from cc_playout_history_metadata as phm +where key = 'artist_name') +as artist_name + +) as artist_filter + +USING (history_id) + +INNER JOIN + +( +select album_title.value as album_title, album_title.history_id +from (select * from cc_playout_history_metadata as phm +where key = 'album_title') +as album_title + +) as album_filter + +USING (history_id) + */ + + $this->translateColumns($opts); $select = array ( @@ -172,9 +212,9 @@ class Application_Service_HistoryService try { $form = new Application_Form_EditHistoryItem(); - $template = $this->getItemTemplate(); - - $form->createFromTemplate($template); + $template = $this->getConfiguredItemTemplate(); + $required = $this->mandatoryItemFields(); + $form->createFromTemplate($template["fields"], $required); return $form; } @@ -214,7 +254,7 @@ class Application_Service_HistoryService $this->con->beginTransaction(); try { - $template = $this->getItemTemplate(); + $template = $this->getConfiguredItemTemplate(); $prefix = Application_Form_EditHistoryItem::ID_PREFIX; $historyRecord = new CcPlayoutHistory(); @@ -233,39 +273,42 @@ class Application_Service_HistoryService $file = $historyRecord->getCcFiles(); + $md = array(); $metadata = array(); + $fields = $template["fields"]; + $required = $this->mandatoryItemFields(); - for ($i = 0, $len = count($template); $i < $len; $i++) { - - $item = $template[$i]; - $key = $item["name"]; - $isFileMd = $item["isFileMd"]; - + for ($i = 0, $len = count($fields); $i < $len; $i++) { + + $field = $fields[$i]; + $key = $field["name"]; + + //required is delt with before this loop. + if (in_array($key, $required)) { + continue; + } + + $isFileMd = $field["isFileMd"]; $entry = $templateValues[$prefix.$key]; - - if (!$isFileMd) { - Logging::info("adding metadata"); - } - else if ($isFileMd && isset($file)) { - Logging::info("adding file metadata associated to a file"); - } - else if ($isFileMd && empty($file)) { - Logging::info("adding file metadata NOT associated to a file"); - $metadata[$key] = $entry; + + if ($isFileMd && isset($file)) { + Logging::info("adding metadata associated to a file for {$key}"); + $md[$key] = $entry; } else { - Logging::info("doing something else"); + Logging::info("adding metadata for {$key}"); + $metadata[$key] = $entry; } - - } - - if (count($metadata) > 0) { - $meta = new CcPlayoutHistoryMetaData(); + + if (count($md) > 0) { + $f = Application_Model_StoredFile::createWithFile($file, $this->con); + $f->setDbColMetadata($md); } foreach ($metadata as $key => $val) { + $meta = new CcPlayoutHistoryMetaData(); $meta->setDbKey($key); $meta->setDbValue($val); @@ -273,12 +316,10 @@ class Application_Service_HistoryService } $historyRecord->save($this->con); - $this->con->commit(); } catch (Exception $e) { $this->con->rollback(); - Logging::info($e); throw $e; } @@ -301,14 +342,11 @@ class Application_Service_HistoryService } else { Logging::info("created list item NOT VALID"); + Logging::info($form->getMessages()); } - - Logging::info($form->getMessages()); - - //return $json; } catch (Exception $e) { - Logging::info($e); + throw $e; } } @@ -435,18 +473,16 @@ class Application_Service_HistoryService return $fileMD; } - public function mandatoryItemTemplate() { + public function mandatoryItemFields() { - $fields = array(); - - $fields[] = array("name" => "starts", "type" => TEMPLATE_DATETIME, "isFileMd" => false); - $fields[] = array("name" => "ends", "type" => TEMPLATE_DATETIME, "isFileMd" => false); + $fields = array("starts", "ends"); return $fields; } private function defaultItemTemplate() { + $template = array(); $fields = array(); $fields[] = array("name" => "starts", "type" => TEMPLATE_DATETIME, "isFileMd" => false); @@ -454,15 +490,48 @@ class Application_Service_HistoryService $fields[] = array("name" => MDATA_KEY_TITLE, "type" => TEMPLATE_STRING, "isFileMd" => true); //these fields can be populated from an associated file. $fields[] = array("name" => MDATA_KEY_CREATOR, "type" => TEMPLATE_STRING, "isFileMd" => true); - return $fields; + $template["name"] = ""; + $template["fields"] = $fields; + + return $template; + } + + private function loadTemplate($id) { + + try { + $template = CcPlayoutHistoryTemplateQuery::create()->findPk($id, $this->con); + + $c = new Criteria(); + $c->addAscendingOrderByColumn(CcPlayoutHistoryTemplateFieldPeer::POSITION); + $config = $template->getCcPlayoutHistoryTemplateFields($c, $this->con); + $fields = array(); + + foreach ($config as $item) { + + $fields[] = array( + "name" => $item->getDbName(), + "type" => $item->getDbType(), + "isFileMd" => $item->getDbIsFileMD(), + "id" => $item->getDbId() + ); + } + + $data = array(); + $data["name"] = $template->getDbName(); + $data["fields"] = $fields; + + return $data; + } + catch (Exception $e) { + throw $e; + } } - private function getItemTemplate() { + public function getItemTemplate($id) { - $template_id = Application_Model_Preference::GetHistoryItemTemplate(); - - if (is_numeric($template_id)) { - Logging::info("template id is: $template_id"); + if (is_numeric($id)) { + Logging::info("template id is: $id"); + $template = $this->loadTemplate($id); } else { Logging::info("Using default template"); @@ -472,6 +541,46 @@ class Application_Service_HistoryService return $template; } + public function getListItemTemplates() { + + $list = array(); + + try { + + $templates = CcPlayoutHistoryTemplateQuery::create() + ->setFormatter(ModelCriteria::FORMAT_ON_DEMAND) + ->findByDbType(self::TEMPLATE_TYPE_ITEM); + + foreach ($templates as $template) { + $list[$template->getDbId()] = $template->getDbName(); + } + + return $list; + } + catch (Exception $e) { + throw $e; + } + } + + public function getConfiguredItemTemplate() { + try { + $id = Application_Model_Preference::GetHistoryItemTemplate(); + return $this->getItemTemplate($id); + } + catch (Exception $e) { + throw $e; + } + } + + public function setConfiguredItemTemplate($id) { + try { + Application_Model_Preference::SetHistoryItemTemplate($id); + } + catch (Exception $e) { + throw $e; + } + } + public function createItemTemplate($config) { $this->con->beginTransaction(); @@ -480,15 +589,18 @@ class Application_Service_HistoryService $template = new CcPlayoutHistoryTemplate(); $template->setDbName($config["name"]); + $template->setDbType(self::TEMPLATE_TYPE_ITEM); $fields = $config["fields"]; foreach ($fields as $index=>$field) { + $isMd = ($field["filemd"] == 'true') ? true : false; + $templateField = new CcPlayoutHistoryTemplateField(); $templateField->setDbName($field["name"]); $templateField->setDbType($field["type"]); - $templateField->setDbIsFileMD($field["filemd"]); + $templateField->setDbIsFileMD($isMd); $templateField->setDbPosition($index); $template->addCcPlayoutHistoryTemplateField($templateField); @@ -496,13 +608,17 @@ class Application_Service_HistoryService $template->save($this->con); + $doSetDefault = $config['setDefault']; + if (isset($doSetDefault) && $doSetDefault) { + $this->setConfiguredItemTemplate($template->getDbid()); + } + $this->con->commit(); } - catch (Exception $e) { - $this->con->rollback(); - Logging::info($e); - throw $e; - } + catch (Exception $e) { + $this->con->rollback(); + throw $e; + } } } \ No newline at end of file diff --git a/airtime_mvc/application/views/scripts/playouthistory/configure-item-template.phtml b/airtime_mvc/application/views/scripts/playouthistory/configure-item-template.phtml index 8b6df15df..99654fbbd 100644 --- a/airtime_mvc/application/views/scripts/playouthistory/configure-item-template.phtml +++ b/airtime_mvc/application/views/scripts/playouthistory/configure-item-template.phtml @@ -1,40 +1,14 @@
\ No newline at end of file diff --git a/airtime_mvc/application/views/scripts/playouthistory/item-template.phtml b/airtime_mvc/application/views/scripts/playouthistory/item-template.phtml new file mode 100644 index 000000000..2aa247ae6 --- /dev/null +++ b/airtime_mvc/application/views/scripts/playouthistory/item-template.phtml @@ -0,0 +1,43 @@ +