Little silly fixes in corefields

This commit is contained in:
Antonio de la Rosa 2016-01-28 16:26:01 +01:00
parent a57f714cd2
commit 2747eb56a6
5 changed files with 81 additions and 57 deletions

View file

@ -34,13 +34,13 @@ class DateField extends PhangoField {
{ {
$final_value=0; $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)); $final_value=PhaTime\DateTime::local_to_gmt(date(PhaTime\DateTime::$sql_format_time));
} }*/
if(gettype($value)=='array') 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; $this->error=1;
@ -122,4 +128,4 @@ class DateField extends PhangoField {
} }
?> ?>

View file

@ -29,10 +29,10 @@ class DoubleField extends PhangoField {
function check($value) function check($value)
{ {
$this->value=Utils::form_text($value); //$this->value=Utils::form_text($value);
settype($value, "double"); settype($value, "double");
if($this->value==0 && $this->required==true) if($value==0 && $this->required==true)
{ {
$this->error=1; $this->error=1;
@ -71,4 +71,4 @@ class DoubleField extends PhangoField {
} }
?> ?>

View file

@ -114,7 +114,7 @@ class ForeignKeyField extends IntegerField{
function get_type_sql() 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{
} }
?> ?>

View file

@ -25,7 +25,7 @@ class ImageField extends PhangoField {
public $min_size=array(0, 0); public $min_size=array(0, 0);
public $prefix_id=1; public $prefix_id=1;
public $img_minimal_height=array(); 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 $move_file_func='move_uploaded_file';
public $size=255; public $size=255;
public $driver='gd'; public $driver='gd';
@ -71,6 +71,13 @@ class ImageField extends PhangoField {
$name_image=$_FILES[$file_name]['name']; $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)); $manager = new ImageManager(array('driver' => $this->driver));
@ -321,4 +328,4 @@ class ImageField extends PhangoField {
} }
?> ?>

View file

@ -921,7 +921,7 @@ class Webmodel {
} }
ModelForm::pass_errors_to_form($this); 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; return 0;
@ -1845,72 +1845,83 @@ class Webmodel {
$z=0; $z=0;
foreach($this->components as $key => $field) if(count($this->fields_to_update)>0)
{ {
//If is set the variable for this component make checking 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)) if(isset($post[$key]) && ($field->protected==0 || $safe_query==1) && in_array($key, $this->fields_to_update))
{ {
$this->components[$key]->update=$this->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) if($this->components[$key]->required==1 && $this->components[$key]->error==1)
{ {
//Set errors... //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. ' '; $arr_std_error[]=I18n::lang('error_model', 'check_error_field', 'Error in field').' '.$key.' -> '.$this->components[$key]->std_error. ' ';
$set_error++; $set_error++;
} }
$z++; $z++;
} }
else if($this->components[$key]->required==1) else if($this->components[$key]->required==1)
{ {
//If isn't set the value and this value is required set std_error. //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.' '; $arr_std_error[]=I18n::lang('error_model', 'check_error_field_required', 'Error: Field required').' '.$key.' ';
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');
} }
$set_error++; $set_error++;
} }
}
}
else
{
$this->std_error.='Error: no fields selected to update or insert ';
}
}
if($z==0) if($z==0)
{ {
$this->std_error='Error: no fields to check'; $this->std_error.='Error: no fields to check ';
$set_error++; $set_error++;
} }
//Set std_error for the model where is stored all errors in checking... //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 //If error return 0
@ -2340,4 +2351,4 @@ class SuperModel {
Webmodel::$m=new SuperModel(); Webmodel::$m=new SuperModel();
?> ?>