From 5a69e2d66d3d5a2d02a8b7a424ce5deef76bfb7a Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 16 Apr 2015 02:53:21 +0200 Subject: [PATCH 01/43] first commit --- README.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..66038ed --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +# phaview From 92e7b17f0e720986480893d8c6c25bff2d584453 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 19 Apr 2015 15:22:10 +0200 Subject: [PATCH 02/43] Added new files --- composer.json | 22 ++++++ src/View.php | 180 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 202 insertions(+) create mode 100644 composer.json create mode 100644 src/View.php diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..c03ded6 --- /dev/null +++ b/composer.json @@ -0,0 +1,22 @@ +{ + "name": "phangoapp/phaview", + "description": "A simple class for create views", + "require-dev": { + "phpunit/phpunit": "~4.8@dev", + "phautils/utils": "dev-master" + }, + "license": "GPL", + "authors": [ + { + "name": "Antonio de la Rosa", + "email": "webmaster@web-t-sys.com" + } + ], + "minimum-stability": "dev-master", + "require": {}, + "autoload": { + "psr-4": { + "PhaRouter\\": "src" + } + } +} diff --git a/src/View.php b/src/View.php new file mode 100644 index 0000000..c58c89f --- /dev/null +++ b/src/View.php @@ -0,0 +1,180 @@ +0) + { + + $this->folder_env=$arr_arg; + + } + + $this->root_path=getcwd(); + + } + + /** + * Very important function used for load views. Is the V in the MVC paradigm. Phango is an MVC framework and has separate code and html. + * + * load_view is used for load the views. Views in Phango are php files with a function that have a special name with "View" suffix. For example, if you create a view file with the name blog.php, inside you need create a php function called BlogView(). The arguments of this function can be that you want, how on any normal php function. The view files need to be saved on a "view" folders inside of a theme folder, or a "views/module_name" folder inside of a module being "module_name" the name of the module. + * + * @param array $arr_template_values Arguments for the view function of the view. + * @param string $template Name of the view. Tipically views/$template.php or modules/name_module/views/name_module/$template.php + * @param string $module_theme If the view are on a different theme and you don't want put the view on the theme, use this variable for go to the other theme. + */ + + function load_view($arr_template_values_values, $template) + { + + //First see in controller/view/template, if not see in /views/template + + $yes_cache=0; + + if(!isset($this->cache_template[$template])) + { + + foreach($this->folder_env as $base_path) + { + + $view_path=$this->root_path.'/'.$base_path.'/'.$template.'.php'; + + if(is_file($view_path)) + { + + include($view_path); + + $yes_cache=1; + + break; + + } + + } + + //Search view first on an theme + + /*$theme_view=$this->root_path.$container_theme.'views/'.$theme.'/'.strtolower($template).'.php'; + + //Search view on the real module + + $script_module_view=$this->root_path.'modules/'.$this->script_module.'/views/'.strtolower($template).'.php'; + + //Search view on other module specified. + + $module_view=$this->root_path.'modules/'.$module_theme.'/views/'.strtolower($template).'.php';*/ + + /*if(!is_file($theme_view)) + { + + if(!is_file($script_module_view)) + { + + if(!is_file($module_view)) + { + + $output=ob_get_contents(); + + ob_clean(); + + $check_error_lang[0]='Error while loading template, check that the view exists...'; + $check_error_lang[1]='Error while loading template library '.$template.' in path '.$theme_view.' ,'.$script_module_view.' and '.$module_view.', check config.php or that template library exists... '; + + show_error($check_error_lang[0], $check_error_lang[1], $output); + + ob_end_flush(); + + die; + + } + else + { + + include($module_view); + + } + + } + else + { + + include($script_module_view); + + } + + } + else + { + + include($theme_view); + + }*/ + + //If load view, save function name for call write the html again without call include view too + + if($yes_cache==1) + { + + $this->cache_template[$template]=basename($template).'View'; + + } + else + { + + throw new \Exception('Error: view not found: '.$view_path); + die; + + } + + } + + ob_start(); + + $func_view=$this->cache_template[$template]; + + //Load function from loaded view with his parameters + + call_user_func_array($func_view, $arr_template_values); + + $out_template=ob_get_contents(); + + ob_end_clean(); + + return $out_template; + + } + + +} + +?> \ No newline at end of file From 153927546886cacb36669951336d471cc5849990 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 20 Apr 2015 04:31:09 +0200 Subject: [PATCH 03/43] Fixes on view --- src/View.php | 306 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 247 insertions(+), 59 deletions(-) diff --git a/src/View.php b/src/View.php index c58c89f..0dd16cb 100644 --- a/src/View.php +++ b/src/View.php @@ -1,6 +1,7 @@ tag. For example, a view that need a initialitation code in the principal view can use this array and you can insert the code in principal View using loadHeader method for load all header code writed in the array by children views. + */ + + public $header=array(); + /** * The construct for create a view object * @@ -54,7 +103,7 @@ class View { * @param string $module_theme If the view are on a different theme and you don't want put the view on the theme, use this variable for go to the other theme. */ - function load_view($arr_template_values_values, $template) + public function loadView($arr_template_values, $template) { //First see in controller/view/template, if not see in /views/template @@ -82,64 +131,6 @@ class View { } - //Search view first on an theme - - /*$theme_view=$this->root_path.$container_theme.'views/'.$theme.'/'.strtolower($template).'.php'; - - //Search view on the real module - - $script_module_view=$this->root_path.'modules/'.$this->script_module.'/views/'.strtolower($template).'.php'; - - //Search view on other module specified. - - $module_view=$this->root_path.'modules/'.$module_theme.'/views/'.strtolower($template).'.php';*/ - - /*if(!is_file($theme_view)) - { - - if(!is_file($script_module_view)) - { - - if(!is_file($module_view)) - { - - $output=ob_get_contents(); - - ob_clean(); - - $check_error_lang[0]='Error while loading template, check that the view exists...'; - $check_error_lang[1]='Error while loading template library '.$template.' in path '.$theme_view.' ,'.$script_module_view.' and '.$module_view.', check config.php or that template library exists... '; - - show_error($check_error_lang[0], $check_error_lang[1], $output); - - ob_end_flush(); - - die; - - } - else - { - - include($module_view); - - } - - } - else - { - - include($script_module_view); - - } - - } - else - { - - include($theme_view); - - }*/ - //If load view, save function name for call write the html again without call include view too if($yes_cache==1) @@ -163,6 +154,8 @@ class View { $func_view=$this->cache_template[$template]; //Load function from loaded view with his parameters + + array_unshift($arr_template_values, $this); call_user_func_array($func_view, $arr_template_values); @@ -174,6 +167,201 @@ class View { } + /** + * + */ + + public function dynamicGetMediaUrl($path_file) + { + + return $this->php_file.'/'.$path_file; + + } + + /** + * + */ + + public function staticGetMediaUrl($path_file) + { + + return $this->url_media.'/'.$path_file; + + } + + /** + * + */ + + public function setProduction($value=1) + { + + if($value==1) + { + + $production=1; + $this->func_media='staticGetMediaUrl'; + + } + else + { + + $production=0; + + $this->func_media='dynamicGetMediaUrl'; + + } + + } + + /** + * + */ + + public function getMediaUrl($path_file) + { + + $func_media=$this->func_media; + + return $this->$func_media($path_file); + + } + + /** + * Method for load media files. Method for load simple media file, is only for development + * + * This method is used on php files for retrieve media files using a very simple url dispatcher. + * + * @warning NO USE THIS METHOD IN PRODUCTION. + * + */ + + public function loadMediaFile($url) + { + + //Check files origin. + + if($this->production==0) + { + + $yes_file=0; + + $arr_url=explode($this->php_file.'/', $url); + + $final_path=''; + + if(isset($arr_url[1])) + { + + //Clean the path of undesirerable elements. + + $arr_path=explode('/', $arr_url[1]); + + $c=count($arr_path)-1; + + //foreach($arr_path as $key_path => $item_path) + for($x=0;$x<$c-1;$x++) + { + + $arr_path[$key_path]=Utils::slugify($item_path, $respect_upper=0, $replace_space='-', $replace_dot=1, $replace_barr=1); + + } + + $arr_path[$c]=Utils::slugify($arr_path[$c], $respect_upper=1, $replace_space='-', $replace_dot=0, $replace_barr=1); + + $final_path=implode('/', $arr_path); + + + } + + foreach($this->folder_env as $folder) + { + + $file_path=$this->root_path.'/'.$folder.'/'.$this->path_media.'/'.$final_path; + + if(is_file($file_path)) + { + $yes_file=1; + + break; + + } + + } + + if($yes_file==1) + { + + $ext_info=pathinfo($file_path); + + settype($ext_info['extension'], 'string'); + + switch($ext_info['extension']) + { + + default: + + $type_mime='text/plain'; + + break; + + case 'js': + + $type_mime='application/javascript'; + + break; + + case 'css': + + $type_mime='text/css'; + + break; + + case 'gif': + + $type_mime='image/gif'; + + break; + + case 'png': + + $type_mime='image/png'; + + break; + + case 'jpg': + + $type_mime='image/jpg'; + + break; + + } + + + + header('Content-Type: '.$type_mime); + + readfile($file_path); + + die; + + + } + else + { + + header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found"); + + echo 'File not found...'; + + die; + + } + + } + + } + } From d81acb46c78cefe28929b3068d09c7f2532b0308 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 20 Apr 2015 17:54:32 +0200 Subject: [PATCH 04/43] Fixes on view --- src/View.php | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 0dd16cb..5f50198 100644 --- a/src/View.php +++ b/src/View.php @@ -215,7 +215,8 @@ class View { } /** - * + * Method for obtain a url for a media file. + * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ public function getMediaUrl($path_file) @@ -362,6 +363,73 @@ class View { } + /** + * Method that use $this->css array for create a series of html tags that load the css stylesheets + * + * This function is used inside of html tag normally for load css files. + */ + + public function loadCSS() + { + + $arr_final_css=array(); + + foreach($this->css as $css) + { + $url=$this->getMediaUrl('css/'.$css); + + $arr_final_css[]=''."\n"; + + } + + return implode('', $arr_final_css); + + } + + /** + * Method that use $this->js array for create a series of html tags that load the javascript files + * + * This function is used inside of html tag normally for load js files. + */ + + public function loadJS() + { + + $arr_final_js=array(); + + foreach($this->js as $js) + { + $url=$this->getMediaUrl('js/'.$js); + + $arr_final_js[]=$arr_final_jscript[]=''."\n";; + + } + + return implode('', $arr_final_js); + + } + + /** + * Method that use $this->header array for create a series of code (normally javascript) on tag. + * + * This function is used inside of html tag normally for load inline javascript code. + */ + + public function loadHeader() + { + + $arr_final_header=array(); + + foreach($this->header as $header) + { + + $arr_final_header[]=$header."\n"; + + } + + return implode('', $arr_final_header); + + } } From 234c70d317816a406989e9b6c015a6b4c3b9c22f Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 20 Apr 2015 18:00:53 +0200 Subject: [PATCH 05/43] Added documentation in code --- src/View.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/View.php b/src/View.php index 5f50198..86efae0 100644 --- a/src/View.php +++ b/src/View.php @@ -168,7 +168,9 @@ class View { } /** + * Method for create a url for access files via .php script * + * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ public function dynamicGetMediaUrl($path_file) @@ -179,6 +181,9 @@ class View { } /** + * Method for create a url for access files via http server + * + * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media * */ @@ -190,7 +195,9 @@ class View { } /** + * Method for change the method for access to media files. * + * @param boolean $value Set the production property.If true then access to media files directly, if false, access to media files via specified .php script */ public function setProduction($value=1) From 6d8550a1bbdbbd16014ccf2e1294d25aba4a0af4 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 21 Apr 2015 04:25:21 +0200 Subject: [PATCH 06/43] Fixes for psr-4 standard --- composer.json | 2 +- src/View.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index c03ded6..fd462e3 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": {}, "autoload": { "psr-4": { - "PhaRouter\\": "src" + "PhangoApp\\PhaRouter\\": "src" } } } diff --git a/src/View.php b/src/View.php index 86efae0..f2ef7a7 100644 --- a/src/View.php +++ b/src/View.php @@ -1,7 +1,7 @@ Date: Fri, 24 Apr 2015 04:47:02 +0200 Subject: [PATCH 07/43] Fixes for the new behaviour --- src/View.php | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/View.php b/src/View.php index f2ef7a7..73bebec 100644 --- a/src/View.php +++ b/src/View.php @@ -9,37 +9,37 @@ class View { * Root path for includes app folders */ - public $root_path=__DIR__; + static public $root_path=__DIR__; /** * A set of paths inside of $root_path contining views. If a view is located, the foreach for search the view is break */ - public $folder_env=array('views/default', 'app/views'); + static public $folder_env=array('views/default', 'app/views'); /** * Array for caching the template call... */ - public $cache_template=array(); + static public $cache_template=array(); /** * Path of static media files (javascript, images and css). */ - public $path_media='media'; + static public $path_media='media'; /** * Url of static media files (javascript, images and css). */ - public $url_media='media'; + static public $url_media='media'; /** * Media .php path. */ - public $php_file='showmedia.php'; + static public $php_file='showmedia.php'; /** * Internal property used for see if this media are in production @@ -51,7 +51,7 @@ class View { * Internal property used for define the method used for retrieve the media files. */ - protected $func_media='dynamicGetMediaUrl'; + static protected $func_media='dynamicGetMediaUrl'; /** * An array where you can add new css in all views. For example, a view that use a special css can use this array and you can insert the value 'special.css' and the principal View can use loadCss method for load all css writed in the array by children views. @@ -85,11 +85,11 @@ class View { if(count($arr_arg)>0) { - $this->folder_env=$arr_arg; + View::$folder_env=$arr_arg; } - $this->root_path=getcwd(); + View::$root_path=getcwd(); } @@ -110,13 +110,13 @@ class View { $yes_cache=0; - if(!isset($this->cache_template[$template])) + if(!isset(View::$cache_template[$template])) { - foreach($this->folder_env as $base_path) + foreach(View::$folder_env as $base_path) { - $view_path=$this->root_path.'/'.$base_path.'/'.$template.'.php'; + $view_path=View::$root_path.'/'.$base_path.'/'.$template.'.php'; if(is_file($view_path)) { @@ -136,7 +136,7 @@ class View { if($yes_cache==1) { - $this->cache_template[$template]=basename($template).'View'; + View::$cache_template[$template]=basename($template).'View'; } else @@ -151,7 +151,7 @@ class View { ob_start(); - $func_view=$this->cache_template[$template]; + $func_view=View::$cache_template[$template]; //Load function from loaded view with his parameters @@ -176,7 +176,7 @@ class View { public function dynamicGetMediaUrl($path_file) { - return $this->php_file.'/'.$path_file; + return View::$php_file.'/'.$path_file; } @@ -190,7 +190,7 @@ class View { public function staticGetMediaUrl($path_file) { - return $this->url_media.'/'.$path_file; + return View::$url_media.'/'.$path_file; } @@ -200,14 +200,14 @@ class View { * @param boolean $value Set the production property.If true then access to media files directly, if false, access to media files via specified .php script */ - public function setProduction($value=1) + static public function setProduction($value=1) { if($value==1) { $production=1; - $this->func_media='staticGetMediaUrl'; + View::$func_media='staticGetMediaUrl'; } else @@ -215,7 +215,7 @@ class View { $production=0; - $this->func_media='dynamicGetMediaUrl'; + View::$func_media='dynamicGetMediaUrl'; } @@ -229,7 +229,7 @@ class View { public function getMediaUrl($path_file) { - $func_media=$this->func_media; + $func_media=View::$func_media; return $this->$func_media($path_file); @@ -254,7 +254,7 @@ class View { $yes_file=0; - $arr_url=explode($this->php_file.'/', $url); + $arr_url=explode(View::$php_file.'/', $url); $final_path=''; @@ -282,10 +282,10 @@ class View { } - foreach($this->folder_env as $folder) + foreach(View::$folder_env as $folder) { - $file_path=$this->root_path.'/'.$folder.'/'.$this->path_media.'/'.$final_path; + $file_path=View::$root_path.'/'.$folder.'/'.View::$path_media.'/'.$final_path; if(is_file($file_path)) { From 0c317280185be709b0ec2942b62a98ca5c21b8da Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 26 Apr 2015 17:54:17 +0200 Subject: [PATCH 08/43] Fix on composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index fd462e3..021c805 100644 --- a/composer.json +++ b/composer.json @@ -16,7 +16,7 @@ "require": {}, "autoload": { "psr-4": { - "PhangoApp\\PhaRouter\\": "src" + "PhangoApp\\PhaView\\": "src" } } } From 72a2bdab45556d0d4be2f9e7aca334bb20586c05 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 28 Apr 2015 16:14:32 +0200 Subject: [PATCH 09/43] Fixes on View --- src/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 73bebec..5984f4b 100644 --- a/src/View.php +++ b/src/View.php @@ -15,7 +15,7 @@ class View { * A set of paths inside of $root_path contining views. If a view is located, the foreach for search the view is break */ - static public $folder_env=array('views/default', 'app/views'); + static public $folder_env=array('views/default'); /** * Array for caching the template call... From 083ac7e20212a5382d14b24057b6ad1b271e3a85 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Fri, 8 May 2015 05:23:49 +0200 Subject: [PATCH 10/43] Fixes on views --- src/View.php | 56 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/src/View.php b/src/View.php index 5984f4b..360ffec 100644 --- a/src/View.php +++ b/src/View.php @@ -45,7 +45,7 @@ class View { * Internal property used for see if this media are in production */ - protected $production=0; + static protected $production=0; /** * Internal property used for define the method used for retrieve the media files. @@ -57,19 +57,19 @@ class View { * An array where you can add new css in all views. For example, a view that use a special css can use this array and you can insert the value 'special.css' and the principal View can use loadCss method for load all css writed in the array by children views. */ - public $css=array(); + static public $css=array(); /** * An array where you can add new js in all views. For example, a view that use a special js can use this array and you can insert the value 'special.js' in principal View using loadJs method for load all js writed in the array by children views. */ - public $js=array(); + static public $js=array(); /** * An array where you can add new code in
tag. For example, a view that need a initialitation code in the principal view can use this array and you can insert the code in principal View using loadHeader method for load all header code writed in the array by children views. */ - public $header=array(); + static public $header=array(); /** * The construct for create a view object @@ -77,7 +77,7 @@ class View { * @param string $folder_base The folder used how base path for search view files */ - public function __construct() + /*public function __construct() { $arr_arg=func_get_args(); @@ -91,7 +91,7 @@ class View { View::$root_path=getcwd(); - } + }*/ /** * Very important function used for load views. Is the V in the MVC paradigm. Phango is an MVC framework and has separate code and html. @@ -103,7 +103,7 @@ class View { * @param string $module_theme If the view are on a different theme and you don't want put the view on the theme, use this variable for go to the other theme. */ - public function loadView($arr_template_values, $template) + static public function loadView($arr_template_values, $template) { //First see in controller/view/template, if not see in /views/template @@ -155,7 +155,7 @@ class View { //Load function from loaded view with his parameters - array_unshift($arr_template_values, $this); + //array_unshift($arr_template_values, $this); call_user_func_array($func_view, $arr_template_values); @@ -173,7 +173,7 @@ class View { * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - public function dynamicGetMediaUrl($path_file) + static public function dynamicGetMediaUrl($path_file) { return View::$php_file.'/'.$path_file; @@ -187,7 +187,7 @@ class View { * */ - public function staticGetMediaUrl($path_file) + static public function staticGetMediaUrl($path_file) { return View::$url_media.'/'.$path_file; @@ -226,12 +226,12 @@ class View { * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - public function getMediaUrl($path_file) + static public function getMediaUrl($path_file) { $func_media=View::$func_media; - return $this->$func_media($path_file); + return View::$func_media($path_file); } @@ -244,12 +244,12 @@ class View { * */ - public function loadMediaFile($url) + static public function loadMediaFile($url) { //Check files origin. - if($this->production==0) + if(View::$production==0) { $yes_file=0; @@ -376,14 +376,14 @@ class View { * This function is used inside of html tag normally for load css files. */ - public function loadCSS() + static public function loadCSS() { $arr_final_css=array(); - foreach($this->css as $css) + foreach(View::$css as $css) { - $url=$this->getMediaUrl('css/'.$css); + $url=View::getMediaUrl('css/'.$css); $arr_final_css[]=''."\n"; @@ -399,14 +399,14 @@ class View { * This function is used inside of html tag normally for load js files. */ - public function loadJS() + static public function loadJS() { $arr_final_js=array(); - foreach($this->js as $js) + foreach(View::$js as $js) { - $url=$this->getMediaUrl('js/'.$js); + $url=View::getMediaUrl('js/'.$js); $arr_final_js[]=$arr_final_jscript[]=''."\n";; @@ -422,12 +422,12 @@ class View { * This function is used inside of html tag normally for load inline javascript code. */ - public function loadHeader() + static public function loadHeader() { $arr_final_header=array(); - foreach($this->header as $header) + foreach(View::$header as $header) { $arr_final_header[]=$header."\n"; @@ -438,6 +438,18 @@ class View { } + /** + * A method for make a redirect based on a theme + * + */ + + static public function loadTheme($title, $cont_index) + { + + echo View::loadView(array($title, $cont_index),'home'); + + } + } ?> \ No newline at end of file From 92e4e9134cf31909b4d9b34b35376ff4100d3ee7 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 11 May 2015 01:27:07 +0200 Subject: [PATCH 11/43] Fixes --- src/View.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 360ffec..6a44d3f 100644 --- a/src/View.php +++ b/src/View.php @@ -271,7 +271,7 @@ class View { for($x=0;$x<$c-1;$x++) { - $arr_path[$key_path]=Utils::slugify($item_path, $respect_upper=0, $replace_space='-', $replace_dot=1, $replace_barr=1); + $arr_path[$x]=Utils::slugify($arr_path[$x], $respect_upper=0, $replace_space='-', $replace_dot=1, $replace_barr=1); } @@ -289,6 +289,7 @@ class View { if(is_file($file_path)) { + $yes_file=1; break; From 12f00ab1511ff4978128e2908d0282285789cd43 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 11 May 2015 04:10:42 +0200 Subject: [PATCH 12/43] Fixes on view --- src/View.php | 100 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/src/View.php b/src/View.php index 6a44d3f..d2891b2 100644 --- a/src/View.php +++ b/src/View.php @@ -382,6 +382,8 @@ class View { $arr_final_css=array(); + View::$css=array_unique(View::$css); + foreach(View::$css as $css) { $url=View::getMediaUrl('css/'.$css); @@ -404,6 +406,8 @@ class View { { $arr_final_js=array(); + + View::$js=array_unique(View::$js); foreach(View::$js as $js) { @@ -427,7 +431,7 @@ class View { { $arr_final_header=array(); - + foreach(View::$header as $header) { @@ -435,7 +439,7 @@ class View { } - return implode('', $arr_final_header); + return implode("\n", $arr_final_header); } @@ -451,6 +455,98 @@ class View { } + /** + * Function for load multiple views for a only source file. + * + * Useful for functions where you need separated views for use on something, When you use load_view for execute a view function, the names used for views are in $func_views array. + * + * @param string $template of the view library. Use the same format for normal views. + * @param string The names of templates, used how template_name for call views with load_view. + */ + + static public function loadLibrariesViews($template, $func_views=array()) + { + + foreach(View::$folder_env as $base_path) + { + + $view_path=View::$root_path.'/'.$base_path.'/'.$template.'.php'; + + if(is_file($view_path)) + { + + include($view_path); + + foreach($func_views as $template) + { + + View::$cache_template[$template]=basename($template).'View'; + + } + + break; + + } + + } + + /*$theme=PhangoVar::$dir_theme; + + $container_theme=PhangoVar::$module_theme; + + $view=''; + + //Load views from a source file... + + //Check func views... + + $no_loaded=0; + + foreach($func_views as $template_check) + { + + if(isset(PhangoVar::$cache_template[$template_check])) + { + //Function view loaded, return because load_view load the function automatically. + + $no_loaded++; + + } + + } + + if($no_loaded==0) + { + if(!include_once(PhangoVar::$base_path.$container_theme.'views/'.$theme.'/'.strtolower($template).'.php')) + { + + $output_error_view=ob_get_contents(); + + ob_clean(); + + if(!include_once(PhangoVar::$base_path.'modules/'.PhangoVar::$script_module.'/views/'.strtolower($template).'.php')) + { + + + + } + + } + + } + + //Forever register views if the code use different functions in a same library. + + foreach($func_views as $template) + { + + PhangoVar::$cache_template[$template]=basename($template).'View'; + + }*/ + + + } + } ?> \ No newline at end of file From fb64d50a0ed13138ec20b3217ca08620f3eea94e Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 12 May 2015 02:47:09 +0200 Subject: [PATCH 13/43] Fix on variables --- src/View.php | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/View.php b/src/View.php index d2891b2..6570b41 100644 --- a/src/View.php +++ b/src/View.php @@ -547,6 +547,30 @@ class View { } + static public function set_flash($text) + { + + $_SESSION['flash_txt']=$text; + + } + + static public function show_flash() + { + + if(isset($_SESSION['flash_txt'])) + { + if($_SESSION['flash_txt']!='') + { + + return View::loadView(array($_SESSION['flash_txt']), 'flash'); + + } + } + + return ''; + + } + } ?> \ No newline at end of file From 5948fe2c79cfb3c23c7a18302442c8f772c9d304 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 14 May 2015 17:34:32 +0200 Subject: [PATCH 14/43] Fixes --- src/View.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 6570b41..9069cb3 100644 --- a/src/View.php +++ b/src/View.php @@ -561,8 +561,11 @@ class View { { if($_SESSION['flash_txt']!='') { + $text=$_SESSION['flash_txt']; + + $_SESSION['flash_txt']=''; - return View::loadView(array($_SESSION['flash_txt']), 'flash'); + return View::loadView(array($text), 'common/utilities/flash'); } } From c43245ecdc113b55434f262a8a60ea14caafdd21 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 14 Jun 2015 17:16:01 +0200 Subject: [PATCH 15/43] Fixes --- src/View.php | 60 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 7 deletions(-) diff --git a/src/View.php b/src/View.php index 9069cb3..06ef729 100644 --- a/src/View.php +++ b/src/View.php @@ -110,6 +110,8 @@ class View { $yes_cache=0; + $all_path=array(); + if(!isset(View::$cache_template[$template])) { @@ -118,6 +120,8 @@ class View { $view_path=View::$root_path.'/'.$base_path.'/'.$template.'.php'; + $all_path[]=$view_path; + if(is_file($view_path)) { @@ -142,7 +146,7 @@ class View { else { - throw new \Exception('Error: view not found: '.$view_path); + throw new \Exception('Error: view not found: '.implode(' and ', $all_path)); die; } @@ -167,6 +171,17 @@ class View { } + /** + * Simple alias of load_view + */ + + static public function load_view($arr_template_values, $template) + { + + return View::loadView($arr_template_values, $template); + + } + /** * Method for create a url for access files via .php script * @@ -382,13 +397,34 @@ class View { $arr_final_css=array(); - View::$css=array_unique(View::$css); + //View::$css=array_unique(View::$css); foreach(View::$css as $css) { - $url=View::getMediaUrl('css/'.$css); + + if(gettype($css)=='array') + { + + $css=array_unique($css); + + foreach($css as $module => $css_item) + { + + $url=View::getMediaUrl('css/'.$css); + + $arr_final_css[]=''."\n"; + + } + + } + else + { - $arr_final_css[]=''."\n"; + $url=View::getMediaUrl('css/'.$css); + + $arr_final_css[]=''."\n"; + + } } @@ -407,13 +443,23 @@ class View { $arr_final_js=array(); - View::$js=array_unique(View::$js); + //View::$js=array_unique(View::$js); foreach(View::$js as $js) { - $url=View::getMediaUrl('js/'.$js); - $arr_final_js[]=$arr_final_jscript[]=''."\n";; + if(gettype($js)=='array') + { + + } + else + { + + $url=View::getMediaUrl('js/'.$js); + + $arr_final_js[]=$arr_final_jscript[]=''."\n";; + + } } From 2fb3fe49559a83d880d8a2354c5311eea782e05f Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sun, 14 Jun 2015 23:04:03 +0200 Subject: [PATCH 16/43] Fixes on view --- src/View.php | 103 ++++++++++----------------------------------------- 1 file changed, 19 insertions(+), 84 deletions(-) diff --git a/src/View.php b/src/View.php index 06ef729..7ce2a62 100644 --- a/src/View.php +++ b/src/View.php @@ -51,7 +51,7 @@ class View { * Internal property used for define the method used for retrieve the media files. */ - static protected $func_media='dynamicGetMediaUrl'; + static protected $func_media='dynamic_get_media_url'; /** * An array where you can add new css in all views. For example, a view that use a special css can use this array and you can insert the value 'special.css' and the principal View can use loadCss method for load all css writed in the array by children views. @@ -103,7 +103,7 @@ class View { * @param string $module_theme If the view are on a different theme and you don't want put the view on the theme, use this variable for go to the other theme. */ - static public function loadView($arr_template_values, $template) + static public function load_view($arr_template_values, $template) { //First see in controller/view/template, if not see in /views/template @@ -171,24 +171,13 @@ class View { } - /** - * Simple alias of load_view - */ - - static public function load_view($arr_template_values, $template) - { - - return View::loadView($arr_template_values, $template); - - } - /** * Method for create a url for access files via .php script * * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - static public function dynamicGetMediaUrl($path_file) + static public function dynamic_get_media_url($path_file) { return View::$php_file.'/'.$path_file; @@ -202,7 +191,7 @@ class View { * */ - static public function staticGetMediaUrl($path_file) + static public function static_get_media_url($path_file) { return View::$url_media.'/'.$path_file; @@ -215,14 +204,14 @@ class View { * @param boolean $value Set the production property.If true then access to media files directly, if false, access to media files via specified .php script */ - static public function setProduction($value=1) + static public function set_production($value=1) { if($value==1) { $production=1; - View::$func_media='staticGetMediaUrl'; + View::$func_media='static_get_media_url'; } else @@ -230,7 +219,7 @@ class View { $production=0; - View::$func_media='dynamicGetMediaUrl'; + View::$func_media='dynamic_get_media_url'; } @@ -241,7 +230,7 @@ class View { * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - static public function getMediaUrl($path_file) + static public function get_media_url($path_file) { $func_media=View::$func_media; @@ -259,7 +248,7 @@ class View { * */ - static public function loadMediaFile($url) + static public function load_media_file($url) { //Check files origin. @@ -392,7 +381,7 @@ class View { * This function is used inside of html tag normally for load css files. */ - static public function loadCSS() + static public function load_css() { $arr_final_css=array(); @@ -410,7 +399,7 @@ class View { foreach($css as $module => $css_item) { - $url=View::getMediaUrl('css/'.$css); + $url=View::get_media_url('css/'.$css); $arr_final_css[]=''."\n"; @@ -420,7 +409,7 @@ class View { else { - $url=View::getMediaUrl('css/'.$css); + $url=View::get_media_url('css/'.$css); $arr_final_css[]=''."\n"; @@ -438,7 +427,7 @@ class View { * This function is used inside of html tag normally for load js files. */ - static public function loadJS() + static public function load_js() { $arr_final_js=array(); @@ -455,7 +444,7 @@ class View { else { - $url=View::getMediaUrl('js/'.$js); + $url=View::get_media_url('js/'.$js); $arr_final_js[]=$arr_final_jscript[]=''."\n";; @@ -473,7 +462,7 @@ class View { * This function is used inside of html tag normally for load inline javascript code. */ - static public function loadHeader() + static public function load_header() { $arr_final_header=array(); @@ -494,10 +483,10 @@ class View { * */ - static public function loadTheme($title, $cont_index) + static public function load_theme($title, $cont_index) { - echo View::loadView(array($title, $cont_index),'home'); + echo View::load_view(array($title, $cont_index),'home'); } @@ -510,7 +499,7 @@ class View { * @param string The names of templates, used how template_name for call views with load_view. */ - static public function loadLibrariesViews($template, $func_views=array()) + static public function load_libraries_views($template, $func_views=array()) { foreach(View::$folder_env as $base_path) @@ -535,60 +524,6 @@ class View { } } - - /*$theme=PhangoVar::$dir_theme; - - $container_theme=PhangoVar::$module_theme; - - $view=''; - - //Load views from a source file... - - //Check func views... - - $no_loaded=0; - - foreach($func_views as $template_check) - { - - if(isset(PhangoVar::$cache_template[$template_check])) - { - //Function view loaded, return because load_view load the function automatically. - - $no_loaded++; - - } - - } - - if($no_loaded==0) - { - if(!include_once(PhangoVar::$base_path.$container_theme.'views/'.$theme.'/'.strtolower($template).'.php')) - { - - $output_error_view=ob_get_contents(); - - ob_clean(); - - if(!include_once(PhangoVar::$base_path.'modules/'.PhangoVar::$script_module.'/views/'.strtolower($template).'.php')) - { - - - - } - - } - - } - - //Forever register views if the code use different functions in a same library. - - foreach($func_views as $template) - { - - PhangoVar::$cache_template[$template]=basename($template).'View'; - - }*/ } @@ -611,7 +546,7 @@ class View { $_SESSION['flash_txt']=''; - return View::loadView(array($text), 'common/utilities/flash'); + return View::load_view(array($text), 'common/utilities/flash'); } } From f01c99efc4aa5be60a90f4d1fb9c4cd582254ab9 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 29 Jun 2015 15:10:40 +0200 Subject: [PATCH 17/43] Fixes on view --- src/View.php | 54 +++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 43 insertions(+), 11 deletions(-) diff --git a/src/View.php b/src/View.php index 7ce2a62..76964de 100644 --- a/src/View.php +++ b/src/View.php @@ -17,6 +17,18 @@ class View { static public $folder_env=array('views/default'); + /** + * A set of paths inside of $root_path contining views. If a view is located, the foreach for search the view is break + */ + + static public $media_env=array('views/default'); + + /** + * Basepath of the theme + */ + + static public $theme=''; + /** * Array for caching the template call... */ @@ -191,10 +203,19 @@ class View { * */ - static public function static_get_media_url($path_file) + static public function static_get_media_url($path_file, $module='') { - - return View::$url_media.'/'.$path_file; + + //Need that the paths was theme/media and theme/module/media + + if($module!='') + { + + $module.='/'; + + } + + return View::$url_media.'media/'.View::$theme.'/'.$module.$path_file; } @@ -230,12 +251,12 @@ class View { * @param string $path_file The relative path of file with respect to $folder_end.'/'.$path_media */ - static public function get_media_url($path_file) + static public function get_media_url($path_file, $module='') { - + $func_media=View::$func_media; - return View::$func_media($path_file); + return View::$func_media($path_file, $module); } @@ -286,7 +307,7 @@ class View { } - foreach(View::$folder_env as $folder) + foreach(View::$media_env as $folder) { $file_path=View::$root_path.'/'.$folder.'/'.View::$path_media.'/'.$final_path; @@ -388,7 +409,7 @@ class View { //View::$css=array_unique(View::$css); - foreach(View::$css as $css) + foreach(View::$css as $module_css => $css) { if(gettype($css)=='array') @@ -399,7 +420,7 @@ class View { foreach($css as $module => $css_item) { - $url=View::get_media_url('css/'.$css); + $url=View::get_media_url('css/'.$css_item, $module_css); $arr_final_css[]=''."\n"; @@ -434,11 +455,22 @@ class View { //View::$js=array_unique(View::$js); - foreach(View::$js as $js) + foreach(View::$js as $module_js => $js) { if(gettype($js)=='array') { + + $js=array_unique($js); + + foreach($js as $module => $js_item) + { + + $url=View::get_media_url('js/'.$js_item, $module_js); + + $arr_final_js[]=$arr_final_jscript[]=''."\n"; + + } } else @@ -446,7 +478,7 @@ class View { $url=View::get_media_url('js/'.$js); - $arr_final_js[]=$arr_final_jscript[]=''."\n";; + $arr_final_js[]=$arr_final_jscript[]=''."\n"; } From fe2d66792ce2e08fe906dffbf9850836c1e17f8b Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Wed, 8 Jul 2015 04:33:22 +0200 Subject: [PATCH 18/43] Fixes on views --- src/View.php | 82 ++++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/src/View.php b/src/View.php index 76964de..9cb9ca0 100644 --- a/src/View.php +++ b/src/View.php @@ -71,12 +71,24 @@ class View { static public $css=array(); + /** + * An array where you can add new css in all views from modules. For example, a view that use a special css can use this array and you can insert the value 'special.css' and the principal View can use load_css method for load all css writed in the array by children views. + */ + + static public $css_module=array(); + /** * An array where you can add new js in all views. For example, a view that use a special js can use this array and you can insert the value 'special.js' in principal View using loadJs method for load all js writed in the array by children views. */ static public $js=array(); + /** + * An array where you can add new js in all views. For example, a view that use a special js can use this array and you can insert the value 'special.js' in principal View using load_js method for load all js writed in the array by children views. + */ + + static public $js_module=array(); + /** * An array where you can add new code in
tag. For example, a view that need a initialitation code in the principal view can use this array and you can insert the code in principal View using loadHeader method for load all header code writed in the array by children views. */ @@ -407,35 +419,29 @@ class View { $arr_final_css=array(); - //View::$css=array_unique(View::$css); + View::$css=array_unique(View::$css); - foreach(View::$css as $module_css => $css) + foreach(View::$css as $css) { - if(gettype($css)=='array') - { - - $css=array_unique($css); - - foreach($css as $module => $css_item) - { - - $url=View::get_media_url('css/'.$css_item, $module_css); - - $arr_final_css[]=''."\n"; - - } - - } - else - { + $url=View::get_media_url('css/'.$css); - $url=View::get_media_url('css/'.$css); + $arr_final_css[]=''."\n"; + + } + + foreach(View::$css_module as $module_css => $css) + { + $css=array_unique($css); + + foreach($css as $module => $css_item) + { + + $url=View::get_media_url('css/'.$css_item, $module_css); $arr_final_css[]=''."\n"; } - } return implode('', $arr_final_css); @@ -453,35 +459,29 @@ class View { $arr_final_js=array(); - //View::$js=array_unique(View::$js); + View::$js=array_unique(View::$js); foreach(View::$js as $module_js => $js) { - if(gettype($js)=='array') + $url=View::get_media_url('js/'.$js); + + $arr_final_js[]=$arr_final_jscript[]=''."\n"; + + } + + foreach(View::$js_module as $module_js => $js) + { + $js=array_unique($js); + + foreach($js as $module => $js_item) { - $js=array_unique($js); + $url=View::get_media_url('js/'.$js_item, $module_js); - foreach($js as $module => $js_item) - { - - $url=View::get_media_url('js/'.$js_item, $module_js); - - $arr_final_js[]=$arr_final_jscript[]=''."\n"; - - } + $arr_final_js[]=''."\n"; } - else - { - - $url=View::get_media_url('js/'.$js); - - $arr_final_js[]=$arr_final_jscript[]=''."\n"; - - } - } return implode('', $arr_final_js); From fe66a759d5ef0212cfd4873091dd83926a2f0dfd Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 18 Aug 2015 01:44:38 +0200 Subject: [PATCH 19/43] Added padmin how bin file --- bin/padmin | 472 +++++++++++++++++++++++++++++++++++++++++ bin/padmin.php | 536 ----------------------------------------------- composer.json | 3 +- src/Webmodel.php | 20 +- 4 files changed, 481 insertions(+), 550 deletions(-) create mode 100755 bin/padmin delete mode 100644 bin/padmin.php diff --git a/bin/padmin b/bin/padmin new file mode 100755 index 0000000..b66d9a1 --- /dev/null +++ b/bin/padmin @@ -0,0 +1,472 @@ +#!/usr/bin/php +white()->backgroundBlack()->out("Use: padmin --model=module/model"); + + die; + + } + + $arr_option=explode('/', $options['model']); + + settype($arr_option[0], 'string'); + settype($arr_option[1], 'string'); + + Webmodel::$model_path='./modules/'; + + $model_file=Webmodel::$model_path.$arr_option[0].'/models/models_'.$arr_option[1].'.php'; + + if(!is_file($model_file)) + { + + $climate->white()->backgroundRed()->out("Error: cannot find the model file in ".$arr_option[0]."/models/models_".$arr_option[1].".php"); + + die(); + + } + + + WebModel::load_model($options['model']); + + try { + + $first_item=current(Webmodel::$model); + + $first_item->connect_to_db(); + + } catch(Exception $e) + { + $climate->white()->backgroundRed()->out($e->getMessage()); + //echo $e->getMessage()."\n"; + die; + + } + + //print_r(get_declared_classes()); + + + + update_table(); + + $post_install_script=Webmodel::$model_path.$arr_option[0].'/install/post_install.php'; + + $post_install_lock=Webmodel::$model_path.$arr_option[0].'/install/lock'; + + if(file_exists($post_install_script) && !file_exists($post_install_lock)) + { + + //echo "Executing post_install script...\n"; + + $climate->white()->backgroundBlack()->out('Executing post_install script...'); + + include($post_install_script); + + if(post_install()) + { + + if(!file_put_contents($post_install_lock, 'installed')) + { + + //echo "Done, but cannot create this file: ".$arr_option[0].'/install/lock'.". Check your permissions and create the file if the script executed satisfally \n"; + $climate->white()->backgroundBlack()->out("Done, but cannot create this file: ".$arr_option[0].'/install/lock'.". Check your permissions and create the file if the script executed satisfally"); + + } + else + { + + //echo "Done\n"; + $climate->white()->backgroundBlack()->out('Done'); + + } + + } + else + { + + //echo "Error, please, check ${post_install_script} file and execute padmin.php again\n"; + $climate->white()->backgroundRed()->out("Error, please, check ${post_install_script} file and execute padmin.php again"); + + } + + } + + //echo "All things done\n"; + + $climate->white()->backgroundBlack()->out("All things done"); + +} + +/** +* This Function is used for padmin.php for create new tables and fields based in Webmodel class. +* +* @param Webmodel $model The model used for create or update a sql table. +*/ + +function update_table() +{ + //include(__DIR__.'/../src/Databases/'.Webmodel::$type_db.'.php'); + + Webmodel::$arr_sql_index=array(); + Webmodel::$arr_sql_set_index=array(); + + Webmodel::$arr_sql_unique=array(); + Webmodel::$arr_sql_set_unique=array(); + + $arr_etable=array(); + + $query=SQLClass::webtsys_query("show tables"); + + while(list($table)=SQLClass::webtsys_fetch_row($query)) + { + + $arr_etable[$table]=1; + + } + + foreach(Webmodel::$model as $key => $thing) + { + + $arr_table=array(); + + $allfields=array(); + $fields=array(); + $types=array(); + + $field=""; + $type=""; + $null=""; + $key_db=""; + $default=""; + $extra=""; + $key_field_old=Webmodel::$model[$key]->idmodel; + + if(!isset($arr_etable[$key])) + { + //If table not exists make this + + echo "Creating table $key\n"; + + Webmodel::$model[$key]->create_table(); + + } + else + if(isset(Webmodel::$model[$key])) + { + //Obtain all fields of model + + foreach(Webmodel::$model[$key]->components as $kfield => $value) + { + + $allfields[$kfield]=1; + + } + + //unset($allfields['Id'.ucfirst($key)]); + + $arr_null['NO']='NOT NULL'; + $arr_null['YES']='NULL'; + + unset($allfields[Webmodel::$model[$key]->idmodel]); + + $query=SQLClass::webtsys_query("describe `".$key."`"); + + list($key_field_old, $type, $null, $key_db, $default, $extra)=SQLClass::webtsys_fetch_row($query); + + while(list($field, $type, $null, $key_db, $default, $extra)=SQLClass::webtsys_fetch_row($query)) + { + + $fields[]=$field; + $types[$field]=$type; + $keys[$field]=$key_db; + + $null_set[$field]=$arr_null[$null]; + + } + + foreach($fields as $field) + { + + if(isset($allfields[$field])) + { + + $type=strtoupper($types[$field]); + + unset($allfields[$field]); + + if(Webmodel::$model[$key]->components[$field]->get_type_sql()!=($type.' '.$null_set[$field])) + { + + $query=SQLClass::webtsys_query('alter table `'.$key.'` modify `'.$field.'` '.Webmodel::$model[$key]->components[$field]->get_type_sql()); + + echo "Upgrading ".$field." from ".$key."...\n"; + + + } + + //Check if indexed + + if(Webmodel::$model[$key]->components[$field]->indexed==true && $keys[$field]=='') + { + + Webmodel::$arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON `'.$key.'`(`'.$field.'`);'; + Webmodel::$arr_sql_set_index[$key][$field]=''; + + } + + //Check if unique + + if(Webmodel::$model[$key]->components[$field]->unique==true && $keys[$field]=='') + { + + Webmodel::$arr_sql_unique[$key][$field]=' ALTER TABLE `'.$key.'` ADD UNIQUE (`'.$field.'`)'; + Webmodel::$arr_sql_set_unique[$key][$field]=''; + + } + + //Set index + + if(isset(Webmodel::$model[$key]->components[$field]->related_model) && $keys[$field]=='') + { + + + Webmodel::$arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON `'.$key.'`(`'.$field.'`);'; + + $table_related=Webmodel::$model[$key]->components[$field]->related_model->name; + + $id_table_related=Webmodel::load_id_model_related(Webmodel::$model[$key]->components[$field], $model); + + Webmodel::$arr_sql_set_index[$key][$field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$field.'_'.$key.'IDX` FOREIGN KEY ( `'.$field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;'; + + + } + + if(!isset(Webmodel::$model[$key]->components[$field]->related_model) && $keys[$field]!='' && Webmodel::$model[$key]->components[$field]->indexed==false && Webmodel::$model[$key]->components[$field]->unique!=true) + { + + echo "---Delete index for ".$field." from ".$key."\n"; + + $query=SQLClass::webtsys_query('DROP INDEX `index_'.$key.'_'.$field.'` ON '.$key); + + } + + } + + else + + { + + $allfields[$field]=0; + + } + + } + + } + + //Check if new id... + + if($key_field_old!=Webmodel::$model[$key]->idmodel) + { + + $query=SQLClass::webtsys_query('alter table `'.$key.'` change `'.$key_field_old.'` `'.Webmodel::$model[$key]->idmodel.'` INT NOT NULL AUTO_INCREMENT'); + + echo "Renaming id for this model to ".Webmodel::$model[$key]->idmodel."...\n"; + + } + + //Check if new fields... + + foreach($allfields as $new_field => $new) + { + + if($allfields[$new_field]==1) + { + + $query=SQLClass::webtsys_query('alter table `'.$key.'` add `'.$new_field.'` '.Webmodel::$model[$key]->components[$new_field]->get_type_sql()); + + echo "Adding ".$new_field." to ".$key."...\n"; + + //Check if indexed + + if(Webmodel::$model[$key]->components[$new_field]->indexed==true) + { + + Webmodel::$arr_sql_index[$key][$new_field]='CREATE INDEX `index_'.$key.'_'.$new_field.'` ON `'.$key.'`(`'.$new_field.'`);'; + Webmodel::$arr_sql_set_index[$key][$new_field]=''; + + } + + if(isset(Webmodel::$model[$key]->components[$new_field]->related_model) ) + { + + /*echo "---Creating index for ".$new_field." from ".$key."\n"; + + $query=SQLClass::webtsys_query('CREATE INDEX index_'.$key.'_'.$new_field.' ON '.$key.'('.$new_field.')');*/ + + Webmodel::$arr_sql_index[$key][$new_field]='CREATE INDEX `index_'.$key.'_'.$new_field.'` ON `'.$key.'`(`'.$new_field.'`);'; + + $table_related=Webmodel::$model[$key]->components[$new_field]->related_model->name; + + $id_table_related=Webmodel::load_id_model_related(Webmodel::$model[$key]->components[$new_field], $model); + + Webmodel::$arr_sql_set_index[$key][$new_field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$new_field.'_'.$key.'IDX` FOREIGN KEY ( `'.$new_field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;'; + + } + + } + + else + + { + + /*if(isset(Webmodel::$model[$key]->components[$new_field]->related_model) ) + {*/ + + //Drop foreignkeyfield + + //Bug, need fixed. + if($keys[$new_field]!='') + { + + $query=SQLClass::webtsys_query('ALTER TABLE `'.$key.'` DROP FOREIGN KEY '.$new_field.'_'.$key.'IDX'); + + } + + + //} + + $query=SQLClass::webtsys_query('alter table `'.$key.'` drop `'.$new_field.'`'); + + echo "Deleting ".$new_field." from ".$key."...\n"; + + } + + } + + $arr_etable[$key]=0; + + } + + //Create Indexes... + + foreach(Webmodel::$arr_sql_index as $model_name => $arr_index) + { + foreach(Webmodel::$arr_sql_index[$model_name] as $key_data => $sql_index) + { + + echo "---Creating index for ".$key_data." on model ".$model_name."\n"; + + $query=SQLClass::webtsys_query($sql_index); + + if(Webmodel::$arr_sql_set_index[$model_name][$key_data]!='') + { + $query=SQLClass::webtsys_query(Webmodel::$arr_sql_set_index[$model_name][$key_data]); + } + + } + } + + //Create Uniques... + + foreach(Webmodel::$arr_sql_unique as $model_name => $arr_index) + { + foreach(Webmodel::$arr_sql_unique[$model_name] as $key_data => $sql_index) + { + + echo "---Creating unique for ".$key_data." on model ".$model_name."\n"; + + $query=SQLClass::webtsys_query($sql_index); + + if(Webmodel::$arr_sql_set_unique[$model_name][$key_data]!='') + { + $query=SQLClass::webtsys_query(Webmodel::$arr_sql_set_unique[$model_name][$key_data]); + } + + } + } + +} + +function load_id_model_related($foreignkeyfield) +{ + + //global $model; + + $table_related=$foreignkeyfield->related_model->name; + + $id_table_related=''; + + if(!isset(Webmodel::$model[ $table_related ]->idmodel)) + { + + //$id_table_related='Id'.ucfirst(PhangoVar::Webmodel::$model[$key]->components[$new_field]->related_model); + //Need load the model + + if(isset($foreignkeyfield->params_loading_mod['module']) && isset($foreignkeyfield->params_loading_mod['model'])) + { + + $model=load_model($foreignkeyfield->params_loading_mod); + + //obtain id + + $id_table_related=Webmodel::$model[ $foreignkeyfield->params_loading_mod['model'] ]->idmodel; + + /*unset(PhangoVar::Webmodel::$model[ $foreignkeyfield->params_loading_mod['model'] ]); + + unset($cache_model);*/ + + } + + } + else + { + + $id_table_related=Webmodel::$model[ $table_related ]->idmodel; + + } + + if($id_table_related=='') + { + + //Set standard... + + $id_table_related='Id'.ucfirst($table_related); + + } + + return $id_table_related; + +} + +?> diff --git a/bin/padmin.php b/bin/padmin.php deleted file mode 100644 index 15e0c2b..0000000 --- a/bin/padmin.php +++ /dev/null @@ -1,536 +0,0 @@ -connect_to_db(); - -} catch(Exception $e) -{ - - echo $e->getMessage()."\n"; - die; - -} - -//print_r(get_declared_classes()); - - - -update_table(Webmodel::$model); - -$post_install_script=Webmodel::$model_path.$arr_option[0].'/install/post_install.php'; - -$post_install_lock=Webmodel::$model_path.$arr_option[0].'/install/lock'; - -if(file_exists($post_install_script) && !file_exists($post_install_lock)) -{ - - echo "Executing post_install script...\n"; - - include($post_install_script); - - if(post_install()) - { - - if(!file_put_contents($post_install_lock, 'installed')) - { - - echo "Done, but cannot create this file: ".$arr_option[0].'/install/lock'.". Check your permissions and create the file if the script executed satisfally \n"; - - } - else - { - - echo "Done\n"; - - } - - } - else - { - - echo "Error, please, check ${post_install_script} file and execute padmin.php again\n"; - - } - -} - -echo "All things done\n"; - -/** -* This Function is used for padmin.php for create new tables and fields based in Webmodel class. -* -* @param Webmodel $model The model used for create or update a sql table. -*/ - -function update_table($model) -{ - //include(__DIR__.'/../src/Databases/'.Webmodel::$type_db.'.php'); - - $arr_sql_index=array(); - $arr_sql_set_index=array(); - - $arr_sql_unique=array(); - $arr_sql_set_unique=array(); - - $arr_etable=array(); - - $query=MySQLClass::webtsys_query("show tables"); - - while(list($table)=MySQLClass::webtsys_fetch_row($query)) - { - - $arr_etable[$table]=1; - - } - - foreach($model as $key => $thing) - - { - - $arr_table=array(); - - $allfields=array(); - $fields=array(); - $types=array(); - - $field=""; - $type=""; - $null=""; - $key_db=""; - $default=""; - $extra=""; - $key_field_old=$model[$key]->idmodel; - - if(!isset($arr_etable[$key])) - { - //If table not exists make this - - foreach($model[$key]->components as $field => $data) - { - - $arr_table[]='`'.$field.'` '.$model[$key]->components[$field]->get_type_sql(); - - //Check if indexed - - if($model[$key]->components[$field]->indexed==true) - { - - $arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON '.$key.'(`'.$field.'`);'; - $arr_sql_set_index[$key][$field]=''; - - } - - //Check if unique - - if($model[$key]->components[$field]->unique==true) - { - - $arr_sql_unique[$key][$field]=' ALTER TABLE `'.$key.'` ADD UNIQUE (`'.$field.'`)'; - $arr_sql_set_unique[$key][$field]=''; - - } - - //Check if foreignkeyfield... - if(isset($model[$key]->components[$field]->related_model)) - { - - //Create indexes... - - $arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON '.$key.'(`'.$field.'`);'; - - $table_related=$model[$key]->components[$field]->related_model->name; - - $id_table_related=load_id_model_related($model[$key]->components[$field], $model); - - //'Id'.ucfirst($model[$key]->components[$field]->related_model); - - $arr_sql_set_index[$key][$field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$field.'_'.$key.'IDX` FOREIGN KEY ( `'.$field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;'; - - } - } - - $sql_query="create table `$key` (\n".implode(",\n", $arr_table)."\n) DEFAULT CHARSET=utf8;\n"; - - echo "Creating table $key\n"; - - $query=MySQLClass::webtsys_query($sql_query); - - /*foreach($arr_sql_index as $key_data => $sql_index) - { - - echo "---Creating index for ".$key_data."\n"; - - $query=MySQLClass::webtsys_query($sql_index); - $query=MySQLClass::webtsys_query($arr_sql_set_index[$key_data]); - - }*/ - - } - else - if(isset($model[$key])) - { - //Obtain all fields of model - - foreach($model[$key]->components as $kfield => $value) - { - - $allfields[$kfield]=1; - - } - - //unset($allfields['Id'.ucfirst($key)]); - - $arr_null['NO']='NOT NULL'; - $arr_null['YES']='NULL'; - - unset($allfields[$model[$key]->idmodel]); - - $query=MySQLClass::webtsys_query("describe `".$key."`"); - - list($key_field_old, $type, $null, $key_db, $default, $extra)=MySQLClass::webtsys_fetch_row($query); - - while(list($field, $type, $null, $key_db, $default, $extra)=MySQLClass::webtsys_fetch_row($query)) - { - - $fields[]=$field; - $types[$field]=$type; - $keys[$field]=$key_db; - - $null_set[$field]=$arr_null[$null]; - - } - - foreach($fields as $field) - { - - if(isset($allfields[$field])) - { - - $type=strtoupper($types[$field]); - - unset($allfields[$field]); - - if($model[$key]->components[$field]->get_type_sql()!=($type.' '.$null_set[$field])) - { - - $query=MySQLClass::webtsys_query('alter table `'.$key.'` modify `'.$field.'` '.$model[$key]->components[$field]->get_type_sql()); - - echo "Upgrading ".$field." from ".$key."...\n"; - - - } - - //Check if indexed - - if($model[$key]->components[$field]->indexed==true && $keys[$field]=='') - { - - $arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON `'.$key.'`(`'.$field.'`);'; - $arr_sql_set_index[$key][$field]=''; - - } - - //Check if unique - - if($model[$key]->components[$field]->unique==true && $keys[$field]=='') - { - - $arr_sql_unique[$key][$field]=' ALTER TABLE `'.$key.'` ADD UNIQUE (`'.$field.'`)'; - $arr_sql_set_unique[$key][$field]=''; - - } - - //Set index - - if(isset($model[$key]->components[$field]->related_model) && $keys[$field]=='') - { - - - $arr_sql_index[$key][$field]='CREATE INDEX `index_'.$key.'_'.$field.'` ON `'.$key.'`(`'.$field.'`);'; - - $table_related=$model[$key]->components[$field]->related_model->name; - - $id_table_related=load_id_model_related($model[$key]->components[$field], $model); - - $arr_sql_set_index[$key][$field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$field.'_'.$key.'IDX` FOREIGN KEY ( `'.$field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;'; - - - } - - if(!isset($model[$key]->components[$field]->related_model) && $keys[$field]!='' && $model[$key]->components[$field]->indexed==false && $model[$key]->components[$field]->unique!=true) - { - - echo "---Delete index for ".$field." from ".$key."\n"; - - $query=MySQLClass::webtsys_query('DROP INDEX `index_'.$key.'_'.$field.'` ON '.$key); - - } - - } - - else - - { - - $allfields[$field]=0; - - } - - } - - } - - //Check if new id... - - if($key_field_old!=$model[$key]->idmodel) - { - - $query=MySQLClass::webtsys_query('alter table `'.$key.'` change `'.$key_field_old.'` `'.$model[$key]->idmodel.'` INT NOT NULL AUTO_INCREMENT'); - - echo "Renaming id for this model to ".$model[$key]->idmodel."...\n"; - - } - - //Check if new fields... - - foreach($allfields as $new_field => $new) - { - - if($allfields[$new_field]==1) - { - - $query=MySQLClass::webtsys_query('alter table `'.$key.'` add `'.$new_field.'` '.$model[$key]->components[$new_field]->get_type_sql()); - - echo "Adding ".$new_field." to ".$key."...\n"; - - //Check if indexed - - if($model[$key]->components[$new_field]->indexed==true) - { - - $arr_sql_index[$key][$new_field]='CREATE INDEX `index_'.$key.'_'.$new_field.'` ON `'.$key.'`(`'.$new_field.'`);'; - $arr_sql_set_index[$key][$new_field]=''; - - } - - if(isset($model[$key]->components[$new_field]->related_model) ) - { - - /*echo "---Creating index for ".$new_field." from ".$key."\n"; - - $query=MySQLClass::webtsys_query('CREATE INDEX index_'.$key.'_'.$new_field.' ON '.$key.'('.$new_field.')');*/ - - $arr_sql_index[$key][$new_field]='CREATE INDEX `index_'.$key.'_'.$new_field.'` ON `'.$key.'`(`'.$new_field.'`);'; - - $table_related=$model[$key]->components[$new_field]->related_model->name; - - $id_table_related=load_id_model_related($model[$key]->components[$new_field], $model); - - $arr_sql_set_index[$key][$new_field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$new_field.'_'.$key.'IDX` FOREIGN KEY ( `'.$new_field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;'; - - } - - } - - else - - { - - /*if(isset($model[$key]->components[$new_field]->related_model) ) - {*/ - - //Drop foreignkeyfield - - //Bug, need fixed. - if($keys[$new_field]!='') - { - - $query=MySQLClass::webtsys_query('ALTER TABLE `'.$key.'` DROP FOREIGN KEY '.$new_field.'_'.$key.'IDX'); - - } - - - //} - - $query=MySQLClass::webtsys_query('alter table `'.$key.'` drop `'.$new_field.'`'); - - echo "Deleting ".$new_field." from ".$key."...\n"; - - } - - } - - $arr_etable[$key]=0; - - } - - //Create Indexes... - - foreach($arr_sql_index as $model_name => $arr_index) - { - foreach($arr_sql_index[$model_name] as $key_data => $sql_index) - { - - echo "---Creating index for ".$key_data." on model ".$model_name."\n"; - - $query=MySQLClass::webtsys_query($sql_index); - - if($arr_sql_set_index[$model_name][$key_data]!='') - { - $query=MySQLClass::webtsys_query($arr_sql_set_index[$model_name][$key_data]); - } - - } - } - - //Create Uniques... - - foreach($arr_sql_unique as $model_name => $arr_index) - { - foreach($arr_sql_unique[$model_name] as $key_data => $sql_index) - { - - echo "---Creating unique for ".$key_data." on model ".$model_name."\n"; - - $query=MySQLClass::webtsys_query($sql_index); - - if($arr_sql_set_unique[$model_name][$key_data]!='') - { - $query=MySQLClass::webtsys_query($arr_sql_set_unique[$model_name][$key_data]); - } - - } - } - - /*foreach($arr_etable as $table => $value) - { - - if($value==1) - { - - $query=MySQLClass::webtsys_query('DROP TABLE `'.$table.'`'); - - echo 'Deleting table '.$table."\n"; - - } - - }*/ - -} - -function load_id_model_related($foreignkeyfield, $model) -{ - - //global $model; - - $table_related=$foreignkeyfield->related_model->name; - - $id_table_related=''; - - if(!isset($model[ $table_related ]->idmodel)) - { - - //$id_table_related='Id'.ucfirst(PhangoVar::$model[$key]->components[$new_field]->related_model); - //Need load the model - - if(isset($foreignkeyfield->params_loading_mod['module']) && isset($foreignkeyfield->params_loading_mod['model'])) - { - - $model=load_model($foreignkeyfield->params_loading_mod); - - //obtain id - - $id_table_related=$model[ $foreignkeyfield->params_loading_mod['model'] ]->idmodel; - - /*unset(PhangoVar::$model[ $foreignkeyfield->params_loading_mod['model'] ]); - - unset($cache_model);*/ - - } - - } - else - { - - $id_table_related=$model[ $table_related ]->idmodel; - - } - - if($id_table_related=='') - { - - //Set standard... - - $id_table_related='Id'.ucfirst($table_related); - - } - - return $id_table_related; - -} - -?> \ No newline at end of file diff --git a/composer.json b/composer.json index a58213d..72a1afb 100644 --- a/composer.json +++ b/composer.json @@ -18,5 +18,6 @@ "psr-4": { "PhangoApp\\PhaModels\\": "src" } - } + }, + "bin": ["bin/padmin"] } diff --git a/src/Webmodel.php b/src/Webmodel.php index e9fe798..0daa7ec 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -294,11 +294,11 @@ class Webmodel { * */ - static public function load_model($model) + static public function load_model($model_path) { - $app_model=$model; - + //$app_model=$model; + /* if(strpos($model, '/')) { @@ -309,10 +309,11 @@ class Webmodel { $model=$arr_model[1]; } + */ - $path_model=Webmodel::$model_path.$app_model.'/'.Webmodel::$model_folder.'/models_'.$model.'.php'; + $path_model=$model_path.'.php'; - if(!isset(Webmodel::$cache_model[$app_model.'/'.$model])) + if(!isset(Webmodel::$cache_model[$path_model])) { if(is_file($path_model)) @@ -320,7 +321,7 @@ class Webmodel { include($path_model); - Webmodel::$cache_model[$app_model.'/'.$model]=1; + Webmodel::$cache_model[$path_model]=1; } else @@ -365,13 +366,6 @@ class Webmodel { $output=ob_get_contents(); ob_clean(); - - //$text_error='

Output: '.$output.'

'; - - /*$arr_error_sql[0]='

Error: Cannot connect to MySQL db.

'; - $arr_error_sql[1]='

Error: Cannot connect to MySQL db, '.$output.'

'; - - show_error($arr_error_sql[0], $arr_error_sql[1]);*/ throw new \Exception('Error: cannot connect to database'); From fd61da4b7bb28b726e9e7a0105082d9cbf182807 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 18 Aug 2015 02:03:22 +0200 Subject: [PATCH 20/43] Fixes for new behaviour --- src/View.php | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/src/View.php b/src/View.php index 9cb9ca0..e6da3ea 100644 --- a/src/View.php +++ b/src/View.php @@ -9,7 +9,7 @@ class View { * Root path for includes app folders */ - static public $root_path=__DIR__; + static public $root_path="."; /** * A set of paths inside of $root_path contining views. If a view is located, the foreach for search the view is break @@ -95,6 +95,12 @@ class View { static public $header=array(); + /** + * An array with config_paths for load configurations. + */ + + static public $config_path=['settings']; + /** * The construct for create a view object * @@ -117,6 +123,19 @@ class View { }*/ + static public function load_config() + { + + //Load config here + foreach(View::config_path as $config) + { + + Utils::load_config("config_views", $config); + + } + + } + /** * Very important function used for load views. Is the V in the MVC paradigm. Phango is an MVC framework and has separate code and html. * @@ -181,6 +200,14 @@ class View { $func_view=View::$cache_template[$template]; + if(!function_exists($func_view)) + { + + throw new \Exception('Error: Template file loaded but function '.$func_view.' not found: '.implode(' and ', $all_path)); + die; + + } + //Load function from loaded view with his parameters //array_unshift($arr_template_values, $this); From 415ae99b14bf955da1a605c03d6f57cc56a4004e Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 18 Aug 2015 03:52:55 +0200 Subject: [PATCH 21/43] New behaviour for register components in models --- bin/padmin | 16 +++++++++------- src/Webmodel.php | 25 +++++++++++++++++++------ 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/bin/padmin b/bin/padmin index b66d9a1..cbeb2ec 100755 --- a/bin/padmin +++ b/bin/padmin @@ -14,8 +14,11 @@ else use PhangoApp\PhaModels\SQLClass; use PhangoApp\PhaModels\Webmodel; +use PhangoApp\PhaUtils\Utils; use League\CLImate\CLImate; +Utils::load_config('config'); + $options=getopt('', array('model:')); padminConsole($options); @@ -32,9 +35,9 @@ function padminConsole($options) //echo "Use: php console.php -m=padmin -c=padmin --model=module/model\n"; - $climate->white()->backgroundBlack()->out("Use: padmin --model=module/model"); + $climate->white()->backgroundBlack()->out("Use: padmin --model=path/to/model"); - die; + exit(0); } @@ -43,16 +46,16 @@ function padminConsole($options) settype($arr_option[0], 'string'); settype($arr_option[1], 'string'); - Webmodel::$model_path='./modules/'; + #Webmodel::$model_path='./modules/'; - $model_file=Webmodel::$model_path.$arr_option[0].'/models/models_'.$arr_option[1].'.php'; + $model_file=$options['model'].'.php'; if(!is_file($model_file)) { $climate->white()->backgroundRed()->out("Error: cannot find the model file in ".$arr_option[0]."/models/models_".$arr_option[1].".php"); - die(); + exit(1); } @@ -68,8 +71,7 @@ function padminConsole($options) } catch(Exception $e) { $climate->white()->backgroundRed()->out($e->getMessage()); - //echo $e->getMessage()."\n"; - die; + exit(1); } diff --git a/src/Webmodel.php b/src/Webmodel.php index 0daa7ec..9c39a5b 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -3,6 +3,7 @@ namespace PhangoApp\PhaModels; use PhangoApp\PhaI18n\I18n; +use PhangoApp\PhaModels\CoreFields\PrimaryField; /** * The most important class for the framework @@ -265,7 +266,7 @@ class Webmodel { $this->name=$name_model; $this->idmodel='Id'.ucfirst($this->name); - $this->components[$this->idmodel]=new \PrimaryField(); + $this->components[$this->idmodel]=new PrimaryField(); $this->label=$this->name; if(!isset(Webmodel::$connection_func[$this->db_selected])) @@ -277,8 +278,6 @@ class Webmodel { $this->cache=$cache; $this->type_cache=$type_cache; - - } @@ -1097,6 +1096,17 @@ class Webmodel { return SQLClass::webtsys_query($sql_query); + } + + /** + * Method used for update tables + */ + + public function update_table() + { + + + } /** @@ -1582,11 +1592,14 @@ class Webmodel { * @param string $arguments Array with arguments for construct the new field * @param boolean $required A boolean used for set the default required value */ - public function register($name, $type, $arguments, $required=0) + public function register($name, $type_class, $required=0) { - $rc=new \ReflectionClass($type); - $this->components[$name]=$rc->newInstanceArgs($arguments); + /*$rc=new \ReflectionClass($type); + $this->components[$name]=$rc->newInstanceArgs($arguments);*/ + + $this->components[$name]=&$type_class; + //Set first label... $this->components[$name]->label=Webmodel::set_name_default($name); $this->components[$name]->name_model=$this->name; From 4a5389b2732267eeeb5dff35affddfe488c921f8 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 18 Aug 2015 17:34:36 +0200 Subject: [PATCH 22/43] Added UserPhangoModel Class --- src/ExtraModels/UserPhangoModel.php | 166 ++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 src/ExtraModels/UserPhangoModel.php diff --git a/src/ExtraModels/UserPhangoModel.php b/src/ExtraModels/UserPhangoModel.php new file mode 100644 index 0000000..31cd85d --- /dev/null +++ b/src/ExtraModels/UserPhangoModel.php @@ -0,0 +1,166 @@ + +* @file +* @package ExtraUtils/Login +* +* Now, we define components for use in models. Components are fields on a table. +* +*/ + +namespace PhangoApp\PhaModels\ExtraModels\UserPhangoModel; + +use PhangoApp\Phai18n\I18n; +use PhangoApp\PhaModels\Webmodel; + +I18n::load_lang('users'); + +/** +* Children class of webmodel for use with login class +* +*/ + +class UserPhangoModel extends Webmodel { + + public $username='username'; + public $email='email'; + public $password='password'; + public $repeat_password='repeat_password'; + + public function insert($post) + { + + if($this->check_user_exists($post[$this->username], $post[$this->email])) + { + + if(!$this->check_password($post['password'], $post['repeat_password'])) + { + + //$this->components['password']->required=0; + + $this->components[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal'); + + return false; + + } + + return parent::insert($post); + + } + else + { + + $this->std_error=I18n::lang('users', 'cannot_insert_user_email_or_user', 'A user already exists with this email or username'); + + return false; + + } + + } + + public function update($post, $where_sql='') + { + + if(isset($post[$this->username]) && $post[$this->email]) + { + + if($this->check_user_exists($post[$this->username], $post[$this->email], $post['IdUser_admin'])) + { + + if(!$this->check_password($post['password'], $post['repeat_password'])) + { + + //$this->components['password']->required=0; + + $this->components[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal'); + + return false; + + } + + if(Utils::form_text($post['password'])=='') + { + + $this->components[$this->password]->required=0; + unset($post[$this->password]); + + } + + return parent::update($post, $where_sql); + + } + else + { + + $this->std_error=I18n::lang('users', 'cannot_insert_user_email_or_user', 'A user already exists with this email or username'); + + return false; + + } + + } + else + { + + return parent::update($post, $where_sql); + + } + + } + + public function check_password($password, $repeat_password) + { + + $password=Utils::form_text($password); + $repeat_password=Utils::form_text($repeat_password); + + if($password!=$repeat_password) + { + + return false; + + } + + return true; + + } + + public function check_user_exists($user, $email, $iduser=0) + { + + $user=$this->components[$this->username]->check($user); + $email=$this->components[$this->email]->check($email); + + $where_sql='where ('.$this->username.'="'.$user.'" or '.$this->email.'="'.$email.'")'; + + settype($iduser, 'integer'); + + if($iduser>0) + { + + $where_sql.=' and IdUser_admin!='.$iduser; + + } + + $c=$this->select_count($where_sql); + + if($c==0) + { + + return true; + + } + else + { + + return false; + + } + + + } + +} + +?> From cfe9f7217e6b77968f4e585f1dd852c6c815f537 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 18 Aug 2015 17:38:16 +0200 Subject: [PATCH 23/43] Little fix --- src/ExtraModels/UserPhangoModel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ExtraModels/UserPhangoModel.php b/src/ExtraModels/UserPhangoModel.php index 31cd85d..a4a5623 100644 --- a/src/ExtraModels/UserPhangoModel.php +++ b/src/ExtraModels/UserPhangoModel.php @@ -9,7 +9,7 @@ * */ -namespace PhangoApp\PhaModels\ExtraModels\UserPhangoModel; +namespace PhangoApp\PhaModels\ExtraModels; use PhangoApp\Phai18n\I18n; use PhangoApp\PhaModels\Webmodel; From 40eb84aeab0ddc2d798dca3cf46acddba2ab65f4 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Wed, 19 Aug 2015 02:05:13 +0200 Subject: [PATCH 24/43] Added coreforms --- src/CoreFields/BooleanField.php | 2 +- src/CoreFields/CharField.php | 2 +- src/CoreFields/ChoiceField.php | 2 +- src/CoreFields/DateField.php | 2 +- src/CoreFields/DoubleField.php | 2 +- src/CoreFields/EmailField.php | 2 +- src/CoreFields/FileField.php | 2 +- src/CoreFields/ForeignKeyField.php | 2 +- src/CoreFields/ImageField.php | 2 +- src/CoreFields/IntegerField.php | 2 +- src/CoreFields/KeyField.php | 2 +- src/CoreFields/ParentField.php | 2 +- src/CoreFields/PasswordField.php | 2 +- src/CoreFields/PhangoField.php | 2 +- src/CoreFields/PrimaryField.php | 2 +- src/CoreFields/TextField.php | 2 +- src/CoreFields/TextHTMLField.php | 2 +- src/CoreForms.php | 502 +++++++++++++++++++++++++++++ 18 files changed, 519 insertions(+), 17 deletions(-) create mode 100644 src/CoreForms.php diff --git a/src/CoreFields/BooleanField.php b/src/CoreFields/BooleanField.php index 2a8b55d..8d35258 100644 --- a/src/CoreFields/BooleanField.php +++ b/src/CoreFields/BooleanField.php @@ -24,7 +24,7 @@ class BooleanField extends PhangoField { { $this->size=1; - $this->form='SelectForm'; + $this->form='CoreForms::SelectForm'; } diff --git a/src/CoreFields/CharField.php b/src/CoreFields/CharField.php index 0ad64b5..5a080be 100644 --- a/src/CoreFields/CharField.php +++ b/src/CoreFields/CharField.php @@ -31,7 +31,7 @@ class CharField extends PhangoField { { $this->size=$size; - $this->form='TextForm'; + $this->form='CoreForms::TextForm'; } diff --git a/src/CoreFields/ChoiceField.php b/src/CoreFields/ChoiceField.php index e48391d..764e205 100644 --- a/src/CoreFields/ChoiceField.php +++ b/src/CoreFields/ChoiceField.php @@ -29,7 +29,7 @@ class ChoiceField extends PhangoField { { $this->size=$size; - $this->form='SelectForm'; + $this->form='CoreForms::SelectForm'; $this->type=$type; $this->arr_values=$arr_values; $this->default_value=$default_value; diff --git a/src/CoreFields/DateField.php b/src/CoreFields/DateField.php index 08b2964..0c33474 100644 --- a/src/CoreFields/DateField.php +++ b/src/CoreFields/DateField.php @@ -23,7 +23,7 @@ class DateField extends PhangoField { { $this->size=$size; - $this->form='DateForm'; + $this->form='CoreForms::DateForm'; } diff --git a/src/CoreFields/DoubleField.php b/src/CoreFields/DoubleField.php index 9feeec3..35f54d6 100644 --- a/src/CoreFields/DoubleField.php +++ b/src/CoreFields/DoubleField.php @@ -22,7 +22,7 @@ class DoubleField extends PhangoField { { $this->size=$size; - $this->form='TextForm'; + $this->form='CoreForms::TextForm'; } diff --git a/src/CoreFields/EmailField.php b/src/CoreFields/EmailField.php index 4ff1c3a..cb4ff27 100644 --- a/src/CoreFields/EmailField.php +++ b/src/CoreFields/EmailField.php @@ -12,7 +12,7 @@ class EmailField extends PhangoField { public $size=200; public $value=""; public $label=""; - public $form="TextForm"; + public $form="CoreForms::TextForm"; public $class=""; public $required=0; public $quot_open='\''; diff --git a/src/CoreFields/FileField.php b/src/CoreFields/FileField.php index 670e434..b4fc13e 100644 --- a/src/CoreFields/FileField.php +++ b/src/CoreFields/FileField.php @@ -12,7 +12,7 @@ class FileField extends PhangoField { public $value=""; public $label=""; public $required=0; - public $form="FileForm"; + public $form="CoreForms::FileForm"; public $name_file=""; public $path=""; public $url_path=""; diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index 2661d3d..a1806af 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -29,7 +29,7 @@ class ForeignKeyField extends IntegerField{ { $this->size=$size; - $this->form='SelectForm'; + $this->form='CoreForms::SelectForm'; $this->related_model=&$related_model; $this->container_model=$this->related_model->name; //Fields obtained from related_model if you make a query... diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php index a08f8be..e7b0a70 100644 --- a/src/CoreFields/ImageField.php +++ b/src/CoreFields/ImageField.php @@ -15,7 +15,7 @@ class ImageField extends PhangoField { public $value=""; public $label=""; public $required=0; - public $form="ImageForm"; + public $form="CoreForms::ImageForm"; public $name_file=""; public $path=""; public $url_path=""; diff --git a/src/CoreFields/IntegerField.php b/src/CoreFields/IntegerField.php index cb1d5fb..ef750e0 100644 --- a/src/CoreFields/IntegerField.php +++ b/src/CoreFields/IntegerField.php @@ -22,7 +22,7 @@ class IntegerField extends PhangoField { { $this->size=$size; - $this->form='TextForm'; + $this->form='CoreForms::TextForm'; $this->only_positive=$only_positive; $this->min_num=$min_num; $this->max_num=$max_num; diff --git a/src/CoreFields/KeyField.php b/src/CoreFields/KeyField.php index a23ed84..4b0a11c 100644 --- a/src/CoreFields/KeyField.php +++ b/src/CoreFields/KeyField.php @@ -26,7 +26,7 @@ class KeyField extends PhangoField { { $this->size=$size; - $this->form='TextForm'; + $this->form='CoreForms::TextForm'; } diff --git a/src/CoreFields/ParentField.php b/src/CoreFields/ParentField.php index c5a664b..815e741 100644 --- a/src/CoreFields/ParentField.php +++ b/src/CoreFields/ParentField.php @@ -17,7 +17,7 @@ class ParentField extends IntegerField{ $this->parent_model=&$parent_model; $this->size=$size; - $this->form='SelectForm'; + $this->form='CoreForms::SelectForm'; } diff --git a/src/CoreFields/PasswordField.php b/src/CoreFields/PasswordField.php index 09f203e..5219a33 100644 --- a/src/CoreFields/PasswordField.php +++ b/src/CoreFields/PasswordField.php @@ -18,7 +18,7 @@ class PasswordField extends CharField { { $this->size=$size; - $this->form='PasswordForm'; + $this->form='CoreForms::PasswordForm'; } diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index ae277f7..13b8c09 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -87,7 +87,7 @@ class PhangoField { * Form define the function for use in forms... */ - public $form=""; + public $form="CoreForms::TextForm"; /** * Array for create initial parameters for form.. diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index d618813..a2d7eb2 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -33,7 +33,7 @@ class PrimaryField extends PhangoField { * By default, the form used for this field is HiddenForm. */ - public $form="HiddenForm"; + public $form="CoreForms::HiddenForm"; /** * Check function that convert the value on a PrimaryField value. diff --git a/src/CoreFields/TextField.php b/src/CoreFields/TextField.php index 28dd8ff..23d4edf 100644 --- a/src/CoreFields/TextField.php +++ b/src/CoreFields/TextField.php @@ -22,7 +22,7 @@ class TextField extends PhangoField { function __construct($multilang=0) { - $this->form='TextAreaForm'; + $this->form='CoreForms::TextAreaForm'; $this->multilang=$multilang; } diff --git a/src/CoreFields/TextHTMLField.php b/src/CoreFields/TextHTMLField.php index 526c296..9ca4f02 100644 --- a/src/CoreFields/TextHTMLField.php +++ b/src/CoreFields/TextHTMLField.php @@ -25,7 +25,7 @@ class TextHTMLField extends PhangoField { function __construct($multilang=0) { - $this->form='TextAreaForm'; + $this->form='CoreForms::TextAreaForm'; $this->multilang=$multilang; $this->set_safe_html_tags(); diff --git a/src/CoreForms.php b/src/CoreForms.php new file mode 100644 index 0000000..7062013 --- /dev/null +++ b/src/CoreForms.php @@ -0,0 +1,502 @@ +form +* +* @author Antonio de la Rosa +* @file +* @package CoreForms +* +*/ + +namespace PhangoApp\PhaModels; + +use PhangoApp\PhaUtils\Utils; + +class CoreForms { + + /* Function form used for text fields on a form. Show a text html input. + * + * + * @param string $name Name of this text field for use in forms + * @param string $class Css class used in the text field + * @param string $value Initial value for the form + */ + + static public TextForm($name="", $class='', $value='') + { + + return ''; + + } + + //Prepare a value for input text + + static public TextFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + return $value; + + } + + //Create a input password + + static public PasswordForm($name="", $class='', $value='') + { + + $value = Utils::replace_quote_text( $value ); + + return ''; + + } + + //Prepare a value for input password + + static public PasswordFormSet($post, $value) + { + + $value = ''; //Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a input file + + static public FileForm($name="", $class='', $value='', $delete_inline=0, $path_file='') + { + + + + $file_url=$path_file.'/'.$value; + + $file_exist=''; + + if($value!='') + { + + $file_exist=''.basename($value).' '; + + if($delete_inline==1) + { + + $file_exist.=I18n::lang('common', 'delete_file', 'Delete file').' '; + + } + + } + + return ' '.$file_exist; + + } + + //Prepare a value for input password + + static public FileFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + + //Create a special form for a image + + static public ImageForm($name="", $class='', $value='', $delete_inline=0, $path_image='') + { + + $image_url=$path_image.'/'.$value; + + $image_exist=''; + + if($value!='') + { + + $image_exist=''.basename($value).' '; + + if($delete_inline==1) + { + + $image_exist.=I18n::lang('common', 'delete_image', 'Delete image').' '; + + } + + } + + return ' '.$image_exist; + + } + + //Prepare a value for input password + + static public ImageFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a textarea + + static public TextAreaForm($name="", $class='', $value='') + { + + return ''; + + } + + //Prepare the value for the textarea + + static public TextAreaFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a input hidden + + static public HiddenForm($name="", $class='', $value='') + { + + return ''; + + } + + //Prepare the value for a input hidden + + static public HiddenFormSet($post, $value) + { + + $value = Utils::replace_quote_text( $value ); + + return $value; + + } + + //Create a input checkbox + + static public CheckBoxForm($name="", $class='', $value='') + { + + $arr_checked[$value]=''; + + $arr_checked[0]=''; + $arr_checked[1]='checked'; + + return ''; + + } + + //Prepare the value for the checkbox + + static public CheckBoxFormSet($post, $value) + { + + settype($value, 'integer'); + + return $value; + + } + + //Create a select + + static public SelectForm($name="", $class='', $value='', $more_options='') + { + + $select=''."\n"; + + return $select; + + } + + //Prepare the value for the select + + static public SelectFormSet($post, $value) + { + + $value = preg_replace('/<(.*?)\/(.*?)option(.*?)>/', '', $value); + + $post[0]=$value; + + return $post; + + } + + //Crate a multiple select + + static public SelectManyForm($name="", $class='', $value='', $more_options='' ) + { + + $select=''."\n"; + + return $select; + + } + + //Prepare the value for the multiple select + + static public SelectManyFormSet($post, $value) + { + + if(gettype($value)!='array') + { + + $arr_value=unserialize($value); + } + else + { + + $arr_value=$value; + + } + //$value = preg_replace('/<(.*?)\/(.*?)option(.*?)>/', '', $value); + + $post[0]=$arr_value; + + return $post; + + } + + //A special form for dates in format day/month/year + + static public DateForm($field, $class='', $value='', $set_time=1, $see_title=1) + { + + if($value==0) + { + + $day=''; + $month=''; + $year=''; + $hour=''; + $minute=''; + $second=''; + + } + else + { + + //$value+=$user_data['format_time']; + + $day=date('j', $value); + $month=date('n', $value); + $year=date('Y', $value); + $hour=date('G', $value); + $minute=date('i', $value); + $second=date('s', $value); + } + + $date=''; + + if($set_time<=1) + { + + $date.=''."\n"; + $date.=''."\n"; + $date.=''."\n   "; + + } + + if($set_time>0) + { + + $hour_txt=I18n::lang('common', 'hour', 'Hour'); + $minute_txt=I18n::lang('common', 'minute', 'Minute'); + $second_txt=I18n::lang('common', 'second', 'Second'); + + if($see_title==0) + { + + $hour_txt=''; + $minute_txt=''; + $second_txt=''; + + } + + $date.=$hour_txt.' '."\n"; + $date.=$minute_txt.' '."\n"; + $date.=$second_txt.' '."\n"; + + } + + echo ''; + + return $date; + + } + + //Prepare value form dateform + + static public DateFormSet($post, $value) + { + + if(gettype($value)=='array') + { + foreach($value as $key => $val) + { + + settype($value[$key], 'integer'); + + } + + settype($value[3], 'integer'); + settype($value[4], 'integer'); + settype($value[5], 'integer'); + + $final_value=mktime ($value[3], $value[4], $value[5], $value[1], $value[0], $value[2] ); + + } + else + { + + settype($value, 'integer'); + + $final_value=$value; + + } + + + return $final_value; + + } + + static public RadioIntForm($name="", $class='', $value=array(), $more_options='') + { + $select=''; + + list($key, $default)= each($value); + + $arr_selected=array(); + + $arr_selected[$default]="checked"; + + //Check if array is safe. + + $z=count($value); + + for($x=1;$x<$z;$x+=2) + { + + $val=$value[$x+1]; + + settype($arr_selected[$val], "string"); + + $select.= $value[$x].' '."\n"; + + } + + return $select; + + } + + //Prepare the value for the select + + static public RadioIntFormSet($post, $value) + { + + settype($value, 'integer'); + + $post[0]=$value; + + return $post; + + } + +} + +?> \ No newline at end of file From 9174969b8485e207b0693428a1af9da187638dab Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Wed, 19 Aug 2015 02:09:51 +0200 Subject: [PATCH 25/43] Fixes on CoreForms --- src/CoreForms.php | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/CoreForms.php b/src/CoreForms.php index 7062013..0729e4d 100644 --- a/src/CoreForms.php +++ b/src/CoreForms.php @@ -1,6 +1,6 @@ '; @@ -36,7 +36,7 @@ class CoreForms { //Prepare a value for input text - static public TextFormSet($post, $value) + static public function TextFormSet($post, $value) { $value = Utils::replace_quote_text( $value ); @@ -46,7 +46,7 @@ class CoreForms { //Create a input password - static public PasswordForm($name="", $class='', $value='') + static public function PasswordForm($name="", $class='', $value='') { $value = Utils::replace_quote_text( $value ); @@ -57,7 +57,7 @@ class CoreForms { //Prepare a value for input password - static public PasswordFormSet($post, $value) + static public function PasswordFormSet($post, $value) { $value = ''; //Utils::replace_quote_text( $value ); @@ -68,7 +68,7 @@ class CoreForms { //Create a input file - static public FileForm($name="", $class='', $value='', $delete_inline=0, $path_file='') + static public function FileForm($name="", $class='', $value='', $delete_inline=0, $path_file='') { @@ -97,7 +97,7 @@ class CoreForms { //Prepare a value for input password - static public FileFormSet($post, $value) + static public function FileFormSet($post, $value) { $value = Utils::replace_quote_text( $value ); @@ -109,7 +109,7 @@ class CoreForms { //Create a special form for a image - static public ImageForm($name="", $class='', $value='', $delete_inline=0, $path_image='') + static public function ImageForm($name="", $class='', $value='', $delete_inline=0, $path_image='') { $image_url=$path_image.'/'.$value; @@ -136,7 +136,7 @@ class CoreForms { //Prepare a value for input password - static public ImageFormSet($post, $value) + static public function ImageFormSet($post, $value) { $value = Utils::replace_quote_text( $value ); @@ -147,7 +147,7 @@ class CoreForms { //Create a textarea - static public TextAreaForm($name="", $class='', $value='') + static public function TextAreaForm($name="", $class='', $value='') { return ''; @@ -156,7 +156,7 @@ class CoreForms { //Prepare the value for the textarea - static public TextAreaFormSet($post, $value) + static public function TextAreaFormSet($post, $value) { $value = Utils::replace_quote_text( $value ); @@ -167,7 +167,7 @@ class CoreForms { //Create a input hidden - static public HiddenForm($name="", $class='', $value='') + static public function HiddenForm($name="", $class='', $value='') { return ''; @@ -176,7 +176,7 @@ class CoreForms { //Prepare the value for a input hidden - static public HiddenFormSet($post, $value) + static public function HiddenFormSet($post, $value) { $value = Utils::replace_quote_text( $value ); @@ -187,7 +187,7 @@ class CoreForms { //Create a input checkbox - static public CheckBoxForm($name="", $class='', $value='') + static public function CheckBoxForm($name="", $class='', $value='') { $arr_checked[$value]=''; @@ -201,7 +201,7 @@ class CoreForms { //Prepare the value for the checkbox - static public CheckBoxFormSet($post, $value) + static public function CheckBoxFormSet($post, $value) { settype($value, 'integer'); @@ -212,7 +212,7 @@ class CoreForms { //Create a select - static public SelectForm($name="", $class='', $value='', $more_options='') + static public function SelectForm($name="", $class='', $value='', $more_options='') { $select=''."\n"; @@ -330,7 +330,7 @@ class CoreForms { //Prepare the value for the multiple select - static public SelectManyFormSet($post, $value) + static public function SelectManyFormSet($post, $value) { if(gettype($value)!='array') @@ -354,7 +354,7 @@ class CoreForms { //A special form for dates in format day/month/year - static public DateForm($field, $class='', $value='', $set_time=1, $see_title=1) + static public function DateForm($field, $class='', $value='', $set_time=1, $see_title=1) { if($value==0) @@ -422,7 +422,7 @@ class CoreForms { //Prepare value form dateform - static public DateFormSet($post, $value) + static public function DateFormSet($post, $value) { if(gettype($value)=='array') @@ -455,7 +455,7 @@ class CoreForms { } - static public RadioIntForm($name="", $class='', $value=array(), $more_options='') + static public function RadioIntForm($name="", $class='', $value=array(), $more_options='') { $select=''; @@ -486,7 +486,7 @@ class CoreForms { //Prepare the value for the select - static public RadioIntFormSet($post, $value) + static public function RadioIntFormSet($post, $value) { settype($value, 'integer'); From f75ac6d78dd8fe72e5ec7e38e0cf24703b45e611 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Wed, 19 Aug 2015 02:51:11 +0200 Subject: [PATCH 26/43] Fixes on models --- src/CoreFields/BooleanField.php | 2 +- src/CoreFields/CharField.php | 2 +- src/CoreFields/ChoiceField.php | 2 +- src/CoreFields/DateField.php | 2 +- src/CoreFields/DoubleField.php | 2 +- src/CoreFields/EmailField.php | 2 +- src/CoreFields/FileField.php | 2 +- src/CoreFields/ForeignKeyField.php | 2 +- src/CoreFields/ImageField.php | 2 +- src/CoreFields/IntegerField.php | 2 +- src/CoreFields/KeyField.php | 2 +- src/CoreFields/ParentField.php | 2 +- src/CoreFields/PasswordField.php | 2 +- src/CoreFields/PhangoField.php | 2 +- src/CoreFields/PrimaryField.php | 2 +- src/CoreFields/TextField.php | 2 +- src/CoreFields/TextHTMLField.php | 2 +- src/ExtraModels/UserPhangoModel.php | 1 + 18 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/CoreFields/BooleanField.php b/src/CoreFields/BooleanField.php index 8d35258..862b587 100644 --- a/src/CoreFields/BooleanField.php +++ b/src/CoreFields/BooleanField.php @@ -24,7 +24,7 @@ class BooleanField extends PhangoField { { $this->size=1; - $this->form='CoreForms::SelectForm'; + $this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; } diff --git a/src/CoreFields/CharField.php b/src/CoreFields/CharField.php index 5a080be..4bb0b77 100644 --- a/src/CoreFields/CharField.php +++ b/src/CoreFields/CharField.php @@ -31,7 +31,7 @@ class CharField extends PhangoField { { $this->size=$size; - $this->form='CoreForms::TextForm'; + $this->form='PhangoApp\PhaModels\CoreForms::TextForm'; } diff --git a/src/CoreFields/ChoiceField.php b/src/CoreFields/ChoiceField.php index 764e205..f4e7952 100644 --- a/src/CoreFields/ChoiceField.php +++ b/src/CoreFields/ChoiceField.php @@ -29,7 +29,7 @@ class ChoiceField extends PhangoField { { $this->size=$size; - $this->form='CoreForms::SelectForm'; + $this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; $this->type=$type; $this->arr_values=$arr_values; $this->default_value=$default_value; diff --git a/src/CoreFields/DateField.php b/src/CoreFields/DateField.php index 0c33474..157724f 100644 --- a/src/CoreFields/DateField.php +++ b/src/CoreFields/DateField.php @@ -23,7 +23,7 @@ class DateField extends PhangoField { { $this->size=$size; - $this->form='CoreForms::DateForm'; + $this->form='PhangoApp\PhaModels\CoreForms::DateForm'; } diff --git a/src/CoreFields/DoubleField.php b/src/CoreFields/DoubleField.php index 35f54d6..57ba60c 100644 --- a/src/CoreFields/DoubleField.php +++ b/src/CoreFields/DoubleField.php @@ -22,7 +22,7 @@ class DoubleField extends PhangoField { { $this->size=$size; - $this->form='CoreForms::TextForm'; + $this->form='PhangoApp\PhaModels\CoreForms::TextForm'; } diff --git a/src/CoreFields/EmailField.php b/src/CoreFields/EmailField.php index cb4ff27..938e56a 100644 --- a/src/CoreFields/EmailField.php +++ b/src/CoreFields/EmailField.php @@ -12,7 +12,7 @@ class EmailField extends PhangoField { public $size=200; public $value=""; public $label=""; - public $form="CoreForms::TextForm"; + public $form="PhangoApp\PhaModels\CoreForms::TextForm"; public $class=""; public $required=0; public $quot_open='\''; diff --git a/src/CoreFields/FileField.php b/src/CoreFields/FileField.php index b4fc13e..9709a76 100644 --- a/src/CoreFields/FileField.php +++ b/src/CoreFields/FileField.php @@ -12,7 +12,7 @@ class FileField extends PhangoField { public $value=""; public $label=""; public $required=0; - public $form="CoreForms::FileForm"; + public $form="PhangoApp\PhaModels\CoreForms::FileForm"; public $name_file=""; public $path=""; public $url_path=""; diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index a1806af..88323c0 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -29,7 +29,7 @@ class ForeignKeyField extends IntegerField{ { $this->size=$size; - $this->form='CoreForms::SelectForm'; + $this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; $this->related_model=&$related_model; $this->container_model=$this->related_model->name; //Fields obtained from related_model if you make a query... diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php index e7b0a70..9d72a9b 100644 --- a/src/CoreFields/ImageField.php +++ b/src/CoreFields/ImageField.php @@ -15,7 +15,7 @@ class ImageField extends PhangoField { public $value=""; public $label=""; public $required=0; - public $form="CoreForms::ImageForm"; + public $form="PhangoApp\PhaModels\CoreForms::ImageForm"; public $name_file=""; public $path=""; public $url_path=""; diff --git a/src/CoreFields/IntegerField.php b/src/CoreFields/IntegerField.php index ef750e0..2f8b92e 100644 --- a/src/CoreFields/IntegerField.php +++ b/src/CoreFields/IntegerField.php @@ -22,7 +22,7 @@ class IntegerField extends PhangoField { { $this->size=$size; - $this->form='CoreForms::TextForm'; + $this->form='PhangoApp\PhaModels\CoreForms::TextForm'; $this->only_positive=$only_positive; $this->min_num=$min_num; $this->max_num=$max_num; diff --git a/src/CoreFields/KeyField.php b/src/CoreFields/KeyField.php index 4b0a11c..23fb6d2 100644 --- a/src/CoreFields/KeyField.php +++ b/src/CoreFields/KeyField.php @@ -26,7 +26,7 @@ class KeyField extends PhangoField { { $this->size=$size; - $this->form='CoreForms::TextForm'; + $this->form='PhangoApp\PhaModels\CoreForms::TextForm'; } diff --git a/src/CoreFields/ParentField.php b/src/CoreFields/ParentField.php index 815e741..62aea58 100644 --- a/src/CoreFields/ParentField.php +++ b/src/CoreFields/ParentField.php @@ -17,7 +17,7 @@ class ParentField extends IntegerField{ $this->parent_model=&$parent_model; $this->size=$size; - $this->form='CoreForms::SelectForm'; + $this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; } diff --git a/src/CoreFields/PasswordField.php b/src/CoreFields/PasswordField.php index 5219a33..0083f50 100644 --- a/src/CoreFields/PasswordField.php +++ b/src/CoreFields/PasswordField.php @@ -18,7 +18,7 @@ class PasswordField extends CharField { { $this->size=$size; - $this->form='CoreForms::PasswordForm'; + $this->form='PhangoApp\PhaModels\CoreForms::PasswordForm'; } diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index 13b8c09..cca1810 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -87,7 +87,7 @@ class PhangoField { * Form define the function for use in forms... */ - public $form="CoreForms::TextForm"; + public $form="PhangoApp\PhaModels\CoreForms::TextForm"; /** * Array for create initial parameters for form.. diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index a2d7eb2..6970e1f 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -33,7 +33,7 @@ class PrimaryField extends PhangoField { * By default, the form used for this field is HiddenForm. */ - public $form="CoreForms::HiddenForm"; + public $form="PhangoApp\PhaModels\CoreForms::HiddenForm"; /** * Check function that convert the value on a PrimaryField value. diff --git a/src/CoreFields/TextField.php b/src/CoreFields/TextField.php index 23d4edf..62b1d4e 100644 --- a/src/CoreFields/TextField.php +++ b/src/CoreFields/TextField.php @@ -22,7 +22,7 @@ class TextField extends PhangoField { function __construct($multilang=0) { - $this->form='CoreForms::TextAreaForm'; + $this->form='PhangoApp\PhaModels\CoreForms::TextAreaForm'; $this->multilang=$multilang; } diff --git a/src/CoreFields/TextHTMLField.php b/src/CoreFields/TextHTMLField.php index 9ca4f02..1db8cec 100644 --- a/src/CoreFields/TextHTMLField.php +++ b/src/CoreFields/TextHTMLField.php @@ -25,7 +25,7 @@ class TextHTMLField extends PhangoField { function __construct($multilang=0) { - $this->form='CoreForms::TextAreaForm'; + $this->form='PhangoApp\PhaModels\CoreForms::TextAreaForm'; $this->multilang=$multilang; $this->set_safe_html_tags(); diff --git a/src/ExtraModels/UserPhangoModel.php b/src/ExtraModels/UserPhangoModel.php index a4a5623..452a3e1 100644 --- a/src/ExtraModels/UserPhangoModel.php +++ b/src/ExtraModels/UserPhangoModel.php @@ -13,6 +13,7 @@ namespace PhangoApp\PhaModels\ExtraModels; use PhangoApp\Phai18n\I18n; use PhangoApp\PhaModels\Webmodel; +use PhangoApp\PhaUtils\Utils; I18n::load_lang('users'); From 9f35b00fed993717ef01020a511cec6ff2a0fb83 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 22 Aug 2015 05:48:21 +0200 Subject: [PATCH 27/43] Fixes for the new behaviour and set forms methods --- extensions/element_exists.php | 4 +- extensions/select_a_field.php | 4 +- extensions/select_a_row.php | 6 +- extensions/select_a_row_where.php | 6 +- extensions/select_to_array.php | 4 +- src/ModelForm.php | 3 +- src/Webmodel.php | 138 ++++++++++++++++++++++++++++-- 7 files changed, 150 insertions(+), 15 deletions(-) diff --git a/extensions/element_exists.php b/extensions/element_exists.php index 8f1277f..9e9fbc0 100644 --- a/extensions/element_exists.php +++ b/extensions/element_exists.php @@ -30,7 +30,9 @@ function element_exists_method_class($class, $idrow, $field_search='') settype($idrow, 'integer'); - $num_elements=$class->select_count('where '.$field_search.'=\''.$idrow.'\'', $class->idmodel); + $class->set_conditions('where '.$field_search.'=\''.$idrow.'\''); + + $num_elements=$class->select_count($class->idmodel); return $num_elements; diff --git a/extensions/select_a_field.php b/extensions/select_a_field.php index af86115..7742bae 100644 --- a/extensions/select_a_field.php +++ b/extensions/select_a_field.php @@ -19,12 +19,12 @@ * @param string $field The field where search. */ -function select_a_field_method_class($class, $where, $field) +function select_a_field_method_class($class, $field) { $arr_field=array(); - $query=$class->select($where, array($field), $raw_query=1); + $query=$class->select(array($field), $raw_query=1); while(list($field_choose)=$class->fetch_row($query)) { diff --git a/extensions/select_a_row.php b/extensions/select_a_row.php index d351f55..1b69055 100644 --- a/extensions/select_a_row.php +++ b/extensions/select_a_row.php @@ -27,7 +27,11 @@ function select_a_row_method_class($class, $idrow, $arr_select=array(), $raw_que settype($idrow, 'integer'); - $query=$class->select('where '.$class->name.'.`'.$class->idmodel.'`=\''.$idrow.'\'', $arr_select, $raw_query); + $class->set_conditions('where '.$class->name.'.`'.$class->idmodel.'`=\''.$idrow.'\''); + + $class->set_limit('limit 1'); + + $query=$class->select($arr_select, $raw_query); return $class->fetch_array($query, $assoc); diff --git a/extensions/select_a_row_where.php b/extensions/select_a_row_where.php index 3ab27c8..34ce994 100644 --- a/extensions/select_a_row_where.php +++ b/extensions/select_a_row_where.php @@ -23,12 +23,14 @@ */ -function select_a_row_where_method_class($class, $where, $arr_select=array(), $raw_query=0, $assoc=0) +function select_a_row_where_method_class($class, $arr_select=array(), $raw_query=0, $assoc=0) { settype($idrow, 'integer'); - $query=$class->select($where, $arr_select, $raw_query); + $query=$class->select($arr_select, $raw_query); + + $class->set_limit('limit 1'); return $class->fetch_array($query, $assoc); diff --git a/extensions/select_to_array.php b/extensions/select_to_array.php index 3fb054d..6fa83e9 100644 --- a/extensions/select_to_array.php +++ b/extensions/select_to_array.php @@ -22,7 +22,7 @@ * */ -function select_to_array_method_class($class, $where="", $arr_select=array(), $raw_query=0, $index_id='') +function select_to_array_method_class($class, $arr_select=array(), $raw_query=0, $index_id='') { $arr_return=array(); @@ -43,7 +43,7 @@ function select_to_array_method_class($class, $where="", $arr_select=array(), $r } - $query=$class->select($where, $arr_select, $raw_query); + $query=$class->select($arr_select, $raw_query); while($arr_row=$class->fetch_array($query)) { diff --git a/src/ModelForm.php b/src/ModelForm.php index b179cfd..eb9cd40 100644 --- a/src/ModelForm.php +++ b/src/ModelForm.php @@ -221,7 +221,8 @@ class ModelForm { $func_setvalue=$this->form.'Set'; - $this->parameters[2]=$func_setvalue($this->parameters[2], $value, $form_type_set); + //$this->parameters[2]=$func_setvalue($this->parameters[2], $value, $form_type_set); + $this->parameters[2]=call_user_func_array($func_setvalue, array($this->parameters[2], $value, $form_type_set)); } diff --git a/src/Webmodel.php b/src/Webmodel.php index 9c39a5b..f5c698d 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -236,6 +236,34 @@ class Webmodel { static public $model=array(); + /** + * A string where is saved the conditions used for create queries + * + */ + + protected $conditions='WHERE 1=1'; + + /** + * A string where is set the order of query + * + */ + + protected $order_by=''; + + /** + * A string where is saved the limit of rows in query + * + */ + + protected $limit=''; + + /** + * A string where is saved the limit of rows in query + * + */ + + protected $reset_conditions=true; + /** * Internal arrays for create new indexes in the tables * @@ -494,6 +522,53 @@ class Webmodel { return SQLClass::webtsys_query($sql_query, $this->db_selected); } + public function set_conditions($conditions, $order_by='', $limit='') + { + + $conditions=trim($conditions); + + if($conditions=='') + { + + $this->conditions="WHERE 1=1"; + + } + else + { + + $this->conditions=$conditions; + + } + + $this->order_by=$order_by; + + } + + public function set_order($order_by) + { + + $this->order_by=$order_by; + + } + + public function set_limit($limit) + { + + $this->limit=$limit; + + } + + public function reset_conditions() + { + + $this->conditions='WHERE 1=1'; + + $this->order_by='order by '.$this->idmodel.' ASC'; + + $this->limit=''; + + } + /** * This method insert a row in database using model how mirage of table. * @@ -563,11 +638,20 @@ class Webmodel { * @param $conditions is a string containing a sql string beginning by "where". Example: where id=1. */ - public function update($post, $conditions="") + public function update($post) { $this->set_phango_connection(); + $conditions=trim($this->conditions.' '.$this->order_by.' '.$this->limit); + + if($this->reset_conditions()==true) + { + + $this->reset_conditions(); + + } + //Make conversion from post //Check if minimal fields are fill and if fields exists in components. @@ -683,7 +767,7 @@ class Webmodel { * @param $raw_query If set to 0, you obtain fields from table related if you selected a foreignkey field, if set to 1, you obtain an array without any join. */ - public function select($conditions="", $arr_select=array(), $raw_query=0) + public function select($arr_select=array(), $raw_query=0) { //Check conditions.., script must check, i can't make all things!, i am not a machine! @@ -801,7 +885,7 @@ class Webmodel { //$conditions is a variable where store the result from $arr_select and $arr_extra_select - if(preg_match('/^where/', $conditions) || preg_match('/^WHERE/', $conditions)) + /*if(preg_match('/^where/', $conditions) || preg_match('/^WHERE/', $conditions)) { $conditions=str_replace('where', '', $conditions); @@ -815,7 +899,23 @@ class Webmodel { $conditions='WHERE '.$where.' '.$conditions; + }*/ + + if($where!='') + { + + $where=' and '.$where; + } + + $conditions=trim($this->conditions.$where.' '.$this->order_by.' '.$this->limit); + + if($this->reset_conditions()==true) + { + + $this->reset_conditions(); + + } //$this->create_extra_fields(); @@ -856,7 +956,7 @@ class Webmodel { * @param string $fields_for_count Array for fields used for simple counts based on foreignkeyfields. */ - public function select_count($conditions, $field='', $fields_for_count=array()) + public function select_count($field='', $fields_for_count=array()) { $this->set_phango_connection(); @@ -915,6 +1015,23 @@ class Webmodel { $where=implode(" and ", $arr_where); + if($where!='') + { + + $where=' and '.$where; + + } + + $conditions=trim($this->conditions.$where.' '.$this->order_by.' '.$this->limit); + + if($this->reset_conditions()==true) + { + + $this->reset_conditions(); + + } + + /* if(preg_match('/^where/', $conditions) || preg_match('/^WHERE/', $conditions)) { @@ -929,7 +1046,7 @@ class Webmodel { $conditions='WHERE '.$where.' '.$conditions; - } + }*/ $query=SQLClass::webtsys_query('select count('.$this->name.'.`'.$field.'`) from '.implode(', ', $arr_model).' '.$conditions, $this->db_selected); @@ -947,10 +1064,19 @@ class Webmodel { * @param string $conditions Conditions have same sintax that $conditions from $this->select method */ - public function delete($conditions="") + public function delete() { $this->set_phango_connection(); + + $conditions=trim($this->conditions.' '.$this->order_by.' '.$this->limit); + + if($this->reset_conditions()==true) + { + + $this->reset_conditions(); + + } foreach($this->components as $name_field => $component) { From faa1d76350b941b4a57920f6d6d349338e664f83 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Mon, 24 Aug 2015 01:34:21 +0200 Subject: [PATCH 28/43] Fixes on webmodel --- src/CoreFields/PhangoField.php | 6 ++++++ src/Webmodel.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index cca1810..5a9567b 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -95,6 +95,12 @@ class PhangoField { public $parameters=array(); + /** + * A method used for set if this field can be update or insert by everyone. + */ + + public $protected=false; + /** * Method used for internal tasks related with searchs. You can overwrite this method in your PhangoField object if you need translate the value that the user want search to a real value into the database. */ diff --git a/src/Webmodel.php b/src/Webmodel.php index f5c698d..8c5dd16 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -262,7 +262,7 @@ class Webmodel { * */ - protected $reset_conditions=true; + public $reset_conditions=true; /** * Internal arrays for create new indexes in the tables From 1cc3c8cf3402d08b8271ffc9eca888f3a2a72d98 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 25 Aug 2015 18:10:49 +0200 Subject: [PATCH 29/43] Modify the forms system --- src/CoreFields/ForeignKeyField.php | 34 ++----------- src/CoreFields/PhangoField.php | 22 +++++++++ src/CoreFields/PrimaryField.php | 6 +++ src/Forms/BaseForm.php | 44 +++++++++++++++++ src/Webmodel.php | 77 +++++++++++------------------- 5 files changed, 106 insertions(+), 77 deletions(-) create mode 100644 src/Forms/BaseForm.php diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index 88323c0..c934103 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -18,14 +18,13 @@ class ForeignKeyField extends IntegerField{ //field related in the model... public $related_model=''; public $container_model=''; - public $null_relation=1; public $params_loading_mod=array(); public $default_id=0; public $yes_zero=0; public $fields_related_model; public $name_field_to_field; - function __construct($related_model, $size=11, $null_relation=1, $default=0) + function __construct($related_model, $size=11, $default=0) { $this->size=$size; @@ -38,10 +37,8 @@ class ForeignKeyField extends IntegerField{ $this->name_field_to_field=''; $this->null_relation=$null_relation; $this->default_id=$default; - - //PhangoVar::$model[$related_model]->related_models_delete[]=array('model' => $this->name_model, 'related_field' => $this->name_component); - - //echo get_parent_class(); + $this->quot_open=''; + $this->quot_close=''; } @@ -56,8 +53,6 @@ class ForeignKeyField extends IntegerField{ } else { - - //show_error('You need load model before set relantionship', $this->related_model.' model not exists. You need load model before set relantionship with ForeignKeyField with '.$this->name_model.' model', $output_external=''); throw new \Exception($this->related_model.' model not exists. You need load model before set relantionship with ForeignKeyField with '.$this->name_model.' model'); @@ -86,13 +81,6 @@ class ForeignKeyField extends IntegerField{ if($num_rows>0) { - - if($value==0 && $this->yes_zero==0) - { - - return NULL; - - } return $value; @@ -100,18 +88,9 @@ class ForeignKeyField extends IntegerField{ else { - if($this->default_id<=0 && $this->yes_zero==0) - { - return NULL; - - } - else - { + return $this->default_id; - return $this->default_id; - - } } @@ -130,11 +109,8 @@ class ForeignKeyField extends IntegerField{ function get_type_sql() { - - $arr_null[0]='NOT NULL'; - $arr_null[1]='NULL'; - return 'INT('.$this->size.') '.$arr_null[$this->null_relation]; + return 'INT('.$this->size.') NOT NULL DEFAULT "0"'; } diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index 5a9567b..c6a5447 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -101,6 +101,12 @@ class PhangoField { public $protected=false; + /** + * A property that set the default value + */ + + public $default_value=''; + /** * Method used for internal tasks related with searchs. You can overwrite this method in your PhangoField object if you need translate the value that the user want search to a real value into the database. */ @@ -158,6 +164,22 @@ class PhangoField { } + /** + * Method for create a form, you only need subclass the field if you want another form different to default + */ + + public function create_form() + { + + $form=new BaseForm($this->name, $this->value); + $form->default_value=$this->default_value; + $form->required=$this->required; + $form->label=$this->label; + + return $form; + + } + } diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index 6970e1f..160e760 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -35,6 +35,12 @@ class PrimaryField extends PhangoField { public $form="PhangoApp\PhaModels\CoreForms::HiddenForm"; + /** + * By default this field is protected. + */ + + public $protected=true; + /** * Check function that convert the value on a PrimaryField value. * diff --git a/src/Forms/BaseForm.php b/src/Forms/BaseForm.php new file mode 100644 index 0000000..5914ba8 --- /dev/null +++ b/src/Forms/BaseForm.php @@ -0,0 +1,44 @@ +label=name; + $this->name=name; + $this->default_value=value; + $this->css=''; + $this->type='text'; + $this->required=0; + } + + public function form() + { + + return ''; + + } + + #Method for escape value for html input + + public function setform(value) + { + + return value.replace('"', '"') + + } +} + +?> \ No newline at end of file diff --git a/src/Webmodel.php b/src/Webmodel.php index 8c5dd16..edd3096 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -4,6 +4,7 @@ namespace PhangoApp\PhaModels; use PhangoApp\PhaI18n\I18n; use PhangoApp\PhaModels\CoreFields\PrimaryField; +use PhangoApp\PhaModels\Forms\BaseForm; /** * The most important class for the framework @@ -173,7 +174,7 @@ class Webmodel { /** * - * If you checked the values that you going to save on your model, please, put this value to 1 or true. + * If you checked the values that you going to save on your model, please, put this value to 1 or 1. * */ @@ -262,7 +263,7 @@ class Webmodel { * */ - public $reset_conditions=true; + public $reset_conditions=1; /** * Internal arrays for create new indexes in the tables @@ -577,7 +578,7 @@ class Webmodel { * @param array $post Is an array with data to insert. You have a key that represent the name of field to fill with data, and the value that is the data for fill. */ - public function insert($post) + public function insert($post, $safe_query=0) { $this->set_phango_connection(); @@ -587,17 +588,18 @@ class Webmodel { $post=$this->unset_no_required($post); //Check if minimal fields are fill and if fields exists in components.Check field's values. - + /* if(!$this->modify_id) { unset($post[$this->idmodel]); } + */ $arr_fields=array(); - if( $fields=$this->check_all($post) ) + if( $fields=$this->check_all($post, $safe_query) ) { if( !( $query=SQLClass::webtsys_query($this->prepare_insert_sql($fields), $this->db_selected) ) ) @@ -638,14 +640,14 @@ class Webmodel { * @param $conditions is a string containing a sql string beginning by "where". Example: where id=1. */ - public function update($post) + public function update($post, $safe_query=0) { $this->set_phango_connection(); $conditions=trim($this->conditions.' '.$this->order_by.' '.$this->limit); - if($this->reset_conditions()==true) + if($this->reset_conditions==1) { $this->reset_conditions(); @@ -671,7 +673,7 @@ class Webmodel { //Checking and sanitizing data from $post array for use in the query - if( $fields=$this->check_all($post) ) + if( $fields=$this->check_all($post, $safe_query) ) { //Foreach for create the query that comes from the $post array @@ -684,6 +686,7 @@ class Webmodel { $quot_open=$component->quot_open; $quot_close=$component->quot_close; + /* if(get_class($component)=='ForeignKeyField' && $fields[$key]==NULL) { @@ -691,7 +694,7 @@ class Webmodel { $quot_close=''; $fields[$key]='NULL'; - } + }*/ $arr_fields[]='`'.$key.'`='.$quot_open.$fields[$key].$quot_close; @@ -910,7 +913,7 @@ class Webmodel { $conditions=trim($this->conditions.$where.' '.$this->order_by.' '.$this->limit); - if($this->reset_conditions()==true) + if($this->reset_conditions==1) { $this->reset_conditions(); @@ -1024,7 +1027,7 @@ class Webmodel { $conditions=trim($this->conditions.$where.' '.$this->order_by.' '.$this->limit); - if($this->reset_conditions()==true) + if($this->reset_conditions==1) { $this->reset_conditions(); @@ -1071,7 +1074,7 @@ class Webmodel { $conditions=trim($this->conditions.' '.$this->order_by.' '.$this->limit); - if($this->reset_conditions()==true) + if($this->reset_conditions==1) { $this->reset_conditions(); @@ -1181,7 +1184,7 @@ class Webmodel { //Check if indexed - if($this->components[$field]->indexed==true) + if($this->components[$field]->indexed==1) { Webmodel::$arr_sql_index[$this->name][$field]='CREATE INDEX `index_'.$this->name.'_'.$field.'` ON '.$this->name.'(`'.$field.'`);'; @@ -1191,7 +1194,7 @@ class Webmodel { //Check if unique - if($this->components[$field]->unique==true) + if($this->components[$field]->unique==1) { Webmodel::$arr_sql_unique[$this->name][$field]=' ALTER TABLE `'.$this->name.'` ADD UNIQUE (`'.$field.'`)'; @@ -1389,7 +1392,7 @@ class Webmodel { * @param array $post Is an array with data to update. You have a key that represent the name of field to fill with data, and the value that is the data for fill. */ - public function check_all($post) + public function check_all($post, $safe_query=0) { I18n::load_lang('error_model'); @@ -1413,12 +1416,12 @@ class Webmodel { //Make a foreach inside components, fields that are not found in components, are ignored - foreach($this->components as $key => $value) + foreach($this->components as $key => $field) { //If is set the variable for this component make checking - if(isset($post[$key])) + if(isset($post[$key]) && ($field->protected==0 || $safe_query==1)) { //Check if the value is valid.. @@ -1469,7 +1472,7 @@ class Webmodel { $this->std_error=implode(', ', $arr_std_error); - //If error return false + //If error return 0 if($set_error>0) { @@ -1520,7 +1523,7 @@ class Webmodel { * @param array $fields_form The values of this array are used for obtain ModelForms from the fields with the same key that array values. */ - public function create_form($fields_form=array()) + public function create_forms($fields_form=array()) { //With function for create form, we use an array for specific order, after i can insert more fields in the form. @@ -1543,38 +1546,16 @@ class Webmodel { if(isset($this->components[$component_name])) { - $component=&$this->components[$component_name]; + if($this->components[$component_name]->label=='') + { + + $this->components[$component_name]->label=ucfirst($component_name); + + } - //Create form from model's components - - $this->forms[$component_name]=new ModelForm($this->name, $component_name, $component->form, Webmodel::set_name_default($component_name), $component, $component->required, ''); + $this->forms[$component_name]=$this->components[$component_name]->create_form(); - $this->forms[$component_name]->set_all_parameters_form($component->get_parameters_default()); - - if($this->components[$component_name]->label=='') - { - - $this->components[$component_name]->label=ucfirst($component_name); - - } - - $this->forms[$component_name]->label=$this->components[$component_name]->label; - //Set parameters to default - //$parameters_value=$this->components[$component_name]->parameters; - - /*if($this->forms[$component_name]->parameters[2]==0) - {*/ - - //$this->forms[$component_name]->parameters=$this->components[$component_name]->parameters; - - - //} - - //Use method from ModelForm for set initial parameters... - - //$this->forms[$component_name]->set_parameter_value($parameters_initial_value); - } } From 195e6ab4809111e11514c3ec5105b62087a7095e Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 25 Aug 2015 18:12:07 +0200 Subject: [PATCH 30/43] Modify the forms system --- src/CoreFields/PhangoField.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index c6a5447..b22533f 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -14,6 +14,7 @@ */ namespace PhangoApp\PhaModels\CoreFields; +namespace PhangoApp\PhaModels\Forms\BaseForm; use PhangoApp\PhaUtils\Utils; class PhangoField { From 31caf897f02d19ee67671e5daaf804fee391f8c0 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 25 Aug 2015 18:12:46 +0200 Subject: [PATCH 31/43] Modify the forms system --- src/CoreFields/PhangoField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index b22533f..78792e1 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -14,7 +14,7 @@ */ namespace PhangoApp\PhaModels\CoreFields; -namespace PhangoApp\PhaModels\Forms\BaseForm; +namespace PhangoApp\PhaModels\Forms; use PhangoApp\PhaUtils\Utils; class PhangoField { From 7ab106db6239a6f857da6d161b19ba7f7438d0cd Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 25 Aug 2015 18:13:09 +0200 Subject: [PATCH 32/43] Modify the forms system --- src/CoreFields/PhangoField.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index 78792e1..8f45363 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -14,7 +14,7 @@ */ namespace PhangoApp\PhaModels\CoreFields; -namespace PhangoApp\PhaModels\Forms; +use PhangoApp\PhaModels\Forms\BaseForm; use PhangoApp\PhaUtils\Utils; class PhangoField { From 7be0c015882230cadeb19209bdfa583004b86593 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Tue, 25 Aug 2015 21:36:07 +0200 Subject: [PATCH 33/43] Added new form type --- src/CoreFields/PasswordField.php | 19 +++++++++++++++++++ src/CoreFields/PhangoField.php | 2 +- src/CoreFields/PrimaryField.php | 18 ++++++++++++++++++ src/Forms/BaseForm.php | 21 +++++++++++++-------- src/Webmodel.php | 20 ++++++++++++++++---- 5 files changed, 67 insertions(+), 13 deletions(-) diff --git a/src/CoreFields/PasswordField.php b/src/CoreFields/PasswordField.php index 0083f50..48e6b11 100644 --- a/src/CoreFields/PasswordField.php +++ b/src/CoreFields/PasswordField.php @@ -9,6 +9,7 @@ */ namespace PhangoApp\PhaModels\CoreFields; +use PhangoApp\PhaModels\Forms\BaseForm; use PhangoApp\PhaUtils\Utils; class PasswordField extends CharField { @@ -63,6 +64,24 @@ class PasswordField extends CharField { return false; } + + /** + * By default primaryfield use a hidden form + */ + + public function create_form() + { + + $form=new BaseForm($this->name_component, $this->value); + $form->default_value=$this->default_value; + $form->required=$this->required; + $form->label=$this->label; + $form->type='password'; + + return $form; + + } + } diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index 8f45363..f4a0818 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -172,7 +172,7 @@ class PhangoField { public function create_form() { - $form=new BaseForm($this->name, $this->value); + $form=new BaseForm($this->name_component, $this->value); $form->default_value=$this->default_value; $form->required=$this->required; $form->label=$this->label; diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index 160e760..5afc787 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -2,6 +2,7 @@ namespace PhangoApp\PhaModels\CoreFields; use PhangoApp\PhaUtils\Utils; +use PhangoApp\PhaModels\Forms\BaseForm; /** * PrimaryField is used for primary keys for models @@ -77,6 +78,23 @@ class PrimaryField extends PhangoField { return $value; } + + /** + * By default primaryfield use a hidden form + */ + + public function create_form() + { + + $form=new BaseForm($this->name_component, $this->value); + $form->default_value=$this->default_value; + $form->required=$this->required; + $form->label=$this->label; + $form->type='hidden'; + + return $form; + + } } diff --git a/src/Forms/BaseForm.php b/src/Forms/BaseForm.php index 5914ba8..8210eea 100644 --- a/src/Forms/BaseForm.php +++ b/src/Forms/BaseForm.php @@ -2,6 +2,8 @@ namespace PhangoApp\PhaModels\Forms; +use PhangoApp\PhaModels\CoreFields\CharField; + /** * Basic class for create forms */ @@ -14,29 +16,32 @@ class BaseForm { * @param string $name Field class instance used for check files */ - public function __construct($name, $value, $field) + public function __construct($name, $value) { - $this->label=name; - $this->name=name; - $this->default_value=value; + $this->label=$name; + $this->name=$name; + $this->default_value=$value; $this->css=''; $this->type='text'; $this->required=0; + $this->field=new CharField(); } public function form() { - return ''; + return ''; } - #Method for escape value for html input + /** + * Method for escape value for html input + */ - public function setform(value) + public function setform($value) { - return value.replace('"', '"') + return str_replace('"', '"', $value); } } diff --git a/src/Webmodel.php b/src/Webmodel.php index edd3096..9e1f4d3 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -296,6 +296,8 @@ class Webmodel { $this->name=$name_model; $this->idmodel='Id'.ucfirst($this->name); $this->components[$this->idmodel]=new PrimaryField(); + $this->components[$this->idmodel]->name_model=$name_model; + $this->components[$this->idmodel]->name_component=$this->idmodel; $this->label=$this->name; if(!isset(Webmodel::$connection_func[$this->db_selected])) @@ -1331,7 +1333,7 @@ class Webmodel { if(count($this->forms)==0) { - $this->create_form(); + $this->create_forms(); } @@ -1539,7 +1541,6 @@ class Webmodel { } - //foreach($this->components as $component_name => $component) foreach($fields_form as $component_name) { @@ -1553,14 +1554,25 @@ class Webmodel { } - $this->forms[$component_name]=$this->components[$component_name]->create_form(); - + $this->create_form($component_name); } } } + + /** + * Method for create a simple form from a field + * @param string $component_name The name of the component that is used for create the form + */ + + public function create_form($component_name) + { + + $this->forms[$component_name]=$this->components[$component_name]->create_form(); + + } /** * Method for obtain an array with all errors in components From 7dbe80697ee34743411021d831bd27867c29f105 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Wed, 26 Aug 2015 00:32:20 +0200 Subject: [PATCH 34/43] Fixes on PasswordForm --- src/CoreFields/EmailField.php | 21 +++++++++++++++++++ src/CoreFields/ForeignKeyField.php | 1 - src/CoreFields/PasswordField.php | 4 ++-- src/ExtraModels/UserPhangoModel.php | 20 ++++++++++-------- src/Forms/BaseForm.php | 4 ++++ src/Forms/PasswordForm.php | 32 +++++++++++++++++++++++++++++ src/ModelForm.php | 12 +++++------ 7 files changed, 76 insertions(+), 18 deletions(-) create mode 100644 src/Forms/PasswordForm.php diff --git a/src/CoreFields/EmailField.php b/src/CoreFields/EmailField.php index 938e56a..e3a5cfe 100644 --- a/src/CoreFields/EmailField.php +++ b/src/CoreFields/EmailField.php @@ -76,6 +76,27 @@ class EmailField extends PhangoField { return $value; } + + /** + * By default primaryfield use a hidden form + */ + + public function create_form() + { + + /*$form=new PasswordForm($this->name_component, $this->value); + $form->default_value=$this->default_value; + $form->required=$this->required; + $form->label=$this->label; + $form->type='password';*/ + + $form=parent::create_form(); + + $form->field=new EmailField(); + + return $form; + + } } diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index c934103..e9851a2 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -35,7 +35,6 @@ class ForeignKeyField extends IntegerField{ $this->fields_related_model=array(); //Representative field for related model... $this->name_field_to_field=''; - $this->null_relation=$null_relation; $this->default_id=$default; $this->quot_open=''; $this->quot_close=''; diff --git a/src/CoreFields/PasswordField.php b/src/CoreFields/PasswordField.php index 48e6b11..f05f877 100644 --- a/src/CoreFields/PasswordField.php +++ b/src/CoreFields/PasswordField.php @@ -9,7 +9,7 @@ */ namespace PhangoApp\PhaModels\CoreFields; -use PhangoApp\PhaModels\Forms\BaseForm; +use PhangoApp\PhaModels\Forms\PasswordForm; use PhangoApp\PhaUtils\Utils; class PasswordField extends CharField { @@ -72,7 +72,7 @@ class PasswordField extends CharField { public function create_form() { - $form=new BaseForm($this->name_component, $this->value); + $form=new PasswordForm($this->name_component, $this->value); $form->default_value=$this->default_value; $form->required=$this->required; $form->label=$this->label; diff --git a/src/ExtraModels/UserPhangoModel.php b/src/ExtraModels/UserPhangoModel.php index 452a3e1..5bdc673 100644 --- a/src/ExtraModels/UserPhangoModel.php +++ b/src/ExtraModels/UserPhangoModel.php @@ -29,9 +29,9 @@ class UserPhangoModel extends Webmodel { public $password='password'; public $repeat_password='repeat_password'; - public function insert($post) + public function insert($post, $safe_query=0) { - + if($this->check_user_exists($post[$this->username], $post[$this->email])) { @@ -40,13 +40,13 @@ class UserPhangoModel extends Webmodel { //$this->components['password']->required=0; - $this->components[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal'); + $this->forms[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal'); return false; } - return parent::insert($post); + return parent::insert($post, $safe_query); } else @@ -60,7 +60,7 @@ class UserPhangoModel extends Webmodel { } - public function update($post, $where_sql='') + public function update($post, $safe_query=0) { if(isset($post[$this->username]) && $post[$this->email]) @@ -74,7 +74,7 @@ class UserPhangoModel extends Webmodel { //$this->components['password']->required=0; - $this->components[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal'); + $this->forms[$this->password]->std_error=I18n::lang('users', 'pasword_not_equal_repeat_password', 'Passwords are not equal'); return false; @@ -88,7 +88,7 @@ class UserPhangoModel extends Webmodel { } - return parent::update($post, $where_sql); + return parent::update($post, $safe_query); } else @@ -104,7 +104,7 @@ class UserPhangoModel extends Webmodel { else { - return parent::update($post, $where_sql); + return parent::update($post, $safe_query); } @@ -144,7 +144,9 @@ class UserPhangoModel extends Webmodel { } - $c=$this->select_count($where_sql); + $this->set_conditions($where_sql); + + $c=$this->select_count(); if($c==0) { diff --git a/src/Forms/BaseForm.php b/src/Forms/BaseForm.php index 8210eea..4bf9edf 100644 --- a/src/Forms/BaseForm.php +++ b/src/Forms/BaseForm.php @@ -3,6 +3,7 @@ namespace PhangoApp\PhaModels\Forms; use PhangoApp\PhaModels\CoreFields\CharField; +use PhangoApp\PhaI18n\I18n; /** * Basic class for create forms @@ -16,6 +17,8 @@ class BaseForm { * @param string $name Field class instance used for check files */ + public $std_error=''; + public function __construct($name, $value) { $this->label=$name; @@ -25,6 +28,7 @@ class BaseForm { $this->type='text'; $this->required=0; $this->field=new CharField(); + $this->txt_error = I18n::lang('common', 'error_in_field', 'Error in field'); } public function form() diff --git a/src/Forms/PasswordForm.php b/src/Forms/PasswordForm.php new file mode 100644 index 0000000..c3c6140 --- /dev/null +++ b/src/Forms/PasswordForm.php @@ -0,0 +1,32 @@ +field=new PasswordField(); + + } + + public function form() + { + + return ''; + + } + +} + +?> \ No newline at end of file diff --git a/src/ModelForm.php b/src/ModelForm.php index eb9cd40..3202634 100644 --- a/src/ModelForm.php +++ b/src/ModelForm.php @@ -318,21 +318,21 @@ class ModelForm { $form=$arr_form[$key_form]; - $post[$key_form]=$form->type->check($post[$key_form]); + $post[$key_form]=$form->field->check($post[$key_form]); if($post[$key_form]=='' && $form->required==1) { - if($form->type->std_error!='') + if($form->field->std_error!='') { - $form->std_error=$form->type->std_error; + $form->std_error=$form->field->std_error; } else { - $form->std_error=$form->txt_error; + $form->std_error=I18n::lang('common', 'field_required', 'Field is required'); } @@ -390,7 +390,7 @@ class ModelForm { if(isset($arr_form[$name_field])) { - if($arr_form[$name_field]->type->std_error!='' && $show_error==1) + if($arr_form[$name_field]->field->std_error!='' && $show_error==1) { /*if($arr_form[$name_field]->std_error!='') @@ -412,7 +412,7 @@ class ModelForm { //Set value for ModelForm to $value - $arr_form[$name_field]->set_param_value_form($value); + $arr_form[$name_field]->default_value=$value; } else From 6a608f0389a821ae2b318a40bb4bd3e6d6d677dc Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 27 Aug 2015 04:30:47 +0200 Subject: [PATCH 35/43] Added SelectForm --- src/Forms/SelectForm.php | 52 ++++++++++++++++++++++++++++++++++++++++ src/ModelForm.php | 25 ++++++++++++++++--- 2 files changed, 74 insertions(+), 3 deletions(-) create mode 100644 src/Forms/SelectForm.php diff --git a/src/Forms/SelectForm.php b/src/Forms/SelectForm.php new file mode 100644 index 0000000..cdddec8 --- /dev/null +++ b/src/Forms/SelectForm.php @@ -0,0 +1,52 @@ +css.'" name="'.$this->name.'" value="">'; + $arr_selected[$this->default_value]=' selected'; + + ob_start(); + + ?> + + \ No newline at end of file diff --git a/src/ModelForm.php b/src/ModelForm.php index 3202634..39e86b6 100644 --- a/src/ModelForm.php +++ b/src/ModelForm.php @@ -393,18 +393,18 @@ class ModelForm { if($arr_form[$name_field]->field->std_error!='' && $show_error==1) { - /*if($arr_form[$name_field]->std_error!='') + if($arr_form[$name_field]->std_error!='') { $arr_form[$name_field]->std_error=$arr_form[$name_field]->txt_error; } - else*/ + else if($arr_form[$name_field]->std_error=='') { - $arr_form[$name_field]->std_error=$arr_form[$name_field]->type->std_error; + $arr_form[$name_field]->std_error=$arr_form[$name_field]->field->std_error; } @@ -413,6 +413,7 @@ class ModelForm { //Set value for ModelForm to $value $arr_form[$name_field]->default_value=$value; + } else @@ -426,6 +427,24 @@ class ModelForm { } } + + static public function pass_errors_to_form($model) + { + + foreach(array_keys($model->components) as $key) + { + + if(isset($model->forms[$key])) + { + + + $model->forms[$key]->field->std_error=$model->components[$key]->std_error; + + } + + } + + } } From f0860b413aaf163226af15a781b7aec893b7f170 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 27 Aug 2015 04:51:30 +0200 Subject: [PATCH 36/43] Fixed an inconsistency in set_values-form --- src/ModelForm.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ModelForm.php b/src/ModelForm.php index 39e86b6..8ef668b 100644 --- a/src/ModelForm.php +++ b/src/ModelForm.php @@ -375,7 +375,7 @@ class ModelForm { * @param array $show_error An option for choose if in the form is showed */ - static public function set_values_form($post, $arr_form, $show_error=1) + static public function set_values_form($arr_form, $post, $show_error=1) { //Foreach to $post values From f3b4b4e4543090e400981d3d5555774ecbb3fe9d Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 27 Aug 2015 17:25:07 +0200 Subject: [PATCH 37/43] Fixes on fields for show errors properly --- src/CoreFields/EmailField.php | 2 +- src/CoreFields/PasswordField.php | 15 +++++++++++++-- src/CoreFields/PrimaryField.php | 2 +- src/ModelForm.php | 19 ++++++++++++++++--- src/Webmodel.php | 5 ++++- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/CoreFields/EmailField.php b/src/CoreFields/EmailField.php index e3a5cfe..e6192f2 100644 --- a/src/CoreFields/EmailField.php +++ b/src/CoreFields/EmailField.php @@ -50,7 +50,7 @@ class EmailField extends PhangoField { else { - $this->std_error.='Email format error'; + $this->std_error='Email format error'; return ''; diff --git a/src/CoreFields/PasswordField.php b/src/CoreFields/PasswordField.php index f05f877..1bf0744 100644 --- a/src/CoreFields/PasswordField.php +++ b/src/CoreFields/PasswordField.php @@ -35,9 +35,13 @@ class PasswordField extends CharField { } + /* $token_pass=Utils::generate_random_password(); $hash_password=$token_pass.'_'.sha1($token_pass.'_'.$value); + */ + + $hash_password=password_hash($value, PASSWORD_DEFAULT); return $hash_password; @@ -50,8 +54,8 @@ class PasswordField extends CharField { //If pass have _ check if work fine... - $token_pass=preg_replace('/(.*)[_].*/', '$1', $hash_password_check); - + //$token_pass=preg_replace('/(.*)[_].*/', '$1', $hash_password_check); + /* $hash_password=$token_pass.'_'.sha1($token_pass.'_'.$value); if($hash_password==$hash_password_check) @@ -59,6 +63,13 @@ class PasswordField extends CharField { return true; + }*/ + + if(password_verify($value, $hash_password_check)) + { + + return true; + } return false; diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index 5afc787..fdbd373 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -22,7 +22,7 @@ class PrimaryField extends PhangoField { * Initial label for the field. The label is used for create forms from a PhangoField. */ - public $label=""; + public $label="#ID"; /** * Boolean value that is used for check if the field is required for fill a row in the db model. diff --git a/src/ModelForm.php b/src/ModelForm.php index 8ef668b..c0bbddd 100644 --- a/src/ModelForm.php +++ b/src/ModelForm.php @@ -327,7 +327,7 @@ class ModelForm { { $form->std_error=$form->field->std_error; - + } else { @@ -390,9 +390,9 @@ class ModelForm { if(isset($arr_form[$name_field])) { - if($arr_form[$name_field]->field->std_error!='' && $show_error==1) + if($show_error==1) { - + /* if($arr_form[$name_field]->std_error!='') { @@ -406,7 +406,20 @@ class ModelForm { $arr_form[$name_field]->std_error=$arr_form[$name_field]->field->std_error; + }*/ + + if($arr_form[$name_field]->field->std_error!='') + { + + $arr_form[$name_field]->std_error=$arr_form[$name_field]->field->std_error; + } + /*else + { + + + + }*/ } diff --git a/src/Webmodel.php b/src/Webmodel.php index 9e1f4d3..5399db6 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -608,6 +608,7 @@ class Webmodel { { $this->std_error.=I18n::lang('error_model', 'cant_insert', 'Can\'t insert').' '; + ModelForm::pass_errors_to_form($this); return 0; } @@ -621,6 +622,7 @@ class Webmodel { else { + ModelForm::pass_errors_to_form($this); $this->std_error.=I18n::lang('error_model', 'cant_insert', 'Can\'t insert').' '; return 0; @@ -734,6 +736,7 @@ class Webmodel { { $this->std_error.=I18n::lang('error_model', 'cant_update', 'Can\'t update').' '; + ModelForm::pass_errors_to_form($this); return 0; } @@ -747,7 +750,7 @@ class Webmodel { else { //Validation of $post fail, add error to $model->std_error - + ModelForm::pass_errors_to_form($this); $this->std_error.=I18n::lang('error_model', 'cant_update', 'Can\'t update').' '; return 0; From 2a342ad9f98520e6f82da4399ca45b4e1854603a Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Thu, 27 Aug 2015 22:30:43 +0200 Subject: [PATCH 38/43] Added length test to PasswordField --- src/CoreFields/PasswordField.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/CoreFields/PasswordField.php b/src/CoreFields/PasswordField.php index 1bf0744..a40a3c1 100644 --- a/src/CoreFields/PasswordField.php +++ b/src/CoreFields/PasswordField.php @@ -11,13 +11,14 @@ namespace PhangoApp\PhaModels\CoreFields; use PhangoApp\PhaModels\Forms\PasswordForm; use PhangoApp\PhaUtils\Utils; +use PhangoApp\PhaI18n\I18n; class PasswordField extends CharField { function __construct($size=255) { - + $this->min_length=5; $this->size=$size; $this->form='PhangoApp\PhaModels\CoreForms::PasswordForm'; @@ -41,6 +42,15 @@ class PasswordField extends CharField { $hash_password=$token_pass.'_'.sha1($token_pass.'_'.$value); */ + if(strlen($value)<$this->min_length) + { + + $this->std_error=I18n::lang('common', 'password_min_length', 'Minimal password length:').' '.$this->min_length; + + return ''; + + } + $hash_password=password_hash($value, PASSWORD_DEFAULT); return $hash_password; From 890704010bd186e0e6e2389dbaa3494bc48c58fc Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Fri, 28 Aug 2015 05:24:58 +0200 Subject: [PATCH 39/43] Fixes on fields for new behaviour --- src/CoreFields/BooleanField.php | 2 +- src/CoreFields/CharField.php | 2 +- src/CoreFields/ChoiceField.php | 29 ++++++++++++++++++++++------- src/CoreFields/DateField.php | 2 +- src/CoreFields/DoubleField.php | 2 +- src/CoreFields/EmailField.php | 2 +- src/CoreFields/FileField.php | 2 +- src/CoreFields/ForeignKeyField.php | 6 ++++-- src/CoreFields/ImageField.php | 2 +- src/CoreFields/IntegerField.php | 2 +- src/CoreFields/KeyField.php | 2 +- src/CoreFields/ParentField.php | 2 +- src/CoreFields/PasswordField.php | 2 +- src/CoreFields/PhangoField.php | 7 ++++--- src/CoreFields/PrimaryField.php | 6 +++--- src/CoreFields/SerializeField.php | 2 +- src/CoreFields/TextField.php | 2 +- src/CoreFields/TextHTMLField.php | 2 +- src/ExtraModels/UserPhangoModel.php | 11 ++++++++++- src/Forms/SelectForm.php | 2 +- src/Webmodel.php | 25 ++++++++++++++++++++----- 21 files changed, 78 insertions(+), 36 deletions(-) diff --git a/src/CoreFields/BooleanField.php b/src/CoreFields/BooleanField.php index 862b587..886722a 100644 --- a/src/CoreFields/BooleanField.php +++ b/src/CoreFields/BooleanField.php @@ -24,7 +24,7 @@ class BooleanField extends PhangoField { { $this->size=1; - $this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; + $this->form=public $form='PhangoApp\PhaModels\Forms\SelectForm'; } diff --git a/src/CoreFields/CharField.php b/src/CoreFields/CharField.php index 4bb0b77..01ca582 100644 --- a/src/CoreFields/CharField.php +++ b/src/CoreFields/CharField.php @@ -31,7 +31,7 @@ class CharField extends PhangoField { { $this->size=$size; - $this->form='PhangoApp\PhaModels\CoreForms::TextForm'; + $this->form='PhangoApp\PhaModels\Forms\BaseForm'; } diff --git a/src/CoreFields/ChoiceField.php b/src/CoreFields/ChoiceField.php index f4e7952..62e97e2 100644 --- a/src/CoreFields/ChoiceField.php +++ b/src/CoreFields/ChoiceField.php @@ -3,6 +3,7 @@ namespace PhangoApp\PhaModels\CoreFields; use PhangoApp\PhaUtils\Utils; use PhangoApp\PhaI18n\I18n; +use PhangoApp\PhaModels\Forms\SelectForm; /** * @@ -14,7 +15,6 @@ class ChoiceField extends PhangoField { public $value=0; public $label=""; public $required=0; - public $form=""; public $quot_open='\''; public $quot_close='\''; public $std_error=''; @@ -22,18 +22,18 @@ class ChoiceField extends PhangoField { public $arr_values=array(); public $arr_formatted=array(); public $default_value=''; - + public $form='PhangoApp\PhaModels\Forms\SelectForm'; function __construct($size=11, $type='integer', $arr_values=array(), $default_value='') { $this->size=$size; - $this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; $this->type=$type; $this->arr_values=$arr_values; $this->default_value=$default_value; - $this->arr_formatted['']=''; + $this->arr_formatted['']=I18n::lang('common', 'none_selected', 'None selected'); + foreach($arr_values as $value) { @@ -119,11 +119,13 @@ class ChoiceField extends PhangoField { public function show_formatted($value) { + + $this->restart_formatted(); return $this->arr_formatted[$value]; } - + /* function get_parameters_default() { @@ -145,13 +147,26 @@ class ChoiceField extends PhangoField { else { - $arr_values=array(0, 'Option 1', 0, 'Option 2', 1); + $arr_values=array(0 => 'Option 1', 1 => 'Option 2'); } return array($this->name_component, '', $arr_values); - } + }*/ + /* + public function create_form() + { + + $form=new SelectForm($this->name_component, $this->value); + $form->default_value=$this->default_value; + $form->required=$this->required; + $form->label=$this->label; + $form->arr_select=$this->arr_formatted; + + return $form; + + }*/ } diff --git a/src/CoreFields/DateField.php b/src/CoreFields/DateField.php index 157724f..8d5310c 100644 --- a/src/CoreFields/DateField.php +++ b/src/CoreFields/DateField.php @@ -23,7 +23,7 @@ class DateField extends PhangoField { { $this->size=$size; - $this->form='PhangoApp\PhaModels\CoreForms::DateForm'; + $this->form='PhangoApp\PhaModels\CoreForms\DateForm'; } diff --git a/src/CoreFields/DoubleField.php b/src/CoreFields/DoubleField.php index 57ba60c..ea14404 100644 --- a/src/CoreFields/DoubleField.php +++ b/src/CoreFields/DoubleField.php @@ -22,7 +22,7 @@ class DoubleField extends PhangoField { { $this->size=$size; - $this->form='PhangoApp\PhaModels\CoreForms::TextForm'; + $this->form='PhangoApp\PhaModels\Forms\BaseForm'; } diff --git a/src/CoreFields/EmailField.php b/src/CoreFields/EmailField.php index e6192f2..073019b 100644 --- a/src/CoreFields/EmailField.php +++ b/src/CoreFields/EmailField.php @@ -12,7 +12,7 @@ class EmailField extends PhangoField { public $size=200; public $value=""; public $label=""; - public $form="PhangoApp\PhaModels\CoreForms::TextForm"; + public $form='PhangoApp\PhaModels\Forms\BaseForm'; public $class=""; public $required=0; public $quot_open='\''; diff --git a/src/CoreFields/FileField.php b/src/CoreFields/FileField.php index 9709a76..950af99 100644 --- a/src/CoreFields/FileField.php +++ b/src/CoreFields/FileField.php @@ -12,7 +12,7 @@ class FileField extends PhangoField { public $value=""; public $label=""; public $required=0; - public $form="PhangoApp\PhaModels\CoreForms::FileForm"; + public $form='PhangoApp\PhaModels\Forms\BaseForm'; public $name_file=""; public $path=""; public $url_path=""; diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index e9851a2..69f91dc 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -28,7 +28,7 @@ class ForeignKeyField extends IntegerField{ { $this->size=$size; - $this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; + $this->form='PhangoApp\PhaModels\Forms\SelectForm'; $this->related_model=&$related_model; $this->container_model=$this->related_model->name; //Fields obtained from related_model if you make a query... @@ -76,7 +76,9 @@ class ForeignKeyField extends IntegerField{ //Need checking if the value exists with a select_count - $num_rows=$this->related_model->select_count('where '.$this->related_model.'.'.$this->related_model->idmodel.'='.$value, $this->related_model->idmodel); + $this->related_model->set_conditions('where '.$this->related_model->name.'.'.$this->related_model->idmodel.'='.$value); + + $num_rows=$this->related_model->select_count(); if($num_rows>0) { diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php index 9d72a9b..97ddfad 100644 --- a/src/CoreFields/ImageField.php +++ b/src/CoreFields/ImageField.php @@ -15,7 +15,7 @@ class ImageField extends PhangoField { public $value=""; public $label=""; public $required=0; - public $form="PhangoApp\PhaModels\CoreForms::ImageForm"; + public $form='PhangoApp\PhaModels\Forms\BaseForm'; public $name_file=""; public $path=""; public $url_path=""; diff --git a/src/CoreFields/IntegerField.php b/src/CoreFields/IntegerField.php index 2f8b92e..864f4c7 100644 --- a/src/CoreFields/IntegerField.php +++ b/src/CoreFields/IntegerField.php @@ -22,7 +22,7 @@ class IntegerField extends PhangoField { { $this->size=$size; - $this->form='PhangoApp\PhaModels\CoreForms::TextForm'; + $this->form='PhangoApp\PhaModels\Forms\BaseForm'; $this->only_positive=$only_positive; $this->min_num=$min_num; $this->max_num=$max_num; diff --git a/src/CoreFields/KeyField.php b/src/CoreFields/KeyField.php index 23fb6d2..215ab72 100644 --- a/src/CoreFields/KeyField.php +++ b/src/CoreFields/KeyField.php @@ -26,7 +26,7 @@ class KeyField extends PhangoField { { $this->size=$size; - $this->form='PhangoApp\PhaModels\CoreForms::TextForm'; + $this->form='PhangoApp\PhaModels\Forms\BaseForm'; } diff --git a/src/CoreFields/ParentField.php b/src/CoreFields/ParentField.php index 62aea58..a6517ef 100644 --- a/src/CoreFields/ParentField.php +++ b/src/CoreFields/ParentField.php @@ -17,7 +17,7 @@ class ParentField extends IntegerField{ $this->parent_model=&$parent_model; $this->size=$size; - $this->form='PhangoApp\PhaModels\CoreForms::SelectForm'; + $this->form='PhangoApp\PhaModels\Forms\BaseForm'; } diff --git a/src/CoreFields/PasswordField.php b/src/CoreFields/PasswordField.php index a40a3c1..97be817 100644 --- a/src/CoreFields/PasswordField.php +++ b/src/CoreFields/PasswordField.php @@ -20,7 +20,7 @@ class PasswordField extends CharField { { $this->min_length=5; $this->size=$size; - $this->form='PhangoApp\PhaModels\CoreForms::PasswordForm'; + $this->form='PhangoApp\PhaModels\Forms\PasswordForm'; } diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index f4a0818..ec42922 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -88,7 +88,7 @@ class PhangoField { * Form define the function for use in forms... */ - public $form="PhangoApp\PhaModels\CoreForms::TextForm"; + public $form='PhangoApp\PhaModels\Forms\BaseForm'; /** * Array for create initial parameters for form.. @@ -108,6 +108,7 @@ class PhangoField { public $default_value=''; + /** * Method used for internal tasks related with searchs. You can overwrite this method in your PhangoField object if you need translate the value that the user want search to a real value into the database. */ @@ -168,7 +169,7 @@ class PhangoField { /** * Method for create a form, you only need subclass the field if you want another form different to default */ - + /* public function create_form() { @@ -179,7 +180,7 @@ class PhangoField { return $form; - } + }*/ } diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index fdbd373..8d91adb 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -34,7 +34,7 @@ class PrimaryField extends PhangoField { * By default, the form used for this field is HiddenForm. */ - public $form="PhangoApp\PhaModels\CoreForms::HiddenForm"; + public $form='PhangoApp\PhaModels\Forms\BaseForm'; /** * By default this field is protected. @@ -82,7 +82,7 @@ class PrimaryField extends PhangoField { /** * By default primaryfield use a hidden form */ - + /* public function create_form() { @@ -94,7 +94,7 @@ class PrimaryField extends PhangoField { return $form; - } + }*/ } diff --git a/src/CoreFields/SerializeField.php b/src/CoreFields/SerializeField.php index f162a75..321526b 100644 --- a/src/CoreFields/SerializeField.php +++ b/src/CoreFields/SerializeField.php @@ -12,7 +12,7 @@ class SerializeField extends PhangoField { public $value=""; public $label=""; public $required=0; - public $form="TextForm"; + public $form='PhangoApp\PhaModels\Forms\BaseForm'; public $quot_open='\''; public $quot_close='\''; public $std_error=''; diff --git a/src/CoreFields/TextField.php b/src/CoreFields/TextField.php index 62b1d4e..7d4b296 100644 --- a/src/CoreFields/TextField.php +++ b/src/CoreFields/TextField.php @@ -22,7 +22,7 @@ class TextField extends PhangoField { function __construct($multilang=0) { - $this->form='PhangoApp\PhaModels\CoreForms::TextAreaForm'; + $this->form='PhangoApp\PhaModels\Forms\BaseForm'; $this->multilang=$multilang; } diff --git a/src/CoreFields/TextHTMLField.php b/src/CoreFields/TextHTMLField.php index 1db8cec..c0c787e 100644 --- a/src/CoreFields/TextHTMLField.php +++ b/src/CoreFields/TextHTMLField.php @@ -25,7 +25,7 @@ class TextHTMLField extends PhangoField { function __construct($multilang=0) { - $this->form='PhangoApp\PhaModels\CoreForms::TextAreaForm'; + $this->form='PhangoApp\PhaModels\Forms\BaseForm'; $this->multilang=$multilang; $this->set_safe_html_tags(); diff --git a/src/ExtraModels/UserPhangoModel.php b/src/ExtraModels/UserPhangoModel.php index 5bdc673..7629ccc 100644 --- a/src/ExtraModels/UserPhangoModel.php +++ b/src/ExtraModels/UserPhangoModel.php @@ -66,6 +66,15 @@ class UserPhangoModel extends Webmodel { if(isset($post[$this->username]) && $post[$this->email]) { + if(!isset($post['IdUser_admin'])) + { + + settype($_GET['IdUser_admin'], 'integer'); + + $post['IdUser_admin']=$_GET['IdUser_admin']; + + } + if($this->check_user_exists($post[$this->username], $post[$this->email], $post['IdUser_admin'])) { @@ -87,7 +96,7 @@ class UserPhangoModel extends Webmodel { unset($post[$this->password]); } - + return parent::update($post, $safe_query); } diff --git a/src/Forms/SelectForm.php b/src/Forms/SelectForm.php index cdddec8..d9d45e9 100644 --- a/src/Forms/SelectForm.php +++ b/src/Forms/SelectForm.php @@ -26,7 +26,7 @@ class SelectForm extends BaseForm{ foreach($this->arr_select as $value => $select) { - + settype($arr_selected[$value], 'string'); ?> diff --git a/src/Webmodel.php b/src/Webmodel.php index 5399db6..95d7141 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -242,21 +242,21 @@ class Webmodel { * */ - protected $conditions='WHERE 1=1'; + public $conditions='WHERE 1=1'; /** * A string where is set the order of query * */ - protected $order_by=''; + public $order_by=''; /** * A string where is saved the limit of rows in query * */ - protected $limit=''; + public $limit=''; /** * A string where is saved the limit of rows in query @@ -572,6 +572,13 @@ class Webmodel { } + public function show_conditions() + { + + return $this->conditions; + + } + /** * This method insert a row in database using model how mirage of table. * @@ -742,7 +749,7 @@ class Webmodel { } else { - + return 1; } @@ -1573,7 +1580,15 @@ class Webmodel { public function create_form($component_name) { - $this->forms[$component_name]=$this->components[$component_name]->create_form(); + $component=$this->components[$component_name]; + + $form_class=$component->form; + + $this->forms[$component_name]=new $form_class($component_name, $component->value); + + $this->forms[$component_name]->default_value=$component->default_value; + $this->forms[$component_name]->required=$component->required; + $this->forms[$component_name]->label=$component->label; } From 52d75b80292438fbf6fd20260f58eafc7c58deea Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Fri, 28 Aug 2015 13:51:50 +0200 Subject: [PATCH 40/43] Fixes on Webmodel --- src/Webmodel.php | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/Webmodel.php b/src/Webmodel.php index 95d7141..3be467e 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -1086,13 +1086,6 @@ class Webmodel { $conditions=trim($this->conditions.' '.$this->order_by.' '.$this->limit); - if($this->reset_conditions==1) - { - - $this->reset_conditions(); - - } - foreach($this->components as $name_field => $component) { @@ -1108,10 +1101,14 @@ class Webmodel { //Delete rows on models with foreignkeyfields to this model... //You need load all models with relationship if you want delete related rows... + $this->set_conditions($this->conditions); + + $this->set_limit($this->limit); + if(count($this->related_models_delete)>0) { - $arr_deleted=$this->select_to_array($conditions, array($this->idmodel), 1); + $arr_deleted=$this->select_to_array(array($this->idmodel), 1); $arr_id=array_keys($arr_deleted); @@ -1122,15 +1119,23 @@ class Webmodel { if( isset( Webmodel::$model[ $arr_set_model['model'] ]->components[ $arr_set_model['related_field'] ] ) ) { + $this->set_conditions('where '.$arr_set_model['related_field'].' IN ('.implode(', ', $arr_id).')'); - Webmodel::$model[ $arr_set_model['model'] ]->delete('where '.$arr_set_model['related_field'].' IN ('.implode(', ', $arr_id).')'); + Webmodel::$model[ $arr_set_model['model'] ]->delete(); } } } - + + if($this->reset_conditions==1) + { + + $this->reset_conditions(); + + } + return SQLClass::webtsys_query('delete from '.$this->name.' '.$conditions, $this->db_selected); } From 9db16a5edd68c358d4627f72bfebc761ede6d053 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Fri, 28 Aug 2015 23:43:08 +0200 Subject: [PATCH 41/43] Added new fields and forms --- bin/padmin | 35 +++-- src/CoreFields/BooleanField.php | 8 +- src/CoreFields/ChoiceField.php | 4 +- src/CoreFields/DateField.php | 2 +- src/CoreFields/DateTimeField.php | 85 ++++++++++++ src/CoreFields/DoubleField.php | 2 +- src/CoreFields/EmailField.php | 2 +- src/CoreFields/FileField.php | 2 +- src/CoreFields/ForeignKeyField.php | 1 + src/CoreFields/I18nField.php | 143 +++++++++++++++++++ src/CoreFields/ImageField.php | 3 +- src/CoreFields/IntegerField.php | 2 +- src/CoreFields/KeyField.php | 2 +- src/CoreFields/MoneyField.php | 26 ++++ src/CoreFields/NormalizeField.php | 51 +++++++ src/CoreFields/PercentField.php | 33 +++++ src/CoreFields/PhangoField.php | 11 +- src/CoreFields/PhoneField.php | 34 +++++ src/CoreFields/SerializeField.php | 2 +- src/CoreFields/SlugifyField.php | 49 +++++++ src/CoreFields/TextField.php | 2 +- src/CoreFields/TextHTMLField.php | 2 +- src/Forms/BaseForm.php | 27 ++++ src/Forms/DateTimeForm.php | 22 +++ src/Forms/MultiLangForm.php | 211 +++++++++++++++++++++++++++++ src/Forms/TextAreaEditor.php | 80 +++++++++++ src/Webmodel.php | 25 +++- 27 files changed, 832 insertions(+), 34 deletions(-) create mode 100644 src/CoreFields/DateTimeField.php create mode 100644 src/CoreFields/I18nField.php create mode 100644 src/CoreFields/MoneyField.php create mode 100644 src/CoreFields/NormalizeField.php create mode 100644 src/CoreFields/PercentField.php create mode 100644 src/CoreFields/PhoneField.php create mode 100644 src/CoreFields/SlugifyField.php create mode 100644 src/Forms/DateTimeForm.php create mode 100644 src/Forms/MultiLangForm.php create mode 100644 src/Forms/TextAreaEditor.php diff --git a/bin/padmin b/bin/padmin index cbeb2ec..10aaca0 100755 --- a/bin/padmin +++ b/bin/padmin @@ -64,9 +64,20 @@ function padminConsole($options) try { - $first_item=current(Webmodel::$model); - - $first_item->connect_to_db(); + if(count(Webmodel::$model)>0) + { + + $first_item=current(Webmodel::$model); + + $first_item->connect_to_db(); + + } + else + { + $climate->white()->backgroundRed()->out('Error: file don\'t have models'); + exit(1); + + } } catch(Exception $e) { @@ -164,6 +175,7 @@ function update_table() $allfields=array(); $fields=array(); $types=array(); + $defaults=array(); $field=""; $type=""; @@ -204,13 +216,14 @@ function update_table() $query=SQLClass::webtsys_query("describe `".$key."`"); list($key_field_old, $type, $null, $key_db, $default, $extra)=SQLClass::webtsys_fetch_row($query); - + while(list($field, $type, $null, $key_db, $default, $extra)=SQLClass::webtsys_fetch_row($query)) { - + $fields[]=$field; $types[$field]=$type; $keys[$field]=$key_db; + $defaults[$field]=$default; $null_set[$field]=$arr_null[$null]; @@ -226,7 +239,7 @@ function update_table() unset($allfields[$field]); - if(Webmodel::$model[$key]->components[$field]->get_type_sql()!=($type.' '.$null_set[$field])) + if(Webmodel::$model[$key]->components[$field]->get_type_sql()!=($type.' '.$null_set[$field].' DEFAULT "'.$defaults[$field].'"')) { $query=SQLClass::webtsys_query('alter table `'.$key.'` modify `'.$field.'` '.Webmodel::$model[$key]->components[$field]->get_type_sql()); @@ -266,7 +279,7 @@ function update_table() $table_related=Webmodel::$model[$key]->components[$field]->related_model->name; - $id_table_related=Webmodel::load_id_model_related(Webmodel::$model[$key]->components[$field], $model); + $id_table_related=Webmodel::load_id_model_related(Webmodel::$model[$key]->components[$field], Webmodel::$model); Webmodel::$arr_sql_set_index[$key][$field]='ALTER TABLE `'.$key.'` ADD CONSTRAINT `'.$field.'_'.$key.'IDX` FOREIGN KEY ( `'.$field.'` ) REFERENCES `'.$table_related.'` (`'.$id_table_related.'`) ON DELETE RESTRICT ON UPDATE RESTRICT;'; @@ -351,11 +364,6 @@ function update_table() else { - - /*if(isset(Webmodel::$model[$key]->components[$new_field]->related_model) ) - {*/ - - //Drop foreignkeyfield //Bug, need fixed. if($keys[$new_field]!='') @@ -444,9 +452,6 @@ function load_id_model_related($foreignkeyfield) $id_table_related=Webmodel::$model[ $foreignkeyfield->params_loading_mod['model'] ]->idmodel; - /*unset(PhangoVar::Webmodel::$model[ $foreignkeyfield->params_loading_mod['model'] ]); - - unset($cache_model);*/ } diff --git a/src/CoreFields/BooleanField.php b/src/CoreFields/BooleanField.php index 886722a..f55d112 100644 --- a/src/CoreFields/BooleanField.php +++ b/src/CoreFields/BooleanField.php @@ -24,7 +24,7 @@ class BooleanField extends PhangoField { { $this->size=1; - $this->form=public $form='PhangoApp\PhaModels\Forms\SelectForm'; + $this->form='PhangoApp\PhaModels\Forms\SelectForm'; } @@ -50,7 +50,7 @@ class BooleanField extends PhangoField { //Int for simple compatibility with sql dbs. - return 'INT('.$this->size.') NOT NULL'; + return 'INT('.$this->size.') NOT NULL DEFAULT "0"'; } @@ -83,9 +83,9 @@ class BooleanField extends PhangoField { function get_parameters_default() { - $arr_values=array($this->default_value, I18n::lang('common', 'no', 'No'), 0, I18n::lang('common', 'yes', 'Yes'), 1);; + $this->form_loaded->arr_select=array(0 => I18n::lang('common', 'no', 'No'), 1 => I18n::lang('common', 'yes', 'Yes')); - return array($this->name_component, '', $arr_values); + } diff --git a/src/CoreFields/ChoiceField.php b/src/CoreFields/ChoiceField.php index 62e97e2..e2f3c1f 100644 --- a/src/CoreFields/ChoiceField.php +++ b/src/CoreFields/ChoiceField.php @@ -99,13 +99,13 @@ class ChoiceField extends PhangoField { case 'integer': - return 'INT('.$this->size.') NOT NULL'; + return 'INT('.$this->size.') NOT NULL DEFAULT "0"'; break; case 'string': - return 'VARCHAR('.$this->size.') NOT NULL'; + return 'VARCHAR('.$this->size.') NOT NULL DEFAULT ""'; break; diff --git a/src/CoreFields/DateField.php b/src/CoreFields/DateField.php index 8d5310c..3d27e62 100644 --- a/src/CoreFields/DateField.php +++ b/src/CoreFields/DateField.php @@ -106,7 +106,7 @@ class DateField extends PhangoField { function get_type_sql() { - return 'INT('.$this->size.') NOT NULL'; + return 'INT('.$this->size.') NOT NULL DEFAULT "0"'; } diff --git a/src/CoreFields/DateTimeField.php b/src/CoreFields/DateTimeField.php new file mode 100644 index 0000000..0d7be00 --- /dev/null +++ b/src/CoreFields/DateTimeField.php @@ -0,0 +1,85 @@ + +* @file +* @package ExtraFields +* +*/ + +namespace PhangoApp\PhaModels\CoreFields; + +class DateTimeField extends DateField +{ + + public function __construct() + { + + $this->form='DateTimeForm'; + + } + + public function check($value) + { + + $timestamp=parent::check($value); + + return date('YmdHis', $timestamp); + + } + + public function search_field($value) + { + + $value_check=$this->check($value); + + return substr($value_check, 0, 8); + + } + + public function show_formatted($value) + { + + $timestamp=$this->obtain_timestamp_datefield($value); + + return parent::show_formatted($timestamp); + + } + + public function get_type_sql() + { + + return 'VARCHAR(14) NOT NULL DEFAULT ""'; + + + } + + static public function obtain_timestamp_datefield($value) + { + + $year=substr($value, 0, 4); + $month=substr($value, 4, 2); + $day=substr($value, 6, 2); + $hour=substr($value, 8, 2); + $minute=substr($value, 10, 2); + $second=substr($value, 12, 2); + + settype($year, 'integer'); + settype($month, 'integer'); + settype($day, 'integer'); + settype($hour, 'integer'); + settype($minute, 'integer'); + settype($second, 'integer'); + + $timestamp=mktime($hour, $minute, $second, $month, $day, $year); + + return $timestamp; + + } + +} + + + +?> \ No newline at end of file diff --git a/src/CoreFields/DoubleField.php b/src/CoreFields/DoubleField.php index ea14404..6471eff 100644 --- a/src/CoreFields/DoubleField.php +++ b/src/CoreFields/DoubleField.php @@ -38,7 +38,7 @@ class DoubleField extends PhangoField { function get_type_sql() { - return 'DOUBLE NOT NULL'; + return 'DOUBLE NOT NULL DEFAULT "0"'; } diff --git a/src/CoreFields/EmailField.php b/src/CoreFields/EmailField.php index 073019b..a7666db 100644 --- a/src/CoreFields/EmailField.php +++ b/src/CoreFields/EmailField.php @@ -62,7 +62,7 @@ class EmailField extends PhangoField { function get_type_sql() { - return 'VARCHAR('.$this->size.') NOT NULL'; + return 'VARCHAR('.$this->size.') NOT NULL DEFAULT ""'; } diff --git a/src/CoreFields/FileField.php b/src/CoreFields/FileField.php index 950af99..abf42fc 100644 --- a/src/CoreFields/FileField.php +++ b/src/CoreFields/FileField.php @@ -109,7 +109,7 @@ class FileField extends PhangoField { function get_type_sql() { - return 'VARCHAR(255) NOT NULL'; + return 'VARCHAR(255) NOT NULL DEFAULT ""'; } diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index 69f91dc..fe99396 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -38,6 +38,7 @@ class ForeignKeyField extends IntegerField{ $this->default_id=$default; $this->quot_open=''; $this->quot_close=''; + $this->protected=1; } diff --git a/src/CoreFields/I18nField.php b/src/CoreFields/I18nField.php new file mode 100644 index 0000000..846c983 --- /dev/null +++ b/src/CoreFields/I18nField.php @@ -0,0 +1,143 @@ + +* @file i18n_fields.php +* @package ExtraFields\I18nFields +* +* +*/ + +namespace PhangoApp\PhaModels\CoreFields; + +use PhangoApp\PhaI18n\I18n; +use PhangoApp\PhaModels\Forms\MultiLangForm; + +/** +* Multilanguage fields. +* +* With this field you can create fields for i18n sites. +*/ + +class I18nField extends PhangoField { + + public $value=""; + public $label=""; + public $required=0; + public $form="PhangoApp\PhaModels\Forms\MultiLangForm"; + public $quot_open='\''; + public $quot_close='\''; + public $std_error=''; + public $related_field=''; + public $type_field=''; + + //This method is used for check all members from serialize + + function __construct($type_field) + { + + $this->type_field=&$type_field; + + } + + function check($value) + { + + settype($value, 'array'); + + foreach(PhangoVar::$arr_i18n as $lang_item) + { + + settype($value[$lang_item], 'string'); + + $value[$lang_item]=$this->type_field->check($value[$lang_item]); + + } + + if($this->required==1 && $value[I18n::$language]=='') + { + + $this->std_error=PhangoVar::$lang['common']['error_you_need_this_language_field'].' '.I18n::$language; + + return ''; + + } + + $ser_value=addslashes(serialize($value)); + + return $ser_value; + + } + + + function get_type_sql() + { + + return 'TEXT NOT NULL DEFAULT ""'; + + + } + + static function show_formatted($value) + { + + $arr_lang=@unserialize($value); + + settype($arr_lang, 'array'); + + settype($arr_lang[I18n::$language], 'string'); + + settype($arr_lang[I18n::$language], 'string'); + + if($arr_lang[I18n::$language]=='' && $arr_lang[I18n::$language]=='') + { + + //Need view var with text... + + //$arr_lang_first=array_unique($arr_lang); + foreach($arr_lang as $key_lang => $val_lang) + { + + if($val_lang!='') + { + + return $val_lang; + + } + + } + + } + else if($arr_lang[I18n::$language]=='') + { + + return $arr_lang[I18n::$language]; + + } + + return $arr_lang[I18n::$language]; + + } + + function add_slugify_i18n_post($field, $post) + { + + + foreach(PhangoVar::$arr_i18n as $lang_field) + { + + $post[$field.'_'.$lang_field]=SlugifyField::check($post[$field][$lang_field]); + + } + + return $post; + + } + +} + + + + +?> diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php index 97ddfad..20be272 100644 --- a/src/CoreFields/ImageField.php +++ b/src/CoreFields/ImageField.php @@ -31,6 +31,7 @@ class ImageField extends PhangoField { public $img_minimal_height=array(); public $func_token='Utils::get_token'; public $move_file_func='move_uploaded_file'; + public $size=255; function __construct($name_file, $path, $url_path, $type, $thumb=0, $img_width=array('mini' => 150), $quality_jpeg=85) { @@ -371,7 +372,7 @@ class ImageField extends PhangoField { function get_type_sql() { - return 'VARCHAR(255) NOT NULL'; + return 'VARCHAR('.$this->size.') NOT NULL DEFAULT ""'; } diff --git a/src/CoreFields/IntegerField.php b/src/CoreFields/IntegerField.php index 864f4c7..688d1cf 100644 --- a/src/CoreFields/IntegerField.php +++ b/src/CoreFields/IntegerField.php @@ -64,7 +64,7 @@ class IntegerField extends PhangoField { function get_type_sql() { - return 'INT('.$this->size.') NOT NULL'; + return 'INT('.$this->size.') NOT NULL DEFAULT "0"'; } diff --git a/src/CoreFields/KeyField.php b/src/CoreFields/KeyField.php index 215ab72..770813f 100644 --- a/src/CoreFields/KeyField.php +++ b/src/CoreFields/KeyField.php @@ -43,7 +43,7 @@ class KeyField extends PhangoField { function get_type_sql() { - return 'INT('.$this->size.') NOT NULL'; + return 'INT('.$this->size.') NOT NULL DEFAULT "0"'; } diff --git a/src/CoreFields/MoneyField.php b/src/CoreFields/MoneyField.php new file mode 100644 index 0000000..3564978 --- /dev/null +++ b/src/CoreFields/MoneyField.php @@ -0,0 +1,26 @@ +currency_format($value); + + } + + + static function currency_format($value, $symbol_currency='€') + { + + + return number_format($value, 2).' '.$symbol_currency; + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/NormalizeField.php b/src/CoreFields/NormalizeField.php new file mode 100644 index 0000000..666de63 --- /dev/null +++ b/src/CoreFields/NormalizeField.php @@ -0,0 +1,51 @@ + +* @file +* @package ExtraFields +* +*/ + +namespace PhangoApp\PhaModels\CoreFields; + +class NormalizeField extends TextField { + + + public $form='HiddenForm'; + + public function check($value) + { + + + return $this->check_text($value); + + + } + + function search_field($value) + { + + return $this->check_text($value); + + } + + static public function check_text($value, $separator='-') + { + + $str_normalize=slugify(strip_tags($value)); + + $arr_normalize=explode($separator, $str_normalize); + + sort($arr_normalize); + + $value=implode('%', $arr_normalize); + + return $value; + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/PercentField.php b/src/CoreFields/PercentField.php new file mode 100644 index 0000000..6deda91 --- /dev/null +++ b/src/CoreFields/PercentField.php @@ -0,0 +1,33 @@ +100 || $value<0) + { + + $this->std_error=i18n_lang('common', 'the_value_can_not_be_greater_than_100', 'The value cannot be greater than 100'); + + return 0; + + } + + return $value; + + + } + + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index ec42922..b741060 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -90,6 +90,12 @@ class PhangoField { public $form='PhangoApp\PhaModels\Forms\BaseForm'; + /** + * Variable where save a copy of form created from this Field + */ + + public $form_loaded; + /** * Array for create initial parameters for form.. */ @@ -109,6 +115,7 @@ class PhangoField { public $default_value=''; + /** * Method used for internal tasks related with searchs. You can overwrite this method in your PhangoField object if you need translate the value that the user want search to a real value into the database. */ @@ -140,7 +147,7 @@ class PhangoField { public function get_type_sql() { - return 'VARCHAR('.$this->size.') NOT NULL'; + return 'VARCHAR('.$this->size.') NOT NULL DEFAULT "0"'; } @@ -151,7 +158,7 @@ class PhangoField { public function get_parameters_default() { - return array($this->name_component, '', ''); + } diff --git a/src/CoreFields/PhoneField.php b/src/CoreFields/PhoneField.php new file mode 100644 index 0000000..c00689a --- /dev/null +++ b/src/CoreFields/PhoneField.php @@ -0,0 +1,34 @@ + +* @file +* @package ExtraFields +* +*/ + +namespace PhangoApp\PhaModels\CoreFields; + +class PhoneField extends CharField{ + + + public function check($value) + { + + if(!preg_match('/^[0-9]+$/', $value)) + { + + return ''; + + } + + return $value; + + + } + + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/SerializeField.php b/src/CoreFields/SerializeField.php index 321526b..8931376 100644 --- a/src/CoreFields/SerializeField.php +++ b/src/CoreFields/SerializeField.php @@ -78,7 +78,7 @@ class SerializeField extends PhangoField { function get_type_sql() { - return 'TEXT NOT NULL'; + return 'TEXT NOT NULL DEFAULT ""'; } diff --git a/src/CoreFields/SlugifyField.php b/src/CoreFields/SlugifyField.php new file mode 100644 index 0000000..6ac3842 --- /dev/null +++ b/src/CoreFields/SlugifyField.php @@ -0,0 +1,49 @@ +type.' NOT NULL DEFAULT ""'; + + + } + + static function add_slugify_i18n_fields($model_name, $field) + { + + foreach(PhangoVar::$arr_i18n as $lang_field) + { + + PhangoVar::$model[$model_name]->components[$field.'_'.$lang_field]=new SlugifyField(); + + } + + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/TextField.php b/src/CoreFields/TextField.php index 7d4b296..344cc89 100644 --- a/src/CoreFields/TextField.php +++ b/src/CoreFields/TextField.php @@ -41,7 +41,7 @@ class TextField extends PhangoField { function get_type_sql() { - return 'TEXT NOT NULL'; + return 'TEXT NOT NULL DEFAULT ""'; } diff --git a/src/CoreFields/TextHTMLField.php b/src/CoreFields/TextHTMLField.php index c0c787e..f23218d 100644 --- a/src/CoreFields/TextHTMLField.php +++ b/src/CoreFields/TextHTMLField.php @@ -85,7 +85,7 @@ class TextHTMLField extends PhangoField { function get_type_sql() { - return 'TEXT NOT NULL'; + return 'TEXT NOT NULL DEFAULT ""'; } diff --git a/src/Forms/BaseForm.php b/src/Forms/BaseForm.php index 4bf9edf..f45a477 100644 --- a/src/Forms/BaseForm.php +++ b/src/Forms/BaseForm.php @@ -38,6 +38,33 @@ class BaseForm { } + /** + * Static method where is registered the js necessary for a field + */ + + static public function js() + { + + } + + /** + * Static method where is registered the js necessary for a field + */ + + static public function css() + { + + } + + /** + * Static method where is registered the js necessary for a field + */ + + static public function header() + { + + } + /** * Method for escape value for html input */ diff --git a/src/Forms/DateTimeForm.php b/src/Forms/DateTimeForm.php new file mode 100644 index 0000000..8971bf1 --- /dev/null +++ b/src/Forms/DateTimeForm.php @@ -0,0 +1,22 @@ +type.'" class="'.$this->css.'" name="'.$this->name.'" value="'.$this->setform($this->default_value).'">'; + + return DateForm($this->name, $class, $this->default_value, $this->set_time); + + } + +} + +?> \ No newline at end of file diff --git a/src/Forms/MultiLangForm.php b/src/Forms/MultiLangForm.php new file mode 100644 index 0000000..da6a8f8 --- /dev/null +++ b/src/Forms/MultiLangForm.php @@ -0,0 +1,211 @@ +name.'_'.$lang_select.'">'; + echo $this->type_form($this->name.'['.$lang_select.']', '', $arr_values[$lang_select]); + echo '';*/ + + } + ?> +
+ + <?php echo $lang_item; ?>  + +
+
+ + name.'_'.$lang_select.'">'; + echo $this->type_form($this->name.'['.$lang_select.']', '', $arr_values[$lang_select]); + echo ''; + + } + ?> +
+ + <?php echo $lang_item; ?>  + +
+
+ + \ No newline at end of file diff --git a/src/Forms/TextAreaEditor.php b/src/Forms/TextAreaEditor.php new file mode 100644 index 0000000..7608d64 --- /dev/null +++ b/src/Forms/TextAreaEditor.php @@ -0,0 +1,80 @@ +name=Utils::slugify($this->name); + + ob_start(); + + ?> + + + + +

+ \ No newline at end of file diff --git a/src/Webmodel.php b/src/Webmodel.php index 3be467e..0ddd3d7 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -276,6 +276,8 @@ class Webmodel { static public $arr_sql_unique=array(); static public $arr_sql_set_unique=array(); + static public $m; + //Construct the model /** @@ -310,6 +312,12 @@ class Webmodel { $this->cache=$cache; $this->type_cache=$type_cache; + //Global access to models + + Webmodel::$model[$name_model]=&$this; + + Webmodel::$m->$name_model=&Webmodel::$model[$name_model]; + } /** @@ -455,7 +463,7 @@ class Webmodel { unset($this->components[$this->idmodel]); $this->idmodel=$name_id; //$this->components[$this->idmodel]=new PrimaryField(); - $this->register($this->idmodel, 'PrimaryField', array()); + $this->register($this->idmodel, new PrimaryField($this->idmodel)); } @@ -1594,6 +1602,10 @@ class Webmodel { $this->forms[$component_name]->default_value=$component->default_value; $this->forms[$component_name]->required=$component->required; $this->forms[$component_name]->label=$component->label; + + $this->components[$component_name]->form_loaded=&$this->forms[$component_name]; + + $this->components[$component_name]->get_parameters_default(); } @@ -1850,4 +1862,15 @@ class Webmodel { } + +//A simple shortcut for access to models + +class SuperModel { + + + +} + +Webmodel::$m=new SuperModel(); + ?> \ No newline at end of file From 22becfad23c16c715e54e5f530f880b1d7cdefc6 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 29 Aug 2015 04:38:21 +0200 Subject: [PATCH 42/43] Added new fields and forms --- src/CoreFields/I18nField.php | 5 +- src/CoreFields/PrimaryField.php | 4 +- src/CoreFields/TextHTMLField.php | 2 +- src/Forms/HiddenForm.php | 25 ++++++ src/Forms/MultiLangForm.php | 145 +++++++++++++++++++++++++++---- src/Forms/TextAreaEditor.php | 2 - src/Webmodel.php | 78 ++++++++++++----- 7 files changed, 217 insertions(+), 44 deletions(-) create mode 100644 src/Forms/HiddenForm.php diff --git a/src/CoreFields/I18nField.php b/src/CoreFields/I18nField.php index 846c983..094b212 100644 --- a/src/CoreFields/I18nField.php +++ b/src/CoreFields/I18nField.php @@ -13,6 +13,7 @@ namespace PhangoApp\PhaModels\CoreFields; use PhangoApp\PhaI18n\I18n; use PhangoApp\PhaModels\Forms\MultiLangForm; +use PhangoApp\PhaModels\CoreFields\SlugifyField; /** * Multilanguage fields. @@ -46,7 +47,7 @@ class I18nField extends PhangoField { settype($value, 'array'); - foreach(PhangoVar::$arr_i18n as $lang_item) + foreach(I18n::$arr_i18n as $lang_item) { settype($value[$lang_item], 'string'); @@ -58,7 +59,7 @@ class I18nField extends PhangoField { if($this->required==1 && $value[I18n::$language]=='') { - $this->std_error=PhangoVar::$lang['common']['error_you_need_this_language_field'].' '.I18n::$language; + $this->std_error=I18n::lang('common', 'error_you_need_this_language_field', 'Error, you need this language field').' '.I18n::$language; return ''; diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index 8d91adb..633119f 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -2,7 +2,7 @@ namespace PhangoApp\PhaModels\CoreFields; use PhangoApp\PhaUtils\Utils; -use PhangoApp\PhaModels\Forms\BaseForm; +use PhangoApp\PhaModels\Forms\HiddenForm; /** * PrimaryField is used for primary keys for models @@ -34,7 +34,7 @@ class PrimaryField extends PhangoField { * By default, the form used for this field is HiddenForm. */ - public $form='PhangoApp\PhaModels\Forms\BaseForm'; + public $form='PhangoApp\PhaModels\Forms\HiddenForm'; /** * By default this field is protected. diff --git a/src/CoreFields/TextHTMLField.php b/src/CoreFields/TextHTMLField.php index f23218d..30eb094 100644 --- a/src/CoreFields/TextHTMLField.php +++ b/src/CoreFields/TextHTMLField.php @@ -26,7 +26,7 @@ class TextHTMLField extends PhangoField { { $this->form='PhangoApp\PhaModels\Forms\BaseForm'; - $this->multilang=$multilang; + $this->set_safe_html_tags(); } diff --git a/src/Forms/HiddenForm.php b/src/Forms/HiddenForm.php new file mode 100644 index 0000000..5666b6e --- /dev/null +++ b/src/Forms/HiddenForm.php @@ -0,0 +1,25 @@ +type='hidden'; + + } + + +} + +?> \ No newline at end of file diff --git a/src/Forms/MultiLangForm.php b/src/Forms/MultiLangForm.php index da6a8f8..962c8cc 100644 --- a/src/Forms/MultiLangForm.php +++ b/src/Forms/MultiLangForm.php @@ -9,22 +9,33 @@ use PhangoApp\PhaView\View; class MultiLangForm extends BaseForm{ - public $type_form='PhangoApp\PhaModels\Forms\BaseForm'; + public $type_form; + public function __construct($name, $value) + { + + $this->type_form=new BaseForm($name, $value); + + parent::__construct($name, $value); + + } + public function form() { + //make a foreach with all langs //default, es_ES, en_US, show default if no exists translation for selected language. + /* foreach(I18n::$arr_i18n as $lang_select) { - /* $arr_selected[Utils::slugify($lang_select)]='hidden_form'; - $arr_selected[Utils::slugify(I18n::$language)]='no_hidden_form';*/ + $arr_selected[Utils::slugify($lang_select)]='hidden_form'; + $arr_selected[Utils::slugify(I18n::$language)]='no_hidden_form'; - /*settype($arr_values[$lang_select], 'string'); + settype($arr_values[$lang_select], 'string'); echo '
'; echo $this->type_form($this->name.'['.$lang_select.']', '', $arr_values[$lang_select]); - echo '
';*/ + echo ''; } ?> @@ -182,28 +193,128 @@ class MultiLangForm extends BaseForm{ return $text_form; */ - } - - function setform($value) - { - if(!gettype($value)=='array') + if(!get_class($this->type_form)) { - - settype($arr_value, 'array'); - - $arr_value = @unserialize( $value ); + + throw new \Exception('Error: need set the $type_form property with a valid class form in '.$this->name); + + } + + if(gettype($this->default_value)!='array') + { + + $arr_values=unserialize($this->default_value); - return $arr_value; - } else { + + $arr_values=$this->default_value; + + } + + //print_r($this->default_value); + + foreach(I18n::$arr_i18n as $lang_select) + { + + $slug=Utils::slugify($lang_select); + $lang_slug=Utils::slugify(I18n::$language); + + $arr_selected[$slug]='hidden_form'; + $arr_selected[$lang_slug]='no_hidden_form'; + + $this->type_form->name=$this->name.'['.$lang_select.']'; + + $this->type_form->default_value=$this->setform($arr_values[$lang_select]); + + echo '
'; + echo $this->type_form->form(); + echo '
'; + + } + + ?> +
+ + <?php echo $lang_item; ?> + +
+
+
+ + + name=Utils::slugify($this->name); ob_start(); diff --git a/src/Webmodel.php b/src/Webmodel.php index 0ddd3d7..acd5618 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -276,8 +276,24 @@ class Webmodel { static public $arr_sql_unique=array(); static public $arr_sql_set_unique=array(); + /** + * Simple property for save models in object mode + */ + static public $m; + /** + * A simple array for load js, header and css from forms objects only one time + */ + + static public $form_type=array(); + + /** + * A simple array for control if was loaded contents from a form + */ + + static public $form_type_checked=array(); + //Construct the model /** @@ -1552,36 +1568,49 @@ class Webmodel { { //With function for create form, we use an array for specific order, after i can insert more fields in the form. - - $this->forms=array(); - $arr_form=array(); - - if(count($fields_form)==0) - { - - $fields_form=array_keys($this->components); - - } - - foreach($fields_form as $component_name) - { - - if(isset($this->components[$component_name])) - { - + $this->forms=array(); + + $arr_form=array(); + + if(count($fields_form)==0) + { + + $fields_form=array_keys($this->components); + + } + + foreach($fields_form as $component_name) + { + + if(isset($this->components[$component_name])) + { + if($this->components[$component_name]->label=='') { $this->components[$component_name]->label=ucfirst($component_name); } - + $this->create_form($component_name); - } + } - } + } + + + foreach(array_keys(Webmodel::$form_type) as $type) + { + $type::js(); + $type::css(); + $type::header(); + + Webmodel::$form_type_checked[$type]=1; + + } + + Webmodel::$form_type=array(); } @@ -1599,6 +1628,15 @@ class Webmodel { $this->forms[$component_name]=new $form_class($component_name, $component->value); + $type_class=get_class($this->forms[$component_name]); + + if(!isset(Webmodel::$form_type_checked[$type_class])) + { + + Webmodel::$form_type[$type_class]=1; + + } + $this->forms[$component_name]->default_value=$component->default_value; $this->forms[$component_name]->required=$component->required; $this->forms[$component_name]->label=$component->label; From 4f3641ad5bd6b50da60964b9c09f17907d4d38e3 Mon Sep 17 00:00:00 2001 From: Antonio de la Rosa Date: Sat, 29 Aug 2015 04:48:26 +0200 Subject: [PATCH 43/43] Added update property for things how ImageField --- src/CoreFields/PhangoField.php | 5 +++++ src/Webmodel.php | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index b741060..2d645d1 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -114,6 +114,11 @@ class PhangoField { public $default_value=''; + /** + * A property for know if updated or insert this field + */ + + public $update=0; /** diff --git a/src/Webmodel.php b/src/Webmodel.php index acd5618..6b6055f 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -294,6 +294,12 @@ class Webmodel { static public $form_type_checked=array(); + /** + * A simple switch for know if updated or insert this model + */ + + public $update=0; + //Construct the model /** @@ -630,6 +636,8 @@ class Webmodel { } */ + $this->update=0; + $arr_fields=array(); if( $fields=$this->check_all($post, $safe_query) ) @@ -706,6 +714,10 @@ class Webmodel { $post=$this->unset_no_required($post); + //With this property your fields can save if insert or update + + $this->update=1; + //Checking and sanitizing data from $post array for use in the query if( $fields=$this->check_all($post, $safe_query) ) @@ -1464,6 +1476,7 @@ class Webmodel { if(isset($post[$key]) && ($field->protected==0 || $safe_query==1)) { + $this->components[$key]->update=$this->update; //Check if the value is valid..