diff --git a/airtime_mvc/application/controllers/PlaylistController.php b/airtime_mvc/application/controllers/PlaylistController.php
index 424f13883..3956ee50d 100644
--- a/airtime_mvc/application/controllers/PlaylistController.php
+++ b/airtime_mvc/application/controllers/PlaylistController.php
@@ -97,10 +97,8 @@ class PlaylistController extends Zend_Controller_Action
$form = new Application_Form_SmartBlockCriteria();
$form->removeDecorator('DtDdWrapper');
$form->startForm($obj->getId());
+
$this->view->form = $form;
- }
-
- if ($isBlock){
$this->view->obj = $obj;
$this->view->id = $obj->getId();
if ($isJson) {
@@ -532,8 +530,21 @@ class PlaylistController extends Zend_Controller_Action
$this->setPlaylistNameDescAction();
if ($params['type'] == 'block') {
- $bl = new Application_Model_Block($params['obj_id']);
- $result = $bl->saveSmartBlockCriteria($params['criteria']);
+ $form = new Application_Form_SmartBlockCriteria();
+ $form->startForm($params['obj_id']);
+ $bl = new Application_Model_Block($params['obj_id']);
+ if ($form->isValid($params)) {
+ $result = $bl->saveSmartBlockCriteria($params['data']);
+ $result['html'] = $this->createFullResponse($bl, true);
+ $result['result'] = 0;
+ } else {
+ $this->view->obj = $bl;
+ $this->view->id = $bl->getId();
+ $this->view->form = $form;
+ $viewPath = 'playlist/smart-block.phtml';
+ $result['html'] = $this->view->render($viewPath);
+ $result['result'] = 1;
+ }
}
$result["modified"] = $this->view->modified;
@@ -544,9 +555,11 @@ class PlaylistController extends Zend_Controller_Action
{
$request = $this->getRequest();
$params = $request->getPost();
+ $form = new Application_Form_SmartBlockCriteria();
+ $form->startForm($params['obj_id']);
$bl = new Application_Model_Block($params['obj_id']);
- $result = $bl->generateSmartBlock($params['data']);
- if ($result['result'] == 0) {
+ if ($form->isValid($params)) {
+ $result = $bl->generateSmartBlock($params['data']);
try {
die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($bl, true))));
}
@@ -557,6 +570,12 @@ class PlaylistController extends Zend_Controller_Action
$this->playlistUnknownError($e);
}
}else{
+ $this->view->obj = $bl;
+ $this->view->id = $bl->getId();
+ $this->view->form = $form;
+ $viewPath = 'playlist/smart-block.phtml';
+ $result['html'] = $this->view->render($viewPath);
+ $result['result'] = 1;
die(json_encode($result));
}
}
@@ -566,14 +585,8 @@ class PlaylistController extends Zend_Controller_Action
$request = $this->getRequest();
$params = $request->getPost();
$bl = new Application_Model_Block($params['obj_id']);
-
- //we need to save criteria in case user hasn't clicked Save or Generate yet
- $result = $bl->saveSmartBlockCriteria($params['data']);
-
- //only shuffle if there are no criteria errors
- if ($result['result'] == 0) {
- $result = $bl->shuffleSmartBlock();
- }
+ $result = $bl->shuffleSmartBlock();
+
if ($result['result'] == 0) {
try {
die(json_encode(array("result"=>0, "html"=>$this->createFullResponse($bl, true))));
diff --git a/airtime_mvc/application/forms/SmartBlockCriteria.php b/airtime_mvc/application/forms/SmartBlockCriteria.php
index 31e62f593..06835ed24 100644
--- a/airtime_mvc/application/forms/SmartBlockCriteria.php
+++ b/airtime_mvc/application/forms/SmartBlockCriteria.php
@@ -266,4 +266,153 @@ class Application_Form_SmartBlockCriteria extends Zend_Form_SubForm
));
}
+ function isValid($params){
+ Logging::log("isvalid called");
+ $isValid = true;
+ // reconstruct the params['criteria'] so we can populate the form
+ $formData = array();
+ foreach ($params['data'] as $ele) {
+ $formData[$ele['name']] = $ele['value'];
+ }
+ $this->populate($formData);
+ $criteria2PeerMap = array(
+ 0 => "Select criteria",
+ "album_title" => "DbAlbumTitle",
+ "artist_name" => "DbArtistName",
+ "bit_rate" => "DbBitRate",
+ "bpm" => "DbBpm",
+ "comments" => "DbComments",
+ "composer" => "DbComposer",
+ "conductor" => "DbConductor",
+ "utime" => "DbUtime",
+ "mtime" => "DbMtime",
+ "lptime" => "DbLPtime",
+ "disc_number" => "DbDiscNumber",
+ "genre" => "DbGenre",
+ "isrc_number" => "DbIsrcNumber",
+ "label" => "DbLabel",
+ "language" => "DbLanguage",
+ "length" => "DbLength",
+ "lyricist" => "DbLyricist",
+ "mood" => "DbMood",
+ "name" => "DbName",
+ "orchestra" => "DbOrchestra",
+ "rating" => "DbRating",
+ "sample_rate" => "DbSampleRate",
+ "track_title" => "DbTrackTitle",
+ "track_number" => "DbTrackNumber",
+ "year" => "DbYear"
+ );
+ $data = Application_Model_Block::organizeSmartPlyalistCriteria($params['data']);
+ // things we need to check
+ // 1. limit value shouldn't be empty and has upperbound of 24 hrs
+ // 2. sp_criteria or sp_criteria_modifier shouldn't be 0
+ // 3. validate formate according to DB column type
+ $multiplier = 1;
+ $result = 0;
+ $errors = array();
+ $error = array();
+
+ // validation start
+ if ($data['etc']['sp_limit_options'] == 'hours') {
+ $multiplier = 60;
+ }
+ if ($data['etc']['sp_limit_options'] == 'hours' || $data['etc']['sp_limit_options'] == 'mins') {
+ $element = $this->getElement("sp_limit_value");
+ if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
+ $element->addError("Limit cannot be empty or smaller than 0");
+ $isValid = false;
+ } else {
+ $mins = floatval($data['etc']['sp_limit_value']) * $multiplier;
+ if ($mins > 1440) {
+ $element->addError("Limit cannot be more than 24 hrs");
+ $isValid = false;
+ }
+ }
+ } else {
+ $element = $this->getElement("sp_limit_value");
+ if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
+ $element->addError("Limit cannot be empty or smaller than 0");
+ $isValid = false;
+ } else if (!ctype_digit($data['etc']['sp_limit_value'])) {
+ $element->addError("The value should be an integer");
+ $isValid = false;
+ } else if (intval($data['etc']['sp_limit_value']) > 500) {
+ $element->addError("500 is the max item limit value you can set");
+ $isValid = false;
+ }
+ }
+
+ $criteriaFieldsUsed = array();
+
+ if (isset($data['criteria'])) {
+ foreach ($data['criteria'] as $rowKey=>$row) {
+ foreach ($row as $key=>$d){
+ $element = $this->getElement("sp_criteria_field_".$rowKey."_".$key);
+ $error = array();
+ // check for not selected select box
+ if ($d['sp_criteria_field'] == "0" || $d['sp_criteria_modifier'] == "0"){
+ $element->addError("You must select Criteria and Modifier");
+ $isValid = false;
+ } else {
+ $column = CcFilesPeer::getTableMap()->getColumnByPhpName($criteria2PeerMap[$d['sp_criteria_field']]);
+ // validation on type of column
+ if ($d['sp_criteria_field'] == 'length') {
+ if (!preg_match("/(\d{2}):(\d{2}):(\d{2})/", $d['sp_criteria_value'])) {
+ $element->addError("'Length' should be in '00:00:00' format");
+ $isValid = false;
+ }
+ } else if ($column->getType() == PropelColumnTypes::TIMESTAMP) {
+ if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) {
+ $element->addError("The value should be in timestamp format(eg. 0000-00-00 or 00-00-00 00:00:00");
+ $isValid = false;
+ } else {
+ $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']);
+ if (!$result["success"]) {
+ // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
+ $element->addError($result["errMsg"]);
+ $isValid = false;
+ }
+ }
+
+ if (isset($d['sp_criteria_extra'])) {
+ if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) {
+ $element->addError("The value should be in timestamp format(eg. 0000-00-00 or 00-00-00 00:00:00");
+ $isValid = false;
+ } else {
+ $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_extra']);
+ if (!$result["success"]) {
+ // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
+ $element->addError($result["errMsg"]);
+ $isValid = false;
+ }
+ }
+ }
+ } else if ($column->getType() == PropelColumnTypes::INTEGER) {
+ if (!is_numeric($d['sp_criteria_value'])) {
+ $element->addError("The value has to be numeric");
+ $isValid = false;
+ }
+ // length check
+ if (intval($d['sp_criteria_value']) >= pow(2,31)) {
+ $element->addError("The value should be less then 2147483648");
+ $isValid = false;
+ }
+ } else if ($column->getType() == PropelColumnTypes::VARCHAR) {
+ if (strlen($d['sp_criteria_value']) > $column->getSize()) {
+ $element->addError("The value should be less ".$column->getSize()." characters");
+ $isValid = false;
+ }
+ }
+ }
+
+ if ($d['sp_criteria_value'] == "") {
+ $element->addError("Value cannot be empty");
+ $isValid = false;
+ }
+ }//end foreach
+ }//for loop
+ }//if
+ return $isValid;
+ }
}
diff --git a/airtime_mvc/application/models/Block.php b/airtime_mvc/application/models/Block.php
index 9fad96c25..617f53265 100644
--- a/airtime_mvc/application/models/Block.php
+++ b/airtime_mvc/application/models/Block.php
@@ -242,9 +242,9 @@ EOT;
return $fade;
}
- // function return "N/A" if dynamic
- public function getLength()
+ public function getUnformatedLength()
{
+ $this->block->reload();
if ($this->isStatic()){
$length = $this->block->getDbLength();
} else {
@@ -253,8 +253,9 @@ EOT;
return $length;
}
- public function getFormattedLength()
+ public function getLength()
{
+ $this->block->reload();
$prepend = "";
if ($this->isStatic()){
$length = $this->block->getDbLength();
@@ -808,7 +809,7 @@ EOT;
throw $e;
}
- return array("cliplength"=> $cliplength, "cueIn"=> $cueIn, "cueOut"=> $cueOut, "length"=> $this->getLength(),
+ return array("cliplength"=> $cliplength, "cueIn"=> $cueIn, "cueOut"=> $cueOut, "length"=> $this->getUnformatedLength(),
"fadeIn"=> $fadeIn, "fadeOut"=> $fadeOut);
}
@@ -935,136 +936,30 @@ EOT;
public function saveSmartBlockCriteria($p_criteria)
{
$data = $this->organizeSmartPlyalistCriteria($p_criteria);
-
- // things we need to check
- // 1. limit value shouldn't be empty and has upperbound of 24 hrs
- // 2. sp_criteria or sp_criteria_modifier shouldn't be 0
- // 3. validate formate according to DB column type
- $multiplier = 1;
- $result = 0;
- $errors = array();
- $error = array();
-
// saving dynamic/static flag
$blockType = $data['etc']['sp_type'] == 0 ? 'static':'dynamic';
$this->saveType($blockType);
-
- // validation start
- if ($data['etc']['sp_limit_options'] == 'hours') {
- $multiplier = 60;
- }
- if ($data['etc']['sp_limit_options'] == 'hours' || $data['etc']['sp_limit_options'] == 'mins') {
- if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
- $error[] = "Limit cannot be empty or smaller than 0";
+ $this->storeCriteriaIntoDb($data);
+ //get number of files that meet the criteria
+ $files = $this->getListofFilesMeetCriteria();
+ //$output['poolCount'] = $files["count"];
+ // if the block is dynamic, put null to the length
+ // as it cannot be calculated
+ if ($blockType == 'dynamic') {
+ if ($this->hasItemLimit()) {
+ $this->setLength(null);
} else {
- $mins = floatval($data['etc']['sp_limit_value']) * $multiplier;
- if ($mins > 1440) {
- $error[] = "Limit cannot be more than 24 hrs";
- }
+ $this->setLength($this->getDynamicBlockLength());
}
} else {
- if ($data['etc']['sp_limit_value'] == "" || floatval($data['etc']['sp_limit_value']) <= 0) {
- $error[] = "Limit cannot be empty or smaller than 0";
- } else if (!ctype_digit($data['etc']['sp_limit_value'])) {
- $error[] = "The value should be an integer";
- } else if (intval($data['etc']['sp_limit_value']) > 500) {
- $error[] = "500 is the max item limit value you can set";
+ $length = $this->getStaticLength();
+ if (!$length) {
+ $length = "00:00:00";
}
+ $this->setLength($length);
}
-
- if (count($error) > 0){
- $errors[] = array("element"=>"sp_limit_value", "msg"=>$error);
- }
-
- $criteriaFieldsUsed = array();
-
- if (isset($data['criteria'])) {
- $critKeys = array_keys($data['criteria']);
- for ($i = 0; $i < count($critKeys); $i++) {
- foreach ($data['criteria'][$critKeys[$i]] as $key=>$d){
- $error = array();
- // check for not selected select box
- if ($d['sp_criteria_field'] == "0" || $d['sp_criteria_modifier'] == "0"){
- $error[] = "You must select Criteria and Modifier";
- } else {
- $column = CcFilesPeer::getTableMap()->getColumnByPhpName(self::$criteria2PeerMap[$d['sp_criteria_field']]);
- // validation on type of column
- if ($d['sp_criteria_field'] == 'length') {
- if (!preg_match("/(\d{2}):(\d{2}):(\d{2})/", $d['sp_criteria_value'])) {
- $error[] = "'Length' should be in '00:00:00' format";
- }
- } else if ($column->getType() == PropelColumnTypes::TIMESTAMP) {
- if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_value'])) {
- $error[] = "The value should be in timestamp format(eg. 0000-00-00 or 00-00-00 00:00:00";
- } else {
- $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_value']);
- if (!$result["success"]) {
- // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
- $error[] = $result["errMsg"];
- }
- }
-
- if (isset($d['sp_criteria_extra'])) {
- if (!preg_match("/(\d{4})-(\d{2})-(\d{2})/", $d['sp_criteria_extra'])) {
- $error[] = "The value should be in timestamp format(eg. 0000-00-00 or 00-00-00 00:00:00";
- } else {
- $result = Application_Common_DateHelper::checkDateTimeRangeForSQL($d['sp_criteria_extra']);
- if (!$result["success"]) {
- // check for if it is in valid range( 1753-01-01 ~ 12/31/9999 )
- $error[] = $result["errMsg"];
- }
- }
- }
- } else if ($column->getType() == PropelColumnTypes::INTEGER) {
- if (!is_numeric($d['sp_criteria_value'])) {
- $error[] = "The value has to be numeric";
- }
- // length check
- if (intval($d['sp_criteria_value']) >= pow(2,31)) {
- $error[] = "The value should be less then 2147483648";
- }
- } else if ($column->getType() == PropelColumnTypes::VARCHAR) {
- if (strlen($d['sp_criteria_value']) > $column->getSize()) {
- $error[] = "The value should be less ".$column->getSize()." characters";
- }
- }
- }
-
- if ($d['sp_criteria_value'] == "") {
- $error[] = "Value cannot be empty";
- }
- if(count($error) > 0){
- $errors[] = array("element"=>"sp_criteria_field_".$critKeys[$i]."_".$key, "msg"=>$error);
- }
- }//end foreach
- }//for loop
- }//if
+ //$output['blockLength'] = $this->getFormattedLength();
- $result = count($errors) > 0 ? 1 :0;
- $files["count"] = 0;
- $output = array("result"=>$result, "errors"=>$errors);
- if ($result == 0) {
- $this->storeCriteriaIntoDb($data);
- //get number of files that meet the criteria
- $files = $this->getListofFilesMeetCriteria();
- $output['poolCount'] = $files["count"];
- // if the block is dynamic, put null to the length
- // as it cannot be calculated
- if ($blockType == 'dynamic') {
- if ($this->hasItemLimit()) {
- $this->setLength(null);
- } else {
- $this->setLength($this->getDynamicBlockLength());
- }
- } else {
- $length = $this->getStaticLength();
- if (!$length) {
- $length = "00:00:00";
- }
- $this->setLength($length);
- }
- $output['blockLength'] = $this->getFormattedLength();
- }
$this->updateBlockLengthInAllPlaylist();
return $output;
}
@@ -1082,7 +977,7 @@ EOT;
public function storeCriteriaIntoDb($p_criteriaData){
// delete criteria under $p_blockId
CcBlockcriteriaQuery::create()->findByDbBlockId($this->id)->delete();
-
+ Logging::log($p_criteriaData);
//insert modifier rows
if (isset($p_criteriaData['criteria'])) {
$critKeys = array_keys($p_criteriaData['criteria']);
@@ -1119,16 +1014,16 @@ EOT;
public function generateSmartBlock($p_criteria, $returnList=false)
{
$result = $this->saveSmartBlockCriteria($p_criteria);
- if ($result['result'] != 0) {
+ /*if ($result['result'] != 0) {
return $result;
- } else {
+ } else {*/
$insertList = $this->getListOfFilesUnderLimit();
$this->deleteAllFilesFromBlock();
$this->addAudioClips(array_keys($insertList));
// update length in playlist contents.
$this->updateBlockLengthInAllPlaylist();
return array("result"=>0);
- }
+ //}
}
public function updateBlockLengthInAllPlaylist()
@@ -1137,7 +1032,7 @@ EOT;
$blocks->getFirst();
$iterator = $blocks->getIterator();
while ($iterator->valid()) {
- $length = $this->getLength();
+ $length = $this->getUnformatedLength();
if (!preg_match("/^[0-9]{2}:[0-9]{2}:[0-9]{2}/", $length)) {
$iterator->current()->setDbClipLength(null);
} else {
@@ -1300,7 +1195,7 @@ EOT;
}
- private static function organizeSmartPlyalistCriteria($p_criteria)
+ public static function organizeSmartPlyalistCriteria($p_criteria)
{
$fieldNames = array('sp_criteria_field', 'sp_criteria_modifier', 'sp_criteria_value', 'sp_criteria_extra');
$output = array();
@@ -1313,7 +1208,7 @@ EOT;
*/
$fieldName = substr($ele['name'], 0, $index);
- // Get criteria row index.
+ // Get criteria row index.
$tempName = $ele['name'];
// Get the last digit in the field name
preg_match('/^\D*(?=\d)/', $tempName, $r);
diff --git a/airtime_mvc/application/models/Datatables.php b/airtime_mvc/application/models/Datatables.php
index a807757ad..01971a139 100644
--- a/airtime_mvc/application/models/Datatables.php
+++ b/airtime_mvc/application/models/Datatables.php
@@ -95,7 +95,7 @@ class Application_Model_Datatables
$r['length'] = $pl->getLength();
} else if ($r['ftype'] == "block") {
$bl = new Application_Model_Block($r['id']);
- $r['length'] = $bl->getFormattedLength();
+ $r['length'] = $bl->getLength();
}
}
} catch (Exception $e) {
diff --git a/airtime_mvc/application/models/Playlist.php b/airtime_mvc/application/models/Playlist.php
index 8e1660394..44ec4d5da 100644
--- a/airtime_mvc/application/models/Playlist.php
+++ b/airtime_mvc/application/models/Playlist.php
@@ -227,7 +227,7 @@ SQL;
//format the length for UI.
if ($row['type'] == 2) {
$bl = new Application_Model_Block($row['item_id']);
- $formatter = new LengthFormatter($bl->getFormattedLength());
+ $formatter = new LengthFormatter($bl->getLength());
} else {
$formatter = new LengthFormatter($row['length']);
}
diff --git a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml
index f3e19d758..38c2719d8 100644
--- a/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml
+++ b/airtime_mvc/application/views/scripts/form/smart-block-criteria.phtml
@@ -31,14 +31,21 @@
element->getElement("sp_criteria_field_".$i."_".$j) ?>
-
+
element->getElement("sp_criteria_modifier_".$i."_".$j) ?>
element->getElement("sp_criteria_value_".$i."_".$j) ?>
- element->getElement("sp_criteria_extra_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>> to element->getElement('sp_criteria_extra_'.$i."_".$j) ?>
+ element->getElement("sp_criteria_extra_".$i."_".$j)->getAttrib("disabled") == "disabled"?'style="display:none;"':""?>> to element->getElement('sp_criteria_extra_'.$i."_".$j) ?>
+ element->getElement("sp_criteria_field_".$i."_".$j)->hasErrors()) : ?>
+ element->getElement("sp_criteria_field_".$i."_".$j)->getMessages() as $error): ?>
+
+
+
+
+
@@ -61,20 +68,20 @@
files meet the criteria
- poolCount == 1) {
echo $this->poolCount;
?>
file meets the criteria
-
+ ?>
0 files meet the criteria
-
diff --git a/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml b/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml
index 82c74b2ec..15aeb1bc4 100644
--- a/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml
+++ b/airtime_mvc/application/views/scripts/library/get-file-metadata.ajax.phtml
@@ -27,7 +27,7 @@
Name:md["dc:title"]);?>
Creator:md["dc:creator"]);?>
type == "block" && $this->blType == "Dynamic") { ?>
- Length:block->getFormattedLength();?>
+ Length:block->getLength();?>
Length:md["dcterms:extent"]);?>
@@ -67,7 +67,7 @@