From 4db6636b065b8388c6db158515f6e39e1244116d Mon Sep 17 00:00:00 2001 From: Yuchen Wang Date: Mon, 24 Oct 2011 12:05:55 -0400 Subject: [PATCH 1/2] CC-2646: Set a calendar view default (Day/week/month) that's remembered 1. If the preference is not user-specific, or if id is null, set subjid to null 2. Rewrote the code for the setValue logic, added comments. Should be easier to read and understand --- airtime_mvc/application/models/Preference.php | 46 ++++++++++--------- 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index 200b4448f..337ba052b 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -29,30 +29,32 @@ class Application_Model_Preference $result = $CC_DBC->GetOne($sql); - if ($result == 1 && is_null($id)){ - $sql = "UPDATE cc_pref" - ." SET subjid = NULL, valstr = '$value'" - ." WHERE keystr = '$key'"; - } - else if ($result == 1 && !is_null($id)){ - if($isUserValue) { - $sql = "UPDATE cc_pref" - ." SET valstr = '$value'" - ." WHERE keystr = '$key' AND subjid = $id"; - } else { - $sql = "UPDATE cc_pref" - ." SET subjid = $id, valstr = '$value'" + if($result == 1) { + // result found + if(is_null($id) || !$isUserValue) { + // system pref + $sql = "UPDATE cc_pref" + ." SET subjid = NULL, valstr = '$value'" ." WHERE keystr = '$key'"; - } - } - else if(is_null($id)) { - $sql = "INSERT INTO cc_pref (keystr, valstr)" - ." VALUES ('$key', '$value')"; - } - else { - $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" - ." VALUES ($id, '$key', '$value')"; + } else { + // user pref + $sql = "UPDATE cc_pref" + . " SET valstr = '$value'" + . " WHERE keystr = '$key' AND subjid = $id"; + } + } else { + // result not found + if(is_null($id) || !$isUserValue) { + // system pref + $sql = "INSERT INTO cc_pref (keystr, valstr)" + ." VALUES ('$key', '$value')"; + } else { + // user pref + $sql = "INSERT INTO cc_pref (subjid, keystr, valstr)" + ." VALUES ($id, '$key', '$value')"; + } } + return $CC_DBC->query($sql); } From a65fb97aecc63338e6056a0ccf1b3a13b4c56d8d Mon Sep 17 00:00:00 2001 From: Yuchen Wang Date: Mon, 24 Oct 2011 13:27:53 -0400 Subject: [PATCH 2/2] CC-2986: Long show description causes Add Show or Edit Show to fail silently Added StringLength validators for the UI fields. This way when user gave more than what they should gave as the input, it's going to display an error msg. The maximum length for the fields is queried from the database before the fields were initialized. --- airtime_mvc/application/forms/AddShowWhat.php | 18 +++++++++++------- airtime_mvc/application/models/Show.php | 15 +++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/airtime_mvc/application/forms/AddShowWhat.php b/airtime_mvc/application/forms/AddShowWhat.php index d3f241b25..d821b97a5 100644 --- a/airtime_mvc/application/forms/AddShowWhat.php +++ b/airtime_mvc/application/forms/AddShowWhat.php @@ -2,9 +2,12 @@ class Application_Form_AddShowWhat extends Zend_Form_SubForm { - public function init() { + // retrieves the length limit for each char field + // and store to assoc array + $maxLens = Application_Model_Show::GetMaxLengths(); + // Hidden element to indicate whether the show is new or // whether we are updating an existing show. $this->addElement('hidden', 'add_show_id', array( @@ -18,7 +21,8 @@ class Application_Form_AddShowWhat extends Zend_Form_SubForm 'required' => true, 'filters' => array('StringTrim'), 'validators' => array('NotEmpty'), - 'value' => 'Untitled Show' + 'value' => 'Untitled Show', + 'validators' => array(array('StringLength', false, array(0, $maxLens['name']))) )); // Add URL element @@ -27,7 +31,7 @@ class Application_Form_AddShowWhat extends Zend_Form_SubForm 'class' => 'input_text', 'required' => false, 'filters' => array('StringTrim'), - 'validators' => array('NotEmpty') + 'validators' => array('NotEmpty', array('StringLength', false, array(0, $maxLens['url']))) )); // Add genre element @@ -35,14 +39,16 @@ class Application_Form_AddShowWhat extends Zend_Form_SubForm 'label' => 'Genre:', 'class' => 'input_text', 'required' => false, - 'filters' => array('StringTrim') + 'filters' => array('StringTrim'), + 'validators' => array(array('StringLength', false, array(0, $maxLens['genre']))) )); // Add the description element $this->addElement('textarea', 'add_show_description', array( 'label' => 'Description:', 'required' => false, - 'class' => 'input_text_area' + 'class' => 'input_text_area', + 'validators' => array(array('StringLength', false, array(0, $maxLens['description']))) )); $descText = $this->getElement('add_show_description'); @@ -53,7 +59,5 @@ class Application_Form_AddShowWhat extends Zend_Form_SubForm )))); } - - } diff --git a/airtime_mvc/application/models/Show.php b/airtime_mvc/application/models/Show.php index 3c004b2d1..f842e1a2e 100644 --- a/airtime_mvc/application/models/Show.php +++ b/airtime_mvc/application/models/Show.php @@ -1338,4 +1338,19 @@ class Application_Model_Show { return $CC_DBC->GetAll($sql); } + + public static function GetMaxLengths() { + global $CC_CONFIG, $CC_DBC; + $sql = "SELECT column_name, character_maximum_length FROM information_schema.columns" + ." WHERE table_name = 'cc_show' AND character_maximum_length > 0"; + $result = $CC_DBC->GetAll($sql); + + // store result into assoc array + $assocArray = array(); + foreach($result as $row) { + $assocArray[$row['column_name']] = $row['character_maximum_length']; + } + + return $assocArray; + } }