Fixes in foreignkey and selec_count webmodel method

This commit is contained in:
Antonio de la Rosa 2016-09-04 06:51:45 +02:00
parent faa3f8198b
commit 86547f8955
4 changed files with 94 additions and 64 deletions

View file

@ -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);
}

View file

@ -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)

View file

@ -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,6 +752,16 @@ class Webmodel {
//Check execution
if($raw_query==0)
{
if(preg_match('/".*"/', $str_conditions) || preg_match('/\'.*\'/', $str_conditions))
{
throw new \Exception('Sorry, i cannot load raw data betwen quotes');
}
$z=0;
$arr_conditions=explode('?', $str_conditions);
@ -770,6 +783,9 @@ class Webmodel {
$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++;
}
}
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,6 +1384,9 @@ class Webmodel {
$arr_check_count=array();
if($raw_query==false)
{
foreach($fields_for_count as $key_component)
{
@ -1400,6 +1425,8 @@ class Webmodel {
$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)
{