From 2747eb56a6b8422c5f8d67204c1b949a2fbdb33e Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 28 Jan 2016 16:26:01 +0100 Subject: [PATCH] Little silly fixes in corefields --- src/CoreFields/DateField.php | 16 +++-- src/CoreFields/DoubleField.php | 6 +- src/CoreFields/ForeignKeyField.php | 4 +- src/CoreFields/ImageField.php | 11 +++- src/Webmodel.php | 101 ++++++++++++++++------------- 5 files changed, 81 insertions(+), 57 deletions(-) diff --git a/src/CoreFields/DateField.php b/src/CoreFields/DateField.php index 0959c1d..e99d48c 100644 --- a/src/CoreFields/DateField.php +++ b/src/CoreFields/DateField.php @@ -34,13 +34,13 @@ class DateField extends PhangoField { { $final_value=0; - - if($this->set_default_time==0) + + /*if($this->set_default_time==0) { $final_value=PhaTime\DateTime::local_to_gmt(date(PhaTime\DateTime::$sql_format_time)); - } + }*/ if(gettype($value)=='array') { @@ -80,8 +80,14 @@ class DateField extends PhangoField { } } + if(PhaTime\DateTime::obtain_timestamp($value)) + { + + $final_value=PhaTime\DateTime::local_to_gmt($value); + + } - if($final_value===false) + if($final_value==0) { $this->error=1; @@ -122,4 +128,4 @@ class DateField extends PhangoField { } -?> \ No newline at end of file +?> diff --git a/src/CoreFields/DoubleField.php b/src/CoreFields/DoubleField.php index 8bca1f1..2cfc4e8 100644 --- a/src/CoreFields/DoubleField.php +++ b/src/CoreFields/DoubleField.php @@ -29,10 +29,10 @@ class DoubleField extends PhangoField { function check($value) { - $this->value=Utils::form_text($value); + //$this->value=Utils::form_text($value); settype($value, "double"); - if($this->value==0 && $this->required==true) + if($value==0 && $this->required==true) { $this->error=1; @@ -71,4 +71,4 @@ class DoubleField extends PhangoField { } -?> \ No newline at end of file +?> diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index 7d4dee8..344af22 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -114,7 +114,7 @@ class ForeignKeyField extends IntegerField{ function get_type_sql() { - return 'INT('.$this->size.') NOT NULL DEFAULT "0"'; + return 'INT('.$this->size.') NULL'; } @@ -168,4 +168,4 @@ class ForeignKeyField extends IntegerField{ } -?> \ No newline at end of file +?> diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php index 53cff53..872cb0d 100644 --- a/src/CoreFields/ImageField.php +++ b/src/CoreFields/ImageField.php @@ -25,7 +25,7 @@ class ImageField extends PhangoField { public $min_size=array(0, 0); public $prefix_id=1; public $img_minimal_height=array(); - public $func_token='Utils::get_token'; + public $func_token='PhangoApp\PhaUtils\Utils::get_token'; public $move_file_func='move_uploaded_file'; public $size=255; public $driver='gd'; @@ -71,6 +71,13 @@ class ImageField extends PhangoField { $name_image=$_FILES[$file_name]['name']; + + if($this->prefix_id) + { + + $name_image=hash('sha256', (call_user_func_array($this->func_token, array(25)))).'_'.$name_image; + + } $manager = new ImageManager(array('driver' => $this->driver)); @@ -321,4 +328,4 @@ class ImageField extends PhangoField { } -?> \ No newline at end of file +?> diff --git a/src/Webmodel.php b/src/Webmodel.php index a990a20..09fa042 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -921,7 +921,7 @@ class Webmodel { } ModelForm::pass_errors_to_form($this); - $this->std_error.=I18n::lang('error_model', 'cant_insert', 'Can\'t insert').' '; + $this->std_error.=I18n::lang('error_model', 'cant_insert', "Can't insert").' '; return 0; @@ -1845,72 +1845,83 @@ class Webmodel { $z=0; - foreach($this->components as $key => $field) - { - - //If is set the variable for this component make checking + if(count($this->fields_to_update)>0) + { + + foreach($this->components as $key => $field) + { + + //If is set the variable for this component make checking - if(isset($post[$key]) && ($field->protected==0 || $safe_query==1) && in_array($key, $this->fields_to_update)) - { - $this->components[$key]->update=$this->update; + if(isset($post[$key]) && ($field->protected==0 || $safe_query==1) && in_array($key, $this->fields_to_update)) + { + $this->components[$key]->update=$this->update; - //Check if the value is valid.. + //Check if the value is valid.. - $arr_components[$key]=$this->$func_check($key, $post[$key]); + $arr_components[$key]=$this->$func_check($key, $post[$key]); - //If value isn't valid and is required set error for this component... + //If value isn't valid and is required set error for this component... - if($this->components[$key]->required==1 && $this->components[$key]->error==1) - { - - //Set errors... + if($this->components[$key]->required==1 && $this->components[$key]->error==1) + { + + //Set errors... - if($this->components[$key]->std_error=='') - { + if($this->components[$key]->std_error=='') + { - $this->components[$key]->std_error=I18n::lang('common', 'field_required', 'Field required'); + $this->components[$key]->std_error=I18n::lang('common', 'field_required', 'Field required'); - } + } - $arr_std_error[]=I18n::lang('error_model', 'check_error_field', 'Error in field').' '.$key.' -> '.$this->components[$key]->std_error. ' '; - $set_error++; - - } - - $z++; - - } - else if($this->components[$key]->required==1) - { - - //If isn't set the value and this value is required set std_error. + $arr_std_error[]=I18n::lang('error_model', 'check_error_field', 'Error in field').' '.$key.' -> '.$this->components[$key]->std_error. ' '; + $set_error++; + + } + + $z++; + + } + else if($this->components[$key]->required==1) + { + + //If isn't set the value and this value is required set std_error. - $arr_std_error[]=I18n::lang('error_model', 'check_error_field_required', 'Error: Field required').' '.$key.' '; - - if($this->components[$key]->std_error=='') - { + $arr_std_error[]=I18n::lang('error_model', 'check_error_field_required', 'Error: Field required').' '.$key.' '; + + if($this->components[$key]->std_error=='') + { - $this->components[$key]->std_error=I18n::lang('common', 'field_required', 'Field required'); + $this->components[$key]->std_error=I18n::lang('common', 'field_required', 'Field required'); - } - - $set_error++; + } + + $set_error++; - } + } + + } + + } + else + { + + $this->std_error.='Error: no fields selected to update or insert '; + + } - } - if($z==0) { - $this->std_error='Error: no fields to check'; + $this->std_error.='Error: no fields to check '; $set_error++; } //Set std_error for the model where is stored all errors in checking... - $this->std_error=implode(', ', $arr_std_error); + $this->std_error.=implode(', ', $arr_std_error).' '; //If error return 0 @@ -2340,4 +2351,4 @@ class SuperModel { Webmodel::$m=new SuperModel(); -?> \ No newline at end of file +?>