Fixes in foreignkey and selec_count webmodel method
This commit is contained in:
parent
faa3f8198b
commit
86547f8955
4 changed files with 94 additions and 64 deletions
|
|
@ -40,7 +40,8 @@ class ForeignKeyField extends IntegerField{
|
|||
$this->quot_open='';
|
||||
$this->quot_close='';
|
||||
$this->protected=0;
|
||||
$this->parameters=array($this->related_model, $name_field);
|
||||
//($name, $value, $model, $field_name, $field_value)
|
||||
$this->parameters=array($this->related_model, $name_field, $name_field);
|
||||
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -359,7 +359,7 @@ class ModelForm {
|
|||
if($error==0 && $num_form>0)
|
||||
{
|
||||
|
||||
return [$post, $arr_form];
|
||||
return [$arr_form, $post];
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -462,6 +462,8 @@ class ModelForm {
|
|||
|
||||
}
|
||||
|
||||
return $model;
|
||||
|
||||
}
|
||||
|
||||
static public function pass_errors_to_array($model)
|
||||
|
|
@ -480,7 +482,7 @@ class ModelForm {
|
|||
|
||||
}
|
||||
|
||||
static public function show_form($arr_form, $post, $pass_values=false)
|
||||
static public function show_form($arr_form, $post, $pass_values=false, $check_values=false)
|
||||
{
|
||||
|
||||
if($pass_values)
|
||||
|
|
|
|||
101
src/Webmodel.php
101
src/Webmodel.php
|
|
@ -712,6 +712,8 @@ class Webmodel {
|
|||
|
||||
$args=$this->args;
|
||||
|
||||
$raw_query=0;
|
||||
|
||||
if(gettype($conditions)=='array')
|
||||
{
|
||||
|
||||
|
|
@ -729,6 +731,7 @@ class Webmodel {
|
|||
}
|
||||
else
|
||||
{
|
||||
$raw_query=1;
|
||||
|
||||
$str_conditions=$conditions;
|
||||
|
||||
|
|
@ -749,27 +752,40 @@ class Webmodel {
|
|||
|
||||
//Check execution
|
||||
|
||||
$z=0;
|
||||
|
||||
$arr_conditions=explode('?', $str_conditions);
|
||||
|
||||
foreach($args as $key => $arg)
|
||||
if($raw_query==0)
|
||||
{
|
||||
$quot='"';
|
||||
|
||||
if(gettype($arg)==='integer' || gettype($arg)==='float')
|
||||
if(preg_match('/".*"/', $str_conditions) || preg_match('/\'.*\'/', $str_conditions))
|
||||
{
|
||||
|
||||
$quot='';
|
||||
throw new \Exception('Sorry, i cannot load raw data betwen quotes');
|
||||
|
||||
}
|
||||
|
||||
$arr_conditions[$key]=trim($arr_conditions[$key].$quot.$this->escape_string($arg).$quot);
|
||||
$z=0;
|
||||
|
||||
$arr_conditions=explode('?', $str_conditions);
|
||||
|
||||
foreach($args as $key => $arg)
|
||||
{
|
||||
$quot='"';
|
||||
|
||||
if(gettype($arg)==='integer' || gettype($arg)==='float')
|
||||
{
|
||||
|
||||
$quot='';
|
||||
|
||||
}
|
||||
|
||||
$arr_conditions[$key]=trim($arr_conditions[$key].$quot.$this->escape_string($arg).$quot);
|
||||
|
||||
}
|
||||
|
||||
$this->conditions=trim(implode(' ', $arr_conditions));
|
||||
|
||||
|
||||
}
|
||||
|
||||
$this->conditions=trim(implode(' ', $arr_conditions));
|
||||
|
||||
}
|
||||
|
||||
//$this->order_by=$order_by;
|
||||
|
|
@ -787,6 +803,7 @@ class Webmodel {
|
|||
{
|
||||
|
||||
$arr_order=[];
|
||||
$yes_order=0;
|
||||
|
||||
foreach($order_by as $key => $order)
|
||||
{
|
||||
|
|
@ -801,12 +818,17 @@ class Webmodel {
|
|||
{
|
||||
|
||||
$arr_order[]=$key.' '.$arr_set_order[$order];
|
||||
$yes_order++;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$this->order_by='order by '.implode(',', $arr_order);
|
||||
if($yes_order>0)
|
||||
{
|
||||
|
||||
$this->order_by='order by '.implode(',', $arr_order);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
|
@ -1345,7 +1367,7 @@ class Webmodel {
|
|||
* @param string $fields_for_count Array for fields used for simple counts based on foreignkeyfields.
|
||||
*/
|
||||
|
||||
public function select_count($field='', $fields_for_count=array())
|
||||
public function select_count($field='', $fields_for_count=array(), $raw_query=true)
|
||||
{
|
||||
|
||||
$this->set_phango_connection();
|
||||
|
|
@ -1362,45 +1384,50 @@ class Webmodel {
|
|||
|
||||
$arr_check_count=array();
|
||||
|
||||
foreach($fields_for_count as $key_component)
|
||||
{
|
||||
if($raw_query==false)
|
||||
{
|
||||
|
||||
if(isset($this->components[$key_component]))
|
||||
{
|
||||
foreach($fields_for_count as $key_component)
|
||||
{
|
||||
|
||||
$component=$this->components[$key_component];
|
||||
if(isset($this->components[$key_component]))
|
||||
{
|
||||
|
||||
if(get_class($component)=='ForeignKeyField')
|
||||
{
|
||||
$component=$this->components[$key_component];
|
||||
|
||||
$table_name=$component->related_model;
|
||||
if(get_class($component)=='ForeignKeyField')
|
||||
{
|
||||
|
||||
if(isset($arr_check_count[$table_name]))
|
||||
{
|
||||
$table_name=$component->related_model;
|
||||
|
||||
$table_name.='_'.uniqid();
|
||||
if(isset($arr_check_count[$table_name]))
|
||||
{
|
||||
|
||||
}
|
||||
$table_name.='_'.uniqid();
|
||||
|
||||
$arr_model[]=$component->related_model.' as '.$table_name;
|
||||
}
|
||||
|
||||
$arr_where[]=$this->name.'.`'.$key_component.'`='.$table_name.'.`'.Webmodel::$model[$component->related_model]->idmodel.'`';
|
||||
$arr_model[]=$component->related_model.' as '.$table_name;
|
||||
|
||||
$arr_check_count[$table_name]=1;
|
||||
$arr_where[]=$this->name.'.`'.$key_component.'`='.$table_name.'.`'.Webmodel::$model[$component->related_model]->idmodel.'`';
|
||||
|
||||
}
|
||||
$arr_check_count[$table_name]=1;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach($this->related_models as $model_name_related => $fields_related)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
$arr_model[]=$model_name_related;
|
||||
foreach($this->related_models as $model_name_related => $fields_related)
|
||||
{
|
||||
|
||||
$arr_where[]=$this->name.'.`'.$this->idmodel.'`='.$model_name_related.'.`'.$fields_related[0].'`';
|
||||
$arr_model[]=$model_name_related;
|
||||
|
||||
}
|
||||
$arr_where[]=$this->name.'.`'.$this->idmodel.'`='.$model_name_related.'.`'.$fields_related[0].'`';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$where=implode(" and ", $arr_where);
|
||||
|
||||
|
|
@ -1411,7 +1438,7 @@ class Webmodel {
|
|||
|
||||
}
|
||||
|
||||
$conditions=trim($this->conditions.$where.' '.$this->order_by.' '.$this->limit);
|
||||
$conditions=trim($this->conditions.$where);
|
||||
|
||||
if($this->reset_conditions==1)
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue