can add a new list item using the template.

set a default item template

working on sql to get a table with unified columns for file md and manually entered metadata without a file.
This commit is contained in:
Naomi 2013-07-30 19:24:05 -04:00
parent 06e21029d0
commit 7ca3048f36
13 changed files with 456 additions and 163 deletions

View file

@ -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,6 +129,7 @@ class PlayouthistoryController extends Zend_Controller_Action
public function createListItemAction()
{
try {
$request = $this->getRequest();
$params = $request->getPost();
Logging::info($params);
@ -137,6 +137,11 @@ class PlayouthistoryController extends Zend_Controller_Action
$historyService = new Application_Service_HistoryService();
$historyService->createPlayedItem($params);
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
}
public function editListItemAction()
{
@ -190,6 +195,11 @@ class PlayouthistoryController extends Zend_Controller_Action
public function configureItemTemplateAction() {
$request = $this->getRequest();
$params = $request->getPost();
Logging::info($params);
try {
$CC_CONFIG = Config::getConfig();
$baseUrl = Application_Common_OsPath::getBaseDir();
@ -198,12 +208,21 @@ class PlayouthistoryController extends Zend_Controller_Action
$template_id = $this->_getParam('id', null);
$historyService = new Application_Service_HistoryService();
$mandatoryFields = $historyService->mandatoryItemTemplate();
$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 = $mandatoryFields;
$this->view->required_fields = $mandatoryFields;
}
catch (Exception $e) {
Logging::info($e);
Logging::info($e->getMessage());
}
}
public function createTemplateAction()
@ -212,9 +231,37 @@ class PlayouthistoryController extends Zend_Controller_Action
$params = $request->getPost();
Logging::info($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()
{
}
}

View file

@ -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]];

View file

@ -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()

View file

@ -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();

View file

@ -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');
}
}

View file

@ -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);
}
/**

View file

@ -7,6 +7,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",
"title" => "track_title",
@ -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++) {
for ($i = 0, $len = count($fields); $i < $len; $i++) {
$item = $template[$i];
$key = $item["name"];
$isFileMd = $item["isFileMd"];
$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());
//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 getItemTemplate() {
private function loadTemplate($id) {
$template_id = Application_Model_Preference::GetHistoryItemTemplate();
try {
$template = CcPlayoutHistoryTemplateQuery::create()->findPk($id, $this->con);
if (is_numeric($template_id)) {
Logging::info("template id is: $template_id");
$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;
}
}
public function getItemTemplate($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,11 +608,15 @@ 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;
}
}

View file

@ -1,40 +1,14 @@
<div id="configure_item_template" class="ui-widget ui-widget-content block-shadow alpha-block padded">
<button id="template_item_save" data-template="<?php echo $this->template_id; ?>">Save</button>
<div><label>Name<input id="template_name" type="text"></label></div>
<?php $i = 0; ?>
<ul class="template_item_list">
<?php foreach ($this->required as $field): ?>
<li id="<?php echo "field_".$i?>" data-name="<?php echo $field["name"]?>" data-type="<?php echo $field["type"]?>" data-filemd="<?php echo var_export($field["isFileMd"], true)?>">
<span><?php echo $field["name"]?></span>
<span><?php echo $field["type"]?></span>
</li>
<?php $i++; ?>
<?php endforeach; ?>
</ul>
<ul class="template_file_md">
<?php foreach ($this->fileMD as $md): ?>
<li id="<?php echo "md_".$md["name"]?>" data-name="<?php echo $md["name"]?>" data-type="<?php echo $md["type"]?>"><?php echo $md["name"] ?></li>
<?php endforeach; ?>
</ul>
<div class="template_item_add">
<div>Add New Field</div>
<div>
<input type="text">
<select>
<?php foreach ($this->fields as $field): ?>
<option value="<?php echo $field; ?>"><?php echo $field; ?></option>
<select id="template_list">
<option value="">New</option>
<?php foreach ($this->template_list as $id=>$name): ?>
<option value="<?php echo $id; ?>"><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
<button>Add</button>
</div>
</div>
<?php echo $this->render('playouthistory/item-template.phtml'); ?>
</div>

View file

@ -0,0 +1,43 @@
<div>
<button id="template_set_default" data-template="<?php echo $this->template_id; ?>">Set Default Template</button>
<button id="template_item_save" data-template="<?php echo $this->template_id; ?>">Save</button>
</div>
<div><label>Name<input id="template_name" type="text" value="<?php echo $this->template_name; ?>"></label></div>
<?php $i = 0; ?>
<ul class="template_item_list">
<?php foreach ($this->template_fields as $field): ?>
<li id="<?php echo "field_".$i?>" data-id="<?php echo isset($field["id"]) ? $field["id"] : ""; ?>" data-name="<?php echo $field["name"]?>" data-type="<?php echo $field["type"]?>" data-filemd="<?php echo var_export($field["isFileMd"], true)?>">
<span><?php echo $field["name"]?></span>
<span><?php echo $field["type"]?></span>
<?php if(!in_array($field["name"], $this->required_fields)): ?>
<span class="template_item_remove">Remove</span>
<?php endif; ?>
</li>
<?php $i++; ?>
<?php endforeach; ?>
</ul>
<ul class="template_file_md">
<?php foreach ($this->fileMD as $md): ?>
<li id="<?php echo "md_".$md["name"]?>" data-name="<?php echo $md["name"]?>" data-type="<?php echo $md["type"]?>"><?php echo $md["name"] ?></li>
<?php endforeach; ?>
</ul>
<div class="template_item_add">
<div>Add New Field</div>
<div>
<input type="text">
<select>
<?php foreach ($this->fields as $field): ?>
<option value="<?php echo $field; ?>"><?php echo $field; ?></option>
<?php endforeach; ?>
</select>
<button>Add</button>
</div>
</div>

View file

@ -1,4 +1,3 @@
<div id="history_template" class="ui-widget ui-widget-content block-shadow alpha-block padded">
<a href="<?php echo $this->baseUrl("Playouthistory/configure-item-template"); ?>">Configure Item Template</a>
</div>

View file

@ -499,7 +499,8 @@
</table>
<table name="cc_playout_history_template" phpName="CcPlayoutHistoryTemplate">
<column name="id" phpName="DbId" primaryKey="true" type="INTEGER" autoIncrement="true" required="true" />
<column name="template_name" phpName="DbName" type="VARCHAR" size="128" required="true" />
<column name="name" phpName="DbName" type="VARCHAR" size="128" required="true" />
<column name="type" phpName="DbType" type="VARCHAR" size="35" required="true" />
</table>
<table name="cc_playout_history_template_field" phpName="CcPlayoutHistoryTemplateField">
<column name="id" phpName="DbId" primaryKey="true" type="INTEGER" autoIncrement="true" required="true" />

View file

@ -803,7 +803,8 @@ DROP TABLE "cc_playout_history_template" CASCADE;
CREATE TABLE "cc_playout_history_template"
(
"id" serial NOT NULL,
"template_name" VARCHAR(128) NOT NULL,
"name" VARCHAR(128) NOT NULL,
"type" VARCHAR(35) NOT NULL,
PRIMARY KEY ("id")
);

View file

@ -1,5 +1,6 @@
var AIRTIME = (function(AIRTIME) {
var mod;
var $templateDiv;
var $templateList;
var $fileMDList;
@ -44,6 +45,7 @@ var AIRTIME = (function(AIRTIME) {
name: $el.data("name"),
type: $el.data("type"),
filemd: $el.data("filemd"),
id: $el.data("id")
};
}
@ -77,12 +79,12 @@ var AIRTIME = (function(AIRTIME) {
mod.onReady = function() {
$templateDiv = $("#configure_item_template");
$templateList = $(".template_item_list");
$fileMDList = $(".template_file_md");
$fileMDList.find("li").draggable({
//helper: "clone",
helper: function(event, ui) {
var $li = $(this);
var name = $li.data("name");
@ -96,11 +98,11 @@ var AIRTIME = (function(AIRTIME) {
$templateList.sortable(fieldSortable);
$templateList.on("click", ".template_item_remove", function() {
$templateDiv.on("click", ".template_item_remove", function() {
$(this).parents("li").remove();
});
$(".template_item_add").on("click", "button", function() {
$templateDiv.on("click", ".template_item_add button", function() {
var $div = $(this).parents("div.template_item_add");
var name = $div.find("input").val();
@ -109,8 +111,7 @@ var AIRTIME = (function(AIRTIME) {
addField(name, type, false, false);
});
$("#template_item_save").click(function(){
var template_id = $(this).data("template");
function createUpdateTemplate(template_id, isDefault) {
var createUrl = baseUrl+"Playouthistory/create-template/format/json";
var updateUrl = baseUrl+"Playouthistory/update-template/format/json";
var url;
@ -130,9 +131,46 @@ var AIRTIME = (function(AIRTIME) {
data[i] = getFieldData($li);
}
$.post(url, {name: templateName, fields: data}, function(json) {
$.post(url, {'name': templateName, 'fields': data, 'setDefault': isDefault}, function(json) {
var x;
});
}
$templateDiv.on("click", "#template_item_save", function(){
var template_id = $(this).data("template");
createUpdateTemplate(template_id, false);
});
$templateDiv.on("click", "#template_set_default", function(){
var template_id = $(this).data("template");
if (isNaN(parseInt(template_id, 10))) {
createUpdateTemplate(template_id, true);
}
else {
var url = baseUrl+"Playouthistory/set-item-template-default/format/json";
$.post(url, {id: template_id}, function(json) {
var x;
});
}
});
$("#template_list").change(function(){
var template_id = $(this).find(":selected").val(),
url;
if (!isNaN(parseInt(template_id, 10))) {
url = baseUrl+"Playouthistory/configure-item-template/id/"+template_id;
}
else {
url = baseUrl+"Playouthistory/configure-item-template";
}
window.location.href = url;
});
};