diff options
Diffstat (limited to 'h-source/Library/Model/Base.php')
| -rwxr-xr-x | h-source/Library/Model/Base.php | 607 | 
1 files changed, 85 insertions, 522 deletions
diff --git a/h-source/Library/Model/Base.php b/h-source/Library/Model/Base.php index 67bd91c..4162a56 100755 --- a/h-source/Library/Model/Base.php +++ b/h-source/Library/Model/Base.php @@ -2,7 +2,7 @@  // EasyGiant is a PHP framework for creating and managing dynamic content  // -// Copyright (C) 2009 - 2014  Antonio Gallo (info@laboratoriolibero.com) +// Copyright (C) 2009 - 2011  Antonio Gallo  // See COPYRIGHT.txt and LICENSE.txt.  //  // This file is part of EasyGiant @@ -25,12 +25,10 @@ if (!defined('EG')) die('Direct access not allowed!');  abstract class Model_Base  { -	public $foreignKeys = array(); //list of foreign keys -	  	public $fields = ''; //the fields that have to be manipulated by the update and insert query  	public $values = array(); //the values that corresponding to the $this->fields fields  	public $form = null; //reference to a Form_Form object -	public $formStruct = array("entries" => array()); //the form structure +	public $formStruct = null; //the form structure  	public $submitName = null; //the current submitName (from the form)  	public $identifierName = 'identifier'; @@ -39,18 +37,15 @@ abstract class Model_Base  	public $result = true; //the result of validate conditions, database conditions and query. It can be 'true' or 'false'  	public $queryResult = false; //the result of the query -	//conditions that the $_POST array has to satisfy (strong) +	//conditions that have to be satisfied before applying the query +	//Ex: 'update'=>'checkEmpty:titolo,autore','submitName'=>'conditions'  	public $strongConditions = array(); -	//conditions that the $_POST array has to satisfy (soft) +	//conditions that have to be satisfied before applying the query +	//Ex: 'update'=>'checkEmpty:titolo,autore','submitName'=>'conditions' +	//do not return error if a value is equal to '' or null  	public $softConditions = array(); -	//conditions that $this->values has to satisfy (strong) -	public $valuesConditions = array(); -	 -	//array where the conditions are temporary saved when the saveConditions is called -	public $backupConditions = array(); -	  	//conditions that have to be satisfied before applying the query  	//check that the new values inserted satisfy some conditions  	//Ex: 'update'=>'checkUniqueCompl:titolo,autore;checkUnique:titolo','insert'=>'checkUnique:titolo' @@ -62,17 +57,13 @@ abstract class Model_Base  	public $supplUpdateValues = array(); //associative array defining supplementary values to be inserted on each update query. It has to have the following form: array(field1 => value1,field2 => value2, ...) -	public $backupSelect = array(); //where the status of the where clause is stored when the save() method is called  	public $select = null; //fields that have to be selected in select queries -	public $sWhere = null; //string: free where clause  	public $where = array(); //associative array containing all the where clauses ($field => $value)  	//group by, order by and limit clauses  	public $groupBy = null;  	public $orderBy = null;  	public $limit = null; -	public $convert = false; //It can be tru or false. If true the extracted values are converted from MySQL format to $_lang format -	  	public $from = null; //from clause of the select queries  	public $on = array(); //on array  	public $using = array(); //using array @@ -108,14 +99,9 @@ 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  -	protected $_conversionToDbObject = null; //reference to the class to convert the values from current lang formats to MySQL formats -	protected $_conversionFromDbObject = null; //reference to the class to convert the values from MySQL formats to current lang formats -	  	protected $_backupFields = ''; //field saved after the delFields method has been applied   	protected $_backupValues = array(); //values saved after the delFields method has been applied   	protected $_allowedDbMethods = array('update','insert','del','moveup','movedown'); //methods that can be called by the updateTable method @@ -133,7 +119,6 @@ abstract class Model_Base  	protected $_arrayStrongCheck; //Array_Validate_Strong object  	protected $_arraySoftCheck; //Array_Validate_Soft object -	protected $_arrayValuesCheck; //Array_Validate_Values object  	public $db; //reference to the database layer class  	protected $_lang = null; //language of notices @@ -145,16 +130,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->_arrayValuesCheck = new Array_Validate_Values($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)) @@ -171,24 +155,6 @@ abstract class Model_Base  		}  		$this->_dbCondString = new $dbCondStringClass(); -		//create the references of the classes to convert to e from MySQL formats -		if (DATABASE_TYPE === "Mysqli" or DATABASE_TYPE === "Mysql") -		{ -			$_conversionToDbObject = 'Lang_'.$this->_lang.'_Formats_To_Mysql'; -			if (!class_exists($_conversionToDbObject)) -			{ -				$_conversionToDbObject = 'Lang_En_Formats_To_Mysql'; -			} -			$this->_conversionToDbObject = new $_conversionToDbObject(); -			 -			$_conversionFromDbObject = 'Lang_'.$this->_lang.'_Formats_From_Mysql'; -			if (!class_exists($_conversionFromDbObject)) -			{ -				$_conversionFromDbObject = 'Lang_En_Formats_From_Mysql'; -			} -			$this->_conversionFromDbObject = new $_conversionFromDbObject(); -		} -		  		//instantiate the database class  		$this->db = Factory_Db::getInstance(DATABASE_TYPE); @@ -205,22 +171,12 @@ abstract class Model_Base  	}  	//sanitize all the $values property -	public function sanitize($function = "sanitizeDb") +	public function sanitize()  	{ -		if (!function_exists($function)) { -			throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$function.'</b> does not exists.'); -		} -		  		$keys = implode(',',array_keys($this->values)); -		$this->values = $this->arrayExt->subset($this->values,$keys,$function); +		$this->values = $this->arrayExt->subset($this->values,$keys,'sanitizeDb');  	} -	//return the name of the primary key -	public function getPrimaryKey() -	{ -		return $this->_idFields; -	} -	  	//change a resulting string from a db query  	public function setString($key,$value)  	{ @@ -321,11 +277,11 @@ abstract class Model_Base  					{  						foreach (params::$whereClauseSymbolArray as $symbol)  						{ -							if (stristr($value,$symbol)) +							if (strstr($value,$symbol))  							{  								//check if write or not the table name  								$tableName = strstr($field,'n!') ? null : $this->getTableName($field).'.'; -								$whereClauseArray[] = strstr($field,'n!n!') ? $value : $tableName.$fieldClean.' '.$value; +								$whereClauseArray[] = $tableName.$fieldClean.' '.$value;  								$flag = 1; //not equal where clause  								break;  							} @@ -335,7 +291,7 @@ abstract class Model_Base  							$value = '"'.$value.'"';  							//check if write or not the table name  							$tableName = strstr($field,'n!') ? null : $this->getTableName($field).'.'; -							$whereClauseArray[] = strstr($field,'n!n!') ? $value : $tableName.$fieldClean.'='.$value; +							$whereClauseArray[] = $tableName.$fieldClean.'='.$value;  						}					  					}  				} @@ -368,129 +324,7 @@ abstract class Model_Base  	} -	//converts values from MySQl to $_lang format when filling the form with values coming from the DB -	public function convertFromMysql($values) -	{ -		if (Params::$automaticConversionFromDbFormat) -		{ -			if (isset($this->_conversionFromDbObject)) -			{ -				//get all types as associative array -				$types = $this->db->getTypes($this->_tables, "*", false, true); -				 -				if ($types) -				{ -					$values = $this->convertFromMysqlT($types, $values, $this->db->getEnumTypes()); -				} -			} -		} -		 -		return $values; -	} -	 -	//convert an array associaive from MySQL format to $_lang format -	//$values: array associative to convert -	//$types: types of the elements of the associative array -	//$excludeTypes: array of type whose conversion has to be avoided -	public function convertFromMysqlT($types, $values, $excludeTypes = array()) -	{ -		foreach ($values as $field => $value) -		{ -			if (array_key_exists($field, $types)) -			{ -				if (!in_array(strtolower($types[$field]),$excludeTypes)) -				{ -					if (method_exists($this->_conversionFromDbObject,strtolower($types[$field]))) -					{ -						$values[$field] = call_user_func(array($this->_conversionFromDbObject, strtolower($types[$field])), $values[$field]); -					} -				} -			} -		} -		return $values; -	} -	 -	//set the default values taking it from DB or from type definition -	public function setDefaultFormValues($fields) -	{ -		$returnDefaultValues = array(); -		 -		if (Params::$automaticallySetFormDefaultValues) -		{ -			if (isset($this->_conversionFromDbObject)) -			{ -				//get all types as associative array -				$types = $this->db->getTypes($this->_tables, "*", true, true); -				 -				//get all default values as associative array -				$defaultValues = $this->db->getDefaultValues($this->_tables, "*", false, true); -				 -				$fieldsArray = explode(",",$fields); -				 -				foreach ($fieldsArray as $field) -				{ -					if (array_key_exists($field,$defaultValues)) -					{ -						if (preg_match('/^('.implode("|",$this->db->getCharTypes()).')/i',$types[$field],$matches) or preg_match('/^('.implode("|",$this->db->getTextTypes()).')/i',$types[$field],$matches)) -						{ -							if (strcmp($defaultValues[$field],"") !== 0) -							{ -								$returnDefaultValues[$field] = $defaultValues[$field]; -							} -						} -						else if (preg_match('/^('.implode("|",$this->db->getIntegerTypes()).')/i',$types[$field],$matches) or preg_match('/^('.implode("|",$this->db->getFloatTypes()).')$/i',$types[$field],$matches) or preg_match('/^('.implode("|",$this->db->getDecimalTypes()).')/i',$types[$field],$matches)) -						{ -							if (strcmp($defaultValues[$field],"") !== 0) -							{ -								$returnDefaultValues[$field] = method_exists($this->_conversionFromDbObject,strtolower($matches[1])) ? call_user_func(array($this->_conversionFromDbObject, strtolower($matches[1])), $defaultValues[$field]) : $defaultValues[$field]; -							} -							else -							{ -								$returnDefaultValues[$field] = 0; -							} -						} -						else if (preg_match('/^('.implode("|",$this->db->getDateTypes()).')$/i',$types[$field],$matches)) -						{ -							$defDate = Params::$useCurrentDateAsDefaultDate ? date("Y-m-d") : ""; -							if (strcmp($defaultValues[$field],"") !== 0) -							{ -								$defDate = $defaultValues[$field]; -							} -							 -							if (method_exists($this->_conversionFromDbObject,strtolower($types[$field]))) -							{ -								$returnDefaultValues[$field] = call_user_func(array($this->_conversionFromDbObject, strtolower($types[$field])), $defDate); -							} -							else -							{ -								$returnDefaultValues[$field] = $defDate; -							} -						} -						else if (preg_match('/^('.implode("|",$this->db->getEnumTypes()).')\((.*?)\)$/i',$types[$field],$matches)) -						{ -							if (strcmp($defaultValues[$field],"") !== 0) -							{ -								$returnDefaultValues[$field] = $defaultValues[$field]; -							} -							else -							{ -								$temp = array(); -								$strings = explode(",",$matches[2]); -								for ($i=0;$i<count($strings);$i++) -								{ -									$returnDefaultValues[$field] = trim($strings[$i],"'\""); -									break; -								} -							} -						} -					} -				} -			} -		} -		 -		return $returnDefaultValues; -	} -	 +  	//return the values, taken from the $_POST array, to be inserted inside the forms  	//$queryType: insert or update  	//$func: sanitize function to apply upon each value @@ -533,12 +367,15 @@ abstract class Model_Base  					{  						$recordArray = $this->selectId($ident); -						$recordArray = $this->convertFromMysql($recordArray); -						  						$fieldsArray = explode(',',$this->fields); -						 +  						$values = $this->arrayExt->subset($recordArray,$this->fields,$funcDb); +// 						foreach ($fieldsArray as $field) +// 						{ +// 							$values[$field] = array_key_exists($field,$recordArray) ? $recordArray[$field] : ''; +// 						} +						  						$values[$idName] = $ident;  						//apply the functions upon entries @@ -569,16 +406,8 @@ abstract class Model_Base  				}  				else if ($queryType === 'insert')  				{ -					//set the default values taking it from DB or from type definition -					$tempArray = $this->setDefaultFormValues($this->fields); -					if (is_array($defaultValues)) -					{ -						foreach ($defaultValues as $field => $value) -						{ -							$tempArray[$field] = $value; -						} -					} +					$tempArray = is_array($defaultValues) ? $defaultValues : array();  					$values = $this->arrayExt->subset($tempArray,$this->fields,$funcPost); @@ -697,8 +526,6 @@ abstract class Model_Base  	//if $whereClause is set then use $whereClause as where clause of the update query  	public function update($id = null, $whereClause = null)  	{ -		$this->notice = null; -		  		if (!is_array($this->supplUpdateValues))  		{  			throw new Exception('error in <b>' . __METHOD__ . '</b>: the <b>supplUpdateValues</b> property has to be an array.'); @@ -706,70 +533,50 @@ abstract class Model_Base  		$el = $this->setSupplValues('update');  		$this->queryResult = false; -		if (count($this->values) > 0) +		if (isset($whereClause)) +		{ +			$result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$whereClause); +			$this->setNotice($result); +			return $result; +		} +		else  		{ -			if (isset($whereClause)) +			if (isset($id))  			{ -				$result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$whereClause); +				$where = $this->_idFieldsArray[0].'='.(int)($id); +				$result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$where);  				$this->setNotice($result);  				return $result;  			}  			else  			{ -				if (isset($id)) -				{ -					$where = $this->_idFieldsArray[0].'='.(int)($id); -					$result = $this->db->update($this->_tablesArray[0],$el[0],$el[1],$where); -					$this->setNotice($result); -					return $result; -				} -				else -				{ -					$this->notice .= $this->_resultString->getString('no-id'); -					$this->result = false; -					$this->identifierValue = null; -					return false; -				} +				$this->notice = $this->_resultString->getString('no-id'); +				$this->result = false; +				$this->identifierValue = null; +				return false;  			}  		} -		else -		{ -			$this->notice .= $this->_resultString->getString('no-fields'); -			$this->result = true; -			$this->queryResult = true; -			return false; -		}  	}  	//method to call the insert query (overriding of the base_db del method)  	public function insert() { -		$this->notice = null; +		  		$this->queryResult = false;  		if (!is_array($this->supplInsertValues)) {  			throw new Exception('error in <b>' . __METHOD__ . '</b>: the <b>supplInsertValues</b> property has to be an array.');  		} -		if (count($this->values) > 0) +		if (isset($this->_idOrder))  		{ -			if (isset($this->_idOrder)) -			{ -				$maxValue = $this->db->getMax($this->_tablesArray[0],$this->_idOrder); -				$this->supplInsertValues[$this->_idOrder] = (int)$maxValue + 1; -			} -			 -			$el = $this->setSupplValues('insert'); - -			$result = $this->db->insert($this->_tablesArray[0],$el[0],$el[1]); -			$this->setNotice($result); -			return $result; -		} -		else -		{ -			$this->notice .= $this->_resultString->getString('no-fields'); -			$this->result = true; -			$this->queryResult = true; -			return false; +			$maxValue = $this->db->getMax($this->_tablesArray[0],$this->_idOrder); +			$this->supplInsertValues[$this->_idOrder] = (int)$maxValue + 1;  		} +		 +		$el = $this->setSupplValues('insert'); + +		$result = $this->db->insert($this->_tablesArray[0],$el[0],$el[1]); +		$this->setNotice($result); +		return $result;  	}  	//method to call the delete query (overriding of the base_db del method) @@ -791,7 +598,7 @@ abstract class Model_Base  				$this->setNotice($result);  				return $result;  			} else { -				$this->notice .= $this->_resultString->getString('no-id'); +				$this->notice = $this->_resultString->getString('no-id');  				$this->result = false;  				$this->identifierValue = null;  				return false; @@ -818,8 +625,6 @@ abstract class Model_Base  	//where clause  	public function move($id,$par = 'up')  	{ -		$this->notice = null; -		  		$this->queryResult = false;  		if (isset($id))  		{ @@ -855,7 +660,7 @@ abstract class Model_Base  		}  		else  		{ -			$this->notice .= $this->_resultString->getString('no-id'); +			$this->notice = $this->_resultString->getString('no-id');  			$this->result = false;  			$this->identifierValue = null;  			return false; @@ -865,11 +670,11 @@ abstract class Model_Base  	public function setNotice($result) {  		if ($result) { -			$this->notice .= $this->_resultString->getString('executed'); +			$this->notice = $this->_resultString->getString('executed');  			$this->result = true;  			$this->queryResult = true;  		} else { -			$this->notice .= $this->_resultString->getString('error'); +			$this->notice = $this->_resultString->getString('error');  			$this->result = false;  			$this->queryResult = false;  		} @@ -932,6 +737,18 @@ 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); @@ -958,140 +775,29 @@ 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 addDatabaseCondition($queryType,$condition,$field) -	{ -		if ($queryType === "both") -		{ -			$this->addChooseCondition($this->databaseConditions,"insert",$condition,$field); -			$this->addChooseCondition($this->databaseConditions,"update",$condition."Compl",$field); -		} -		else -		{ -			$this->addChooseCondition($this->databaseConditions,$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 softCondition array -	public function addSoftCondition($queryType,$condition,$field) -	{ -		$this->addChooseCondition($this->softConditions,$queryType,$condition,$field); -	} -	 -	//add a condition to the valuesCondition array -	public function addValuesCondition($queryType,$condition,$field) -	{ -		$this->addChooseCondition($this->valuesConditions,$queryType,$condition,$field); -	} -	 -	//return the correct conditions array -	//$strength: strong,soft,values -	public function &getConditions($strength) -	{ -		if ($strength === 'strong') -		{ -			return $this->strongConditions; -		} -		else if ($strength === 'values') -		{ -			return $this->valuesConditions; -		} -		else if ($strength === 'database') -		{ -			return $this->databaseConditions; -		} - -		return $this->softConditions; -	} -	 -	//save the conditions -	//$strength: strong,soft,values -	public function saveConditions($strength) -	{ -		$this->backupConditions[$strength] = $this->getConditions($strength); -	} -	 -	//restore the conditions taking them from $this->backupConditions -	public function restoreConditions($strength) -	{ -		$c = &$this->getConditions($strength); -		 -		if (isset($this->backupConditions[$strength])) -		{ -			$c = $this->backupConditions[$strength]; -		} -	} -	 -	//clear the conditions -	//$strength: strong,soft,values -	public function clearConditions($strength) -	{ -		$c = &$this->getConditions($strength); -		$c = array(); -	}  	//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) -	//$strength: strong,soft,values +	//$strength: 'strong' or 'soft'  	public function applyValidateConditions($queryType,$strength = 'strong')  	{ -		$arrayToCheck = $_POST;  		if ($strength === 'strong')  		{  			$validateObj = $this->_arrayStrongCheck;  			$conditions = $this->strongConditions;  			$errString = 'strongConditions';  		} -		else if ($strength === 'values') -		{ -			$validateObj = $this->_arrayValuesCheck; -			$conditions = $this->valuesConditions; -			$errString = 'valuesConditions'; -			$arrayToCheck = $this->values; -		}  		else  		{  			$validateObj = $this->_arraySoftCheck;  			$conditions = $this->softConditions;  			$errString = 'softConditions'; +			 +			if (Params::$nullQueryValue !== false) +			{ +				$conditions['insert']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; +				$conditions['update']['+++++checkIsNotStrings|'.Params::$nullQueryValue] = 'all'; +			}  		}  		if (array_key_exists($queryType,$conditions)) @@ -1109,6 +815,18 @@ 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,'|'))  				{ @@ -1117,7 +835,7 @@ abstract class Model_Base  					$values = $temp[0];  				} -				$baseArgs = array($arrayToCheck,$values); +				$baseArgs = array($_POST,$values);  				if (strstr($key,'|'))  				{ @@ -1150,6 +868,7 @@ abstract class Model_Base  		}  	} +  	//apply, in sequence, the strong,soft and database conditions  	//$methodName: insert,update  	//$id: the id of the record. It is necessary for database conditions @@ -1189,10 +908,6 @@ 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))  					{ @@ -1232,9 +947,7 @@ abstract class Model_Base  			$popupWhereClause = array_key_exists($field,$this->_popupWhere) ? $this->_popupWhere[$field] : null; -			$popupOrderBy = array_key_exists($field,$this->_popupOrderBy) ? $this->_popupOrderBy[$field] : null; -			 -			$result = $this->db->select($table,$queryFields,$popupWhereClause,$fieldClean,$popupOrderBy); +			$result = $this->db->select($table,$queryFields,$popupWhereClause,$fieldClean);  			if ($result and $result !== false)  			{ @@ -1306,13 +1019,6 @@ abstract class Model_Base  		return $this;  	} -	//set the $convert property and return the current object -	public function convert($convert = true) -	{ -		$this->convert = $convert; -		return $this; -	} -	  	//set the $from property and return the current object  	public function from($tables = null)  	{ @@ -1371,12 +1077,6 @@ abstract class Model_Base  		return $this;  	} -	public function sWhere($sWhere) -	{ -		$this->sWhere = $sWhere; -		return $this; -	} -	  	//set the $groupBy property and return the current object  	public function groupBy($groupBy = null)  	{ @@ -1411,7 +1111,6 @@ abstract class Model_Base  	{  		$this->select = null;  		$this->where = array(); -		$this->sWhere = null;  		$this->groupBy = null;  		$this->orderBy = null;  		$this->limit = null; @@ -1420,84 +1119,9 @@ abstract class Model_Base  		$this->using = array();  		$this->join = array();  		$this->toList = false; -		$this->convert = false;  		return $this;  	} -	//save all the clauses of the select query -	public function save() -	{ -		$this->backupSelect["select"] = $this->select; -		$this->backupSelect["where"] = $this->where; -		$this->backupSelect["sWhere"] = $this->sWhere; -		$this->backupSelect["groupBy"] = $this->groupBy; -		$this->backupSelect["orderBy"] = $this->orderBy; -		$this->backupSelect["limit"] = $this->limit; -		$this->backupSelect["from"] = $this->from; -		$this->backupSelect["on"] = $this->on; -		$this->backupSelect["using"] = $this->using; -		$this->backupSelect["join"] = $this->join; -		$this->backupSelect["toList"] = $this->toList; -		$this->backupSelect["convert"] = $this->convert; -		return $this; -	} -	 -	//restored all the saved clauses of the select query -	public function restore() -	{ -		if (count($this->backupSelect) > 0) -		{ -			$this->select = $this->backupSelect["select"]; -			$this->where = $this->backupSelect["where"]; -			$this->sWhere = $this->backupSelect["sWhere"]; -			$this->groupBy = $this->backupSelect["groupBy"]; -			$this->orderBy = $this->backupSelect["orderBy"]; -			$this->limit = $this->backupSelect["limit"]; -			$this->from = $this->backupSelect["from"]; -			$this->on = $this->backupSelect["on"]; -			$this->using = $this->backupSelect["using"]; -			$this->join = $this->backupSelect["join"]; -			$this->toList = $this->backupSelect["toList"]; -			$this->convert = $this->backupSelect["convert"]; -		} -		return $this; -	} -	 -	public function getSelectArrayFromEnumField($fieldName) -	{ -		$types = $this->db->getTypes($this->_tables, $fieldName, true, true); -		 -		if ($types) -		{ -			if (preg_match('/^('.implode("|",$this->db->getEnumTypes()).')\((.*?)\)/i',$types[$fieldName],$matches)) -			{ -				return $this->getSelectArrayFromEnumValues($matches[1], $matches[2]); -			} -		} -	} -	 -	public function getSelectArrayFromEnumValues($enumFunc, $enumValues) -	{ -		$enumFunc = strtolower($enumFunc); -		 -		$temp = array(); -		$strings = explode(",",$enumValues); -		for ($i=0;$i<count($strings);$i++) -		{ -			$val = trim($strings[$i],"'\""); -			 -			if (isset($this->_conversionFromDbObject) and method_exists($this->_conversionFromDbObject, $enumFunc)) -			{ -				$temp[$val] = call_user_func(array($this->_conversionFromDbObject, $enumFunc), $val); -			} -			else -			{ -				$temp[$val] = $val; -			} -		} -		return $temp; -	} -	  	//initialize and populate the ::form property (reference to a Form_Form object)  	public function setForm($defAction = null, $defSubmit = array(), $defMethod = 'POST', $defEnctype = null)  	{ @@ -1511,67 +1135,6 @@ abstract class Model_Base  			$this->form = new Form_Form($action,$submit,$method,$enctype); -			//get the entries from DB definition -			$types = $this->db->getTypes($this->_tables, "*", true, true); -			 -			foreach ($types as $field => $type) -			{ -				$entryType = "InputText"; -				$classType = "varchar_input"; -				$options = null; -				 -				if (strcmp($field, $this->_idFieldsArray[0]) === 0) -				{ -					$entryType = "Hidden"; -				} -				else if (preg_match('/^('.implode("|",$this->db->getTextTypes()).')/i',$type,$matches)) -				{ -					$entryType = "Textarea"; -					$classType = "text_input"; -				} -				else if (preg_match('/^('.implode("|",$this->db->getDateTypes()).')/i',$type,$matches)) -				{ -					$classType = "date_input"; -				} -				else if (preg_match('/^('.implode("|",$this->db->getEnumTypes()).')\((.*?)\)/i',$type,$matches)) -				{ -					$entryType = "Select"; -					$classType = "select_input"; -					$options = $this->getSelectArrayFromEnumValues($matches[1], $matches[2]); -				} -				 -				if (array_key_exists($field,$entries)) -				{ -					if (!array_key_exists("type",$entries[$field])) -					{ -						$entries[$field]["type"] = $entryType; -					} -					 -					if ($entryType === "Select" and !array_key_exists("options",$entries[$field])) -					{ -						$entries[$field]["options"] = $options; -						$entries[$field]["reverse"] = "yes"; -					} -					 -					if (!array_key_exists("className",$entries[$field])) -					{ -						$entries[$field]["className"] = $classType." ".Form_Form::$defaultEntryAttributes['className']; -					} -				} -				else -				{ -					$entries[$field]["type"] = $entryType; -						 -					if ($entryType === "Select") -					{ -						$entries[$field]["options"] = $options; -						$entries[$field]["reverse"] = "yes"; -					} -						 -					$entries[$field]["className"] = $classType." ".Form_Form::$defaultEntryAttributes['className']; -				} -			} -			  			if (isset($entries))  			{  				$this->form->setEntries($entries);  | 
