aboutsummaryrefslogtreecommitdiff
path: root/h-source/Library/Model
diff options
context:
space:
mode:
authorAntonio Gallo <tonicucoz@gmail.com>2011-05-08 15:26:22 +0000
committerAntonio Gallo <tonicucoz@gmail.com>2011-05-08 15:26:22 +0000
commitafc02bc1c3db9ffe8c9bf660c8aa08666752edfb (patch)
tree9a02b06b390dd0c1e796474b888e92c245473424 /h-source/Library/Model
parent7fdac301801bc44f6fdb343187413bdfd2d5366c (diff)
h-source:added new EasyGiant SVN version
Diffstat (limited to 'h-source/Library/Model')
-rwxr-xr-xh-source/Library/Model/Base.php97
-rwxr-xr-xh-source/Library/Model/Map.php35
-rwxr-xr-xh-source/Library/Model/Tree.php25
3 files changed, 113 insertions, 44 deletions
diff --git a/h-source/Library/Model/Base.php b/h-source/Library/Model/Base.php
index 4f2e783..753d93c 100755
--- a/h-source/Library/Model/Base.php
+++ b/h-source/Library/Model/Base.php
@@ -63,14 +63,17 @@ abstract class Model_Base
public $limit = null;
public $from = null; //from clause of the select queries
- public $on = null; //join part of the where clause of the select queries
- public $using = null; //using clause
+ public $on = array(); //on array
+ public $using = array(); //using array
+ public $join = array(); //join array
public $toList = false; //if the result have to be given in a list format
public $listArray = array(); //array containing the $key and the $value to be used to extract a list from a resultSet
//logic operator between statements in the where clause of select queries
public $logicalOperators = array('AND');
+
+ public $files = null; //reference to the Files_Upload class
protected $_tables='itemTable,boxTable,item_boxTable';
protected $_idFields='id_item,id_box';
@@ -149,9 +152,20 @@ abstract class Model_Base
//instantiate the database class
$this->db = Factory_Db::getInstance(DATABASE_TYPE);
+
+ //instantiate the Files_Upload class
+ $params = array(
+ 'filesPermission' => 0777,
+ 'language' => $this->_lang,
+ 'allowedExtensions' => 'png,jpg,jpeg,gif',
+ 'maxFileSize' => 20000000,
+ 'fileUploadKey' => 'userfile'
+ );
+
+ $this->files = new Files_Upload(ROOT."/media/",$params);
}
- //sanitize all the $values proprierty
+ //sanitize all the $values property
public function sanitize()
{
$this->values = $this->arrayExt->subset($this->values,null,'sanitizeDb');
@@ -331,13 +345,25 @@ abstract class Model_Base
if (array_key_exists($entry,$values))
{
if (!function_exists($funcUponEntry)) {
- throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$funcUponEntry. '</b> does not exists');
+ throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$funcUponEntry. '</b> does not exist');
}
$values[$entry] = call_user_func($funcUponEntry,$values[$entry]);
}
}
-
+
+ //set values of $_SESSION array
+ foreach ($values as $k => $v)
+ {
+ if (isset($this->formStruct['entries'][$k]['type']))
+ {
+ if ($this->formStruct['entries'][$k]['type'] === 'File')
+ {
+ session_start();
+ $_SESSION['form_'.$k] = $v;
+ }
+ }
+ }
}
}
else if ($queryType === 'insert')
@@ -356,6 +382,24 @@ abstract class Model_Base
if ($queryType === 'update')
{
$values[$idName] = $ident;
+
+ //take values from $_SESSION array
+ $tempFieldArray = explode(',',$this->fields);
+
+ for ($i = 0; $i < count($tempFieldArray); $i++)
+ {
+ if (isset($this->formStruct['entries'][$tempFieldArray[$i]]['type']))
+ {
+ if ($this->formStruct['entries'][$tempFieldArray[$i]]['type'] === 'File')
+ {
+ session_start();
+ if (isset($_SESSION['form_'.$tempFieldArray[$i]]))
+ {
+ $values[$tempFieldArray[$i]] = $_SESSION['form_'.$tempFieldArray[$i]];
+ }
+ }
+ }
+ }
}
}
}
@@ -886,7 +930,7 @@ abstract class Model_Base
{
if (!function_exists($this->_popupFunctions[$field]))
{
- throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$this->_popupFunctions[$field]. '</b> does not exists');
+ throw new Exception('Error in <b>'.__METHOD__.'</b>: function <b>'.$this->_popupFunctions[$field]. '</b> does not exist');
}
$tempName = call_user_func($this->_popupFunctions[$field],$row[$itemNameTable][$itemNameClean]);
@@ -945,17 +989,40 @@ abstract class Model_Base
return $this;
}
- //set the $on property and return the current object
+ //set the on property and return the current object
public function on($joinClause = '-')
{
- $this->on = $joinClause;
+ $this->on[] = $joinClause;
+ $this->using[] = null;
return $this;
}
//set the $using property and return the current object
public function using($using = null)
{
- $this->using = $using;
+ $this->using[] = $using;
+ $this->on[] = null;
+ return $this;
+ }
+
+ //set the $join property and return the current object
+ public function left($string = null)
+ {
+ $this->join[] = "l:$string";
+ return $this;
+ }
+
+ //set the $join property and return the current object
+ public function right($string = null)
+ {
+ $this->join[] = "r:$string";
+ return $this;
+ }
+
+ //set the $join property and return the current object
+ public function inner($string = null)
+ {
+ $this->join[] = "i:$string";
return $this;
}
@@ -1011,14 +1078,15 @@ abstract class Model_Base
$this->orderBy = null;
$this->limit = null;
$this->from = null;
- $this->on = null;
- $this->using = null;
+ $this->on = array();
+ $this->using = array();
+ $this->join = array();
$this->toList = false;
return $this;
}
//initialize and populate the ::form property (reference to a Form_Form object)
- public function setForm($defAction = null, $defSubmit = array(), $defMethod = 'POST')
+ public function setForm($defAction = null, $defSubmit = array(), $defMethod = 'POST', $defEnctype = null)
{
if (isset($this->formStruct))
{
@@ -1026,8 +1094,9 @@ abstract class Model_Base
$submit = array_key_exists('submit',$this->formStruct) ? $this->formStruct['submit'] : $defSubmit;
$entries = array_key_exists('entries',$this->formStruct) ? $this->formStruct['entries'] : null;
$method = array_key_exists('post',$this->formStruct) ? $this->formStruct['post'] : $defMethod;
+ $enctype = array_key_exists('enctype',$this->formStruct) ? $this->formStruct['enctype'] : $defEnctype;
- $this->form = new Form_Form($action,$submit,$method);
+ $this->form = new Form_Form($action,$submit,$method,$enctype);
if (isset($entries))
{
@@ -1082,7 +1151,7 @@ abstract class Model_Base
}
else
{
- $this->form = new Form_Form($defAction,$defSubmit,$defMethod);
+ $this->form = new Form_Form($defAction,$defSubmit,$defMethod,$defEnctype);
}
}
diff --git a/h-source/Library/Model/Map.php b/h-source/Library/Model/Map.php
index 4fe562d..10166db 100755
--- a/h-source/Library/Model/Map.php
+++ b/h-source/Library/Model/Map.php
@@ -42,25 +42,18 @@ class Model_Map extends Model_Base {
public function createMapWhere($choice)
{ //create the where join clause
//$choice=(first,last,all)
- if (isset($this->on))
- {
- return $this->on;
- }
- else
- {
- $first = $this->_tablesArray[0].'.'.$this->_idFieldsArray[0].'='.$this->_tablesArray[2].'.'.$this->_idFieldsArray[0];
- $last = $this->_tablesArray[1].'.'.$this->_idFieldsArray[1].'='.$this->_tablesArray[2].'.'.$this->_idFieldsArray[1];
- switch ($choice) {
- case 'first':
- return $first;
- break;
- case 'last':
- return $last;
- break;
- case 'all':
- return $first. ' and '.$last;
- break;
- }
+ $first = $this->_tablesArray[0].'.'.$this->_idFieldsArray[0].'='.$this->_tablesArray[2].'.'.$this->_idFieldsArray[0];
+ $last = $this->_tablesArray[1].'.'.$this->_idFieldsArray[1].'='.$this->_tablesArray[2].'.'.$this->_idFieldsArray[1];
+ switch ($choice) {
+ case 'first':
+ return $first;
+ break;
+ case 'last':
+ return $last;
+ break;
+ case 'all':
+ return $first. ' and '.$last;
+ break;
}
}
@@ -168,6 +161,8 @@ class Model_Map extends Model_Base {
public function selectId($id,$fields = null)
{
$id = (int)$id;
+
+ $tempWhere = $this->where;
$this->setWhereQueryClause(array($this->_idFieldsArray[0] => $id));
if (isset($fields))
@@ -178,6 +173,8 @@ class Model_Map extends Model_Base {
{
$values = $this->getAll('Items');
}
+
+ $this->where = $tempWhere;
return (count($values) > 0) ? $values[0][$this->_tablesArray[0]] : array();
}
diff --git a/h-source/Library/Model/Tree.php b/h-source/Library/Model/Tree.php
index 4dcac8f..56a5db3 100755
--- a/h-source/Library/Model/Tree.php
+++ b/h-source/Library/Model/Tree.php
@@ -29,7 +29,7 @@ class Model_Tree extends Model_Base {
//method to create the first part of where clause
//$index: the index of $this->_tablesArray
public function createTreeWhere($index) {
- if (isset($this->on))
+ if (!empty($this->on))
{
return $this->on;
}
@@ -90,9 +90,9 @@ class Model_Tree extends Model_Base {
$wherePlus = $this->createWhereClause();
- if (!isset($this->on))
+ if (empty($this->on))
{
- $on = null;
+ $on = array();
if (isset($where) and isset($wherePlus))
{
@@ -105,7 +105,7 @@ class Model_Tree extends Model_Base {
}
else
{
- $on = (strcmp($where,'-') !== 0) ? $where : null;
+ $on = (isset($where[0]) and strcmp($where[0],'-') !== 0) ? $where : array();
$where = $wherePlus;
}
@@ -128,7 +128,7 @@ class Model_Tree extends Model_Base {
$queryFields = (strcmp($fields,'') === 0) ? $elements['fields'] : $fields;
- return $row = $this->db->select($elements['tables'],$queryFields,$elements['where'],$this->groupBy,$this->orderBy,$this->limit,$elements['on'],$this->using);
+ return $row = $this->db->select($elements['tables'],$queryFields,$elements['where'],$this->groupBy,$this->orderBy,$this->limit,$elements['on'],$this->using,$this->join);
}
public function send()
@@ -158,6 +158,7 @@ class Model_Tree extends Model_Base {
//$id: the id (primary key) of the record
//$fields: the comma separated list of fields that have to be extracted
public function selectId($id,$fields = null) {
+ $tempWhere = $this->where;
$this->setWhereQueryClause(array($this->_idFieldsArray[0] => (int)$id));
$this->using = null;
@@ -170,6 +171,8 @@ class Model_Tree extends Model_Base {
{
$values = $this->getAll('other');
}
+
+ $this->where = $tempWhere;
return (count($values) > 0) ? $values[0][$this->_tablesArray[0]] : array();
@@ -179,38 +182,38 @@ class Model_Tree extends Model_Base {
//the number of records of the table $tableName is returned
public function rowNumber() {
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->get_num_rows($elements['tables'],$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->get_num_rows($elements['tables'],$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
public function getMax($field)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->getMax($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->getMax($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
public function getMin($field)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->getMin($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->getMin($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
public function getSum($field)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->getSum($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->getSum($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
public function getAvg($field)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->getAvg($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->getAvg($elements['tables'],$field,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
//check if the table has the field $field equal to $value
public function has($field,$value)
{
$elements = $this->treeQueryElements($this->_tablesArray[0]);
- return $this->db->recordExists($elements['tables'],$field,$value,$elements['where'],$this->groupBy,$elements['on'],$this->using);
+ return $this->db->recordExists($elements['tables'],$field,$value,$elements['where'],$this->groupBy,$elements['on'],$this->using,$this->join);
}
// //get the number of records of the table $this->_tablesArray[0]