From 479f449b132ac5b38fdc65f408034eb11b6591cb Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 17 Dec 2015 01:48:11 +0100 Subject: [PATCH] Little change for management better the errors in fields --- src/CoreFields/CharField.php | 2 +- src/CoreFields/ChoiceField.php | 2 +- src/CoreFields/DateField.php | 4 ++-- src/CoreFields/DateTimeField.php | 16 ++++++++++++++-- src/CoreFields/DoubleField.php | 8 ++++++++ src/CoreFields/EmailField.php | 2 ++ src/CoreFields/FileField.php | 4 ++++ src/CoreFields/ForeignKeyField.php | 2 +- src/CoreFields/I18nField.php | 2 +- src/CoreFields/ImageField.php | 11 +++++++++++ src/CoreFields/IntegerField.php | 13 ++++++++++--- src/CoreFields/IpField.php | 4 +++- src/CoreFields/KeyField.php | 1 + src/CoreFields/NormalizeField.php | 10 +++++++++- src/CoreFields/ParentField.php | 2 +- src/CoreFields/PasswordField.php | 5 ++++- src/CoreFields/PercentField.php | 2 ++ src/CoreFields/PhoneField.php | 1 + src/CoreFields/PrimaryField.php | 8 ++++++++ src/CoreFields/SlugifyField.php | 11 ++++++++++- src/CoreFields/TextField.php | 12 +++++++++++- src/CoreFields/TextHTMLField.php | 12 +++++++++++- src/CoreFields/UrlField.php | 4 +++- src/Databases/MySQLClass.php | 4 ++-- src/Webmodel.php | 6 +++--- 25 files changed, 124 insertions(+), 24 deletions(-) diff --git a/src/CoreFields/CharField.php b/src/CoreFields/CharField.php index aeefd3b..ef8e0fd 100644 --- a/src/CoreFields/CharField.php +++ b/src/CoreFields/CharField.php @@ -64,7 +64,7 @@ class CharField extends PhangoField { } - return Utils::form_text($value); + return $value; } diff --git a/src/CoreFields/ChoiceField.php b/src/CoreFields/ChoiceField.php index e2f3c1f..e2b16c3 100644 --- a/src/CoreFields/ChoiceField.php +++ b/src/CoreFields/ChoiceField.php @@ -84,7 +84,7 @@ class ChoiceField extends PhangoField { } else { - + $this->error=1; return $this->default_value; } diff --git a/src/CoreFields/DateField.php b/src/CoreFields/DateField.php index 2b6d4af..ff2ec0c 100644 --- a/src/CoreFields/DateField.php +++ b/src/CoreFields/DateField.php @@ -82,8 +82,8 @@ class DateField extends PhangoField { if($final_value===false) { - - $final_value=mktime (0, 0, 0, $arr_time[1], $arr_time[2], $arr_time[0] ); + $this->error=true; + $final_value=mktime(date('H'), date('i'), date('s')); } diff --git a/src/CoreFields/DateTimeField.php b/src/CoreFields/DateTimeField.php index 8c91dc9..749e7d6 100644 --- a/src/CoreFields/DateTimeField.php +++ b/src/CoreFields/DateTimeField.php @@ -25,8 +25,20 @@ class DateTimeField extends DateField $timestamp=parent::check($value); - return date('YmdHis', $timestamp); - + $date=@date('YmdHis', $timestamp); + + if($date!==false) + { + return date('YmdHis', $timestamp); + } + else + { + + $this->error=true; + + return date('YmdHis'); + + } } public function search_field($value) diff --git a/src/CoreFields/DoubleField.php b/src/CoreFields/DoubleField.php index 6471eff..8bca1f1 100644 --- a/src/CoreFields/DoubleField.php +++ b/src/CoreFields/DoubleField.php @@ -31,6 +31,14 @@ class DoubleField extends PhangoField { $this->value=Utils::form_text($value); settype($value, "double"); + + if($this->value==0 && $this->required==true) + { + + $this->error=1; + + } + return $value; } diff --git a/src/CoreFields/EmailField.php b/src/CoreFields/EmailField.php index a7666db..bc20107 100644 --- a/src/CoreFields/EmailField.php +++ b/src/CoreFields/EmailField.php @@ -52,6 +52,8 @@ class EmailField extends PhangoField { $this->std_error='Email format error'; + $this->error=1; + return ''; } diff --git a/src/CoreFields/FileField.php b/src/CoreFields/FileField.php index abf42fc..0517675 100644 --- a/src/CoreFields/FileField.php +++ b/src/CoreFields/FileField.php @@ -75,6 +75,8 @@ class FileField extends PhangoField { $this->std_error=I18n::lang('common', 'error_cannot_upload_this_file_to_the_server', 'Error: Cannot upload this file to the server'); + $this->error=1; + return ''; } @@ -94,6 +96,8 @@ class FileField extends PhangoField { $this->std_error=I18n::lang('error_model', 'check_error_enctype_for_upload_file', 'Please, check enctype form of file form'); + $this->error=1; + return ''; } diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index 0b85620..beb49fc 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -91,7 +91,7 @@ class ForeignKeyField extends IntegerField{ else { - + $this->error=1; return $this->default_id; diff --git a/src/CoreFields/I18nField.php b/src/CoreFields/I18nField.php index 094b212..7c03594 100644 --- a/src/CoreFields/I18nField.php +++ b/src/CoreFields/I18nField.php @@ -60,7 +60,7 @@ class I18nField extends PhangoField { { $this->std_error=I18n::lang('common', 'error_you_need_this_language_field', 'Error, you need this language field').' '.I18n::$language; - + $this->error=1; return ''; } diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php index 7cf2199..76c636a 100644 --- a/src/CoreFields/ImageField.php +++ b/src/CoreFields/ImageField.php @@ -98,6 +98,9 @@ class ImageField extends PhangoField { if(!@unlink($this->path.'/'.$prefix.'_'.$base_old_image)) { + + // $this->error=true; + $this->std_error=I18n::lang('common', 'cannot_delete_old_image', 'Cannot delete old thumb images, please, check permissions'); } @@ -147,6 +150,8 @@ class ImageField extends PhangoField { if(!$image->fit($width)->encode('jpg', $this->quality_jpeg)->save($this->path.'/'.$prefix.'_'.$base_name_image.'.jpg')) { + $this->error=true; + $this->std_error=I18n::lang('common', 'cannot_save_images', 'Cannot save images. Please, check permissions'); } @@ -169,6 +174,8 @@ class ImageField extends PhangoField { if(!$image->save($this->path.'/'.$name_image)) { + $this->error=1; + $this->std_error=I18n::lang('common', 'cannot_save_images', 'Cannot save images, please, check permissions'); return ''; @@ -183,6 +190,8 @@ class ImageField extends PhangoField { $this->std_error=I18n::lang('common', 'no_valid_image', 'This image is wrong'); + $this->error=1; + return ''; } @@ -196,6 +205,8 @@ class ImageField extends PhangoField { } + $this->error=true; + $this->std_error=I18n::lang('common', 'no_image_found', 'No image uploaded, check enctype form'); return ''; diff --git a/src/CoreFields/IntegerField.php b/src/CoreFields/IntegerField.php index 688d1cf..02ae386 100644 --- a/src/CoreFields/IntegerField.php +++ b/src/CoreFields/IntegerField.php @@ -7,6 +7,7 @@ namespace PhangoApp\PhaModels\CoreFields; use PhangoApp\PhaUtils\Utils; +use PhangoApp\PhaI18n\I18n; class IntegerField extends PhangoField { @@ -44,15 +45,21 @@ class IntegerField extends PhangoField { } if($this->min_num<>0 && $value<$this->min_num) - { - + { + $this->std_error=I18n::lang('common', 'no_value', 'The value is wrong. You need a value betwen '.$this->min_num.' and '.$this->max_num); + + $this->error=1; + $value=$this->min_num; } if($this->max_num<>0 && $value>$this->max_num) { - + $this->std_error=I18n::lang('common', 'no_value', 'The value is wrong. You need a value betwen '.$this->min_num.' and '.$this->max_num); + + $this->error=1; + $value=$this->max_num; } diff --git a/src/CoreFields/IpField.php b/src/CoreFields/IpField.php index 43d6322..cdfeb32 100644 --- a/src/CoreFields/IpField.php +++ b/src/CoreFields/IpField.php @@ -18,8 +18,10 @@ class IpField extends CharField { } else { + $this->std_error=I18n::lang('common', 'no_valid_ip', 'This ip is not valid'); + $this->error=1; - return false; + return ""; } diff --git a/src/CoreFields/KeyField.php b/src/CoreFields/KeyField.php index 770813f..b8a1d88 100644 --- a/src/CoreFields/KeyField.php +++ b/src/CoreFields/KeyField.php @@ -36,6 +36,7 @@ class KeyField extends PhangoField { $this->value=Utils::form_text($value); settype($value, "integer"); + return $value; } diff --git a/src/CoreFields/NormalizeField.php b/src/CoreFields/NormalizeField.php index 666de63..141ee52 100644 --- a/src/CoreFields/NormalizeField.php +++ b/src/CoreFields/NormalizeField.php @@ -18,8 +18,16 @@ class NormalizeField extends TextField { public function check($value) { + $value=$this->check_text($value); - return $this->check_text($value); + if($value=='') + { + + $this->error=1; + + } + + return $value; } diff --git a/src/CoreFields/ParentField.php b/src/CoreFields/ParentField.php index a6517ef..5a02f6d 100644 --- a/src/CoreFields/ParentField.php +++ b/src/CoreFields/ParentField.php @@ -38,7 +38,7 @@ class ParentField extends IntegerField{ } else { - + $this->error=1; return 0; } diff --git a/src/CoreFields/PasswordField.php b/src/CoreFields/PasswordField.php index 97be817..45e88f4 100644 --- a/src/CoreFields/PasswordField.php +++ b/src/CoreFields/PasswordField.php @@ -31,7 +31,8 @@ class PasswordField extends CharField { if($value=='') { - + $this->error=1; + return ''; } @@ -45,6 +46,8 @@ class PasswordField extends CharField { if(strlen($value)<$this->min_length) { + $this->error=1; + $this->std_error=I18n::lang('common', 'password_min_length', 'Minimal password length:').' '.$this->min_length; return ''; diff --git a/src/CoreFields/PercentField.php b/src/CoreFields/PercentField.php index 6deda91..e23e033 100644 --- a/src/CoreFields/PercentField.php +++ b/src/CoreFields/PercentField.php @@ -18,6 +18,8 @@ class PercentField extends IntegerField{ $this->std_error=i18n_lang('common', 'the_value_can_not_be_greater_than_100', 'The value cannot be greater than 100'); + $this->error=1; + return 0; } diff --git a/src/CoreFields/PhoneField.php b/src/CoreFields/PhoneField.php index c00689a..00cbdbf 100644 --- a/src/CoreFields/PhoneField.php +++ b/src/CoreFields/PhoneField.php @@ -18,6 +18,7 @@ class PhoneField extends CharField{ if(!preg_match('/^[0-9]+$/', $value)) { + $this->error=1; return ''; diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index 633119f..df85c8d 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -53,6 +53,14 @@ class PrimaryField extends PhangoField { $this->value=Utils::form_text($value); settype($value, "integer"); + + if($this->value==0) + { + + $this->error=1; + + } + return $value; } diff --git a/src/CoreFields/SlugifyField.php b/src/CoreFields/SlugifyField.php index 6ac3842..ab98170 100644 --- a/src/CoreFields/SlugifyField.php +++ b/src/CoreFields/SlugifyField.php @@ -20,8 +20,17 @@ class SlugifyField extends PhangoField { static function check($value) { + + $value=slugify($value); - return slugify($value); + if($value=='') + { + + $this->error=1; + + } + + return $value; } function get_type_sql() diff --git a/src/CoreFields/TextField.php b/src/CoreFields/TextField.php index 344cc89..507b26e 100644 --- a/src/CoreFields/TextField.php +++ b/src/CoreFields/TextField.php @@ -32,7 +32,17 @@ class TextField extends PhangoField { //Delete Javascript tags and simple quotes. $this->value=$value; - return Utils::form_text($value, $this->br); + + $value=Utils::form_text($value, $this->br); + + if($value=='') + { + + $this->error=1; + + } + + return $value; } diff --git a/src/CoreFields/TextHTMLField.php b/src/CoreFields/TextHTMLField.php index 30eb094..b414feb 100644 --- a/src/CoreFields/TextHTMLField.php +++ b/src/CoreFields/TextHTMLField.php @@ -43,6 +43,7 @@ class TextHTMLField extends PhangoField { if($txt_without_tags=='') { + $this->error=true; return ''; } @@ -60,7 +61,16 @@ class TextHTMLField extends PhangoField { } - return Utils::form_text_html($value, $this->allowedtags); + $value=Utils::form_text_html($value, $this->allowedtags); + + if($value=='') + { + + $this->error=1; + + } + + return $value; } diff --git a/src/CoreFields/UrlField.php b/src/CoreFields/UrlField.php index 84e873e..768b96e 100644 --- a/src/CoreFields/UrlField.php +++ b/src/CoreFields/UrlField.php @@ -19,7 +19,9 @@ class UrlField extends CharField { else { - return false; + $this->error=1; + + return ''; } diff --git a/src/Databases/MySQLClass.php b/src/Databases/MySQLClass.php index 82b91bb..777c3b3 100644 --- a/src/Databases/MySQLClass.php +++ b/src/Databases/MySQLClass.php @@ -62,8 +62,8 @@ class SQLClass { static public function webtsys_fetch_array( $query ,$assoc_type=0) { - $arr_assoc[0]=MYSQL_ASSOC; - $arr_assoc[1]=MYSQL_NUM; + $arr_assoc[0]=MYSQLI_ASSOC; + $arr_assoc[1]=MYSQLI_NUM; $arr_final = mysqli_fetch_array( $query ,$arr_assoc[$assoc_type]); diff --git a/src/Webmodel.php b/src/Webmodel.php index 3b9682a..ecafbd1 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -1844,9 +1844,9 @@ class Webmodel { //If value isn't valid and is required set error for this component... - if($this->components[$key]->required==1 && $arr_components[$key]=="") + if($this->components[$key]->required==1 && $this->components[$key]->error==1) { - + //Set errors... if($this->components[$key]->std_error=='') @@ -1906,7 +1906,7 @@ class Webmodel { } //If not return values sanitized... - + return $arr_components; }