diff options
Diffstat (limited to 'h-source/Library/Model/Base.php')
-rwxr-xr-x | h-source/Library/Model/Base.php | 99 |
1 files changed, 63 insertions, 36 deletions
diff --git a/h-source/Library/Model/Base.php b/h-source/Library/Model/Base.php index 4162a56..cdd1843 100755 --- a/h-source/Library/Model/Base.php +++ b/h-source/Library/Model/Base.php @@ -99,6 +99,8 @@ abstract class Model_Base protected $_popupWhere = array(); //where clause for the pupup menu + protected $_popupOrderBy = array(); //order by clause for the pupup menu + protected $_resultString; //reference to the class containing all the result strings of the db queries protected $_dbCondString; //reference to the class containing all the result strings of the database conditions @@ -130,15 +132,15 @@ abstract class Model_Base $this->_where[$this->_idFieldsArray[0]] = $this->_tablesArray[0]; $this->arrayExt = new ArrayExt(); + //set the language of notices + $this->_lang = Params::$language; + //initialize the validate objects $this->_arrayStrongCheck = new Array_Validate_Strong($this->_lang); $this->_arraySoftCheck = new Array_Validate_Soft($this->_lang); $this->identifierName = $this->_idFieldsArray[0]; - //set the language of notices - $this->_lang = Params::$language; - //create the $_resultString object (result strings of the db queries) $modelStringClass = 'Lang_'.$this->_lang.'_ModelStrings'; if (!class_exists($modelStringClass)) @@ -277,11 +279,11 @@ abstract class Model_Base { foreach (params::$whereClauseSymbolArray as $symbol) { - if (strstr($value,$symbol)) + if (stristr($value,$symbol)) { //check if write or not the table name $tableName = strstr($field,'n!') ? null : $this->getTableName($field).'.'; - $whereClauseArray[] = $tableName.$fieldClean.' '.$value; + $whereClauseArray[] = strstr($field,'n!n!') ? $value : $tableName.$fieldClean.' '.$value; $flag = 1; //not equal where clause break; } @@ -291,7 +293,7 @@ abstract class Model_Base $value = '"'.$value.'"'; //check if write or not the table name $tableName = strstr($field,'n!') ? null : $this->getTableName($field).'.'; - $whereClauseArray[] = $tableName.$fieldClean.'='.$value; + $whereClauseArray[] = strstr($field,'n!n!') ? $value : $tableName.$fieldClean.'='.$value; } } } @@ -737,18 +739,6 @@ abstract class Model_Base //delete all the '+' chars $key = $this->dropStartChar($key,'+'); - if (strcmp($values,'all') === 0 or strstr($values,'all|')) - { - if (strstr($values,'all|')) - { - $values = str_replace('all|',$this->fields.'|',$values); - } - else - { - $values = $this->fields; - } - } - if (strstr($values,'|')) { $temp = explode('|',$values); @@ -775,6 +765,49 @@ abstract class Model_Base } } + //add a condition + //$condArray: it can be $this->strongConditions, $this->softConditions or $this->databaseConditions + //$queryType: insert, update + //$condition: the condition + //$field: comma separated list of fields + private function addCondition(&$condArray,$queryType,$condition,$field) + { + if (isset($condArray[$queryType]) and array_key_exists($condition,$condArray[$queryType])) + { + $condition = "+".$condition; + $this->addCondition($condArray,$queryType,$condition,$field); + } + else + { + $condArray[$queryType][$condition] = $field; + } + } + + //choose if to apply insert, update or both conditions + private function addChooseCondition(&$condArray,$queryType,$condition,$field) + { + if ($queryType === "both") + { + $this->addCondition($condArray,"insert",$condition,$field); + $this->addCondition($condArray,"update",$condition,$field); + } + else + { + $this->addCondition($condArray,$queryType,$condition,$field); + } + } + + //add a condition to the strongCondition array + public function addStrongCondition($queryType,$condition,$field) + { + $this->addChooseCondition($this->strongConditions,$queryType,$condition,$field); + } + + //add a condition to the strongCondition array + public function addSoftCondition($queryType,$condition,$field) + { + $this->addChooseCondition($this->softConditions,$queryType,$condition,$field); + } //method to apply the validate conditions listed in the $this->strongConditions associative array //$queryType: indicates what set of validate conditions has to be considered (it's the key of the associative array) @@ -793,11 +826,11 @@ abstract class Model_Base $conditions = $this->softConditions; $errString = 'softConditions'; - if (Params::$nullQueryValue !== false) - { - $conditions['insert']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; - $conditions['update']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; - } +// if (Params::$nullQueryValue !== false) +// { +// $conditions['insert']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; +// $conditions['update']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; +// } } if (array_key_exists($queryType,$conditions)) @@ -815,18 +848,6 @@ abstract class Model_Base //delete all the '+' chars $key = $this->dropStartChar($key,'+'); - - if (strcmp($values,'all') === 0 or strstr($values,'all|')) - { - if (strstr($values,'all|')) - { - $values = str_replace('all|',$this->fields.'|',$values); - } - else - { - $values = $this->fields; - } - } if (strstr($values,'|')) { @@ -908,6 +929,10 @@ abstract class Model_Base $this->submitName = $submitName; if (method_exists($this,$methodName)) { + if (strcmp($methodName,"insert") === 0) + { + $this->identifierValue = null; + } //if the method is allowed if (in_array($methodName,$allowedMethodsArray)) { @@ -947,7 +972,9 @@ abstract class Model_Base $popupWhereClause = array_key_exists($field,$this->_popupWhere) ? $this->_popupWhere[$field] : null; - $result = $this->db->select($table,$queryFields,$popupWhereClause,$fieldClean); + $popupOrderBy = array_key_exists($field,$this->_popupOrderBy) ? $this->_popupOrderBy[$field] : null; + + $result = $this->db->select($table,$queryFields,$popupWhereClause,$fieldClean,$popupOrderBy); if ($result and $result !== false) { |