diff --git a/composer.json b/composer.json index afa5f72..4e6c71d 100644 --- a/composer.json +++ b/composer.json @@ -2,8 +2,7 @@ "name": "phangoapp/phamodel", "description": "A simple class for create models", "require-dev": { - "phpunit/phpunit": "~4.8@dev", - "phautils/utils": "dev-master" + "phpunit/phpunit": "~4.8@dev" }, "license": "GPL", "authors": [ @@ -12,8 +11,9 @@ "email": "webmaster@web-t-sys.com" } ], - "minimum-stability": "dev-master", - "require": {}, + "minimum-stability": "dev", + "require": { + }, "autoload": { "psr-4": { "PhangoApp\\PhaRouter\\": "src" diff --git a/src/CoreFields/CharField.php b/src/CoreFields/CharField.php index a5576b9..9f693e8 100644 --- a/src/CoreFields/CharField.php +++ b/src/CoreFields/CharField.php @@ -7,6 +7,7 @@ */ namespace PhangoApp\PhaModels\CoreFields; +use PhangoApp\PhaUtils\Utils; class CharField extends PhangoField { @@ -53,7 +54,7 @@ class CharField extends PhangoField { { //Delete Javascript tags and simple quotes. - $this->value=form_text($value); + $this->value=Utils::form_text($value); return form_text($value); } diff --git a/src/CoreFields/ChoiceField.php b/src/CoreFields/ChoiceField.php index 01dc1fe..964530e 100644 --- a/src/CoreFields/ChoiceField.php +++ b/src/CoreFields/ChoiceField.php @@ -69,7 +69,7 @@ class ChoiceField extends PhangoField { case 'string': - $value=form_text($value); + $value=Utils::form_text($value); break; diff --git a/src/CoreFields/DoubleField.php b/src/CoreFields/DoubleField.php index 06960ba..9feeec3 100644 --- a/src/CoreFields/DoubleField.php +++ b/src/CoreFields/DoubleField.php @@ -5,6 +5,7 @@ */ namespace PhangoApp\PhaModels\CoreFields; +use PhangoApp\PhaUtils\Utils; class DoubleField extends PhangoField { @@ -28,7 +29,7 @@ class DoubleField extends PhangoField { function check($value) { - $this->value=form_text($value); + $this->value=Utils::form_text($value); settype($value, "double"); return $value; diff --git a/src/CoreFields/EmailField.php b/src/CoreFields/EmailField.php new file mode 100644 index 0000000..4ff1c3a --- /dev/null +++ b/src/CoreFields/EmailField.php @@ -0,0 +1,83 @@ +size=$size; + + } + + //Method for accept valid emails only + + function check($value) + { + + //Delete Javascript tags and simple quotes. + + + + $value=Utils::form_text($value); + + $this->value=$value; + + $email_expression='([\w\!\#$\%\&\'\*\+\-\/\=\?\^\`{\|\}\~]+\.)*(?:[\w\!\#$\%\'\*\+\-\/\=\?\^\`{\|\}\~]|&)+@((((([a-z0-9]{1}[a-z0-9\-]{0,62}[a-z0-9]{1})|[a-z])\.)+[a-z]{2,6})|(\d{1,3}\.){3}\d{1,3}(\:\d{1,5})?)'; + + if(preg_match('/^'.$email_expression.'$/i', $value)) + { + + return $value; + + } + else + { + + $this->std_error.='Email format error'; + + return ''; + + } + + + } + + function get_type_sql() + { + + return 'VARCHAR('.$this->size.') NOT NULL'; + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + return $value; + + } + + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/ForeignKeyField.php b/src/CoreFields/ForeignKeyField.php index 4ae5996..a1024f0 100644 --- a/src/CoreFields/ForeignKeyField.php +++ b/src/CoreFields/ForeignKeyField.php @@ -1,7 +1,6 @@ value=form_text($value); + $this->value=Utils::form_text($value); settype($value, "integer"); diff --git a/src/CoreFields/ParentField.php b/src/CoreFields/ParentField.php new file mode 100644 index 0000000..ee9773e --- /dev/null +++ b/src/CoreFields/ParentField.php @@ -0,0 +1,138 @@ +parent_model=&$parent_model; + $this->size=$size; + $this->form='SelectForm'; + + } + + function check($value) + { + + settype($value, "integer"); + + //Check model + + $num_rows=$this->parent_model->select_count('where '.$this->parent_model->idmodel.'='.$value, $this->parent_model->idmodel); + + if($num_rows>0) + { + + return $value; + + } + else + { + + return 0; + + } + + + } + + /** + * This function is used for show the value on a human format + */ + + public function show_formatted($value) + { + + return $value; + + } + + function get_parameters_default() + { + + + $arr_values=array('', PhangoVar::$l_['common']->lang('any_option_chosen', 'Any option chosen'), ''); + + return array($this->name_component, '', $arr_values); + + } + + public function process_update_field($class, $name_field, $conditions, $value) + { + + $num_rows=$class->select_count($conditions.' and '.$class->idmodel.'='.$value); + + if($num_rows==0) + { + + return true; + + } + else + { + + return false; + + } + + } + + public function obtain_parent_tree($id, $field_ident, $url_op) + { + + $arr_parent=array(); + $arr_link_parent=array(); + + $query=$this->parent_model->select('', array( $this->parent_model->idmodel, $this->name_component, $field_ident) ); + + while(list($id_block, $parent, $name)=webtsys_fetch_row($query)) + { + + $arr_parent[$id_block]=array($parent, $name); + + } + + $arr_link_parent=$this->obtain_recursive_parent($id, $arr_parent, $arr_link_parent, $field_ident, $url_op); + + $arr_link_parent=array_reverse($arr_link_parent, true); + + return $arr_link_parent; + + } + + public function obtain_recursive_parent($id, $arr_parent, $arr_link_parent, $field_ident, $url_op) + { + + //$arr_link_parent[]=array('nombre', 'enlace'); + + //$arr_link_parent=array(); + + if($id>0) + { + + $arr_link_parent[$id]=array($this->parent_model->components[$field_ident]->show_formatted($arr_parent[$id][1]), add_extra_fancy_url($url_op, array($this->name_component => $id) ) ); + + if($arr_parent[$id][0]>0) + { + + $arr_link_parent=$this->obtain_recursive_parent($arr_parent[$id][0], $arr_parent, $arr_link_parent, $field_ident, $url_op); + + } + + } + + return $arr_link_parent; + } + +} + +?> \ No newline at end of file diff --git a/src/CoreFields/PhangoField.php b/src/CoreFields/PhangoField.php index 54ed99b..ae277f7 100644 --- a/src/CoreFields/PhangoField.php +++ b/src/CoreFields/PhangoField.php @@ -14,6 +14,7 @@ */ namespace PhangoApp\PhaModels\CoreFields; +use PhangoApp\PhaUtils\Utils; class PhangoField { @@ -101,7 +102,7 @@ class PhangoField { function search_field($value) { - return form_text($value); + return Utils::form_text($value); } diff --git a/src/CoreFields/PrimaryField.php b/src/CoreFields/PrimaryField.php index 77ea5cd..d618813 100644 --- a/src/CoreFields/PrimaryField.php +++ b/src/CoreFields/PrimaryField.php @@ -1,6 +1,7 @@ value=form_text($value); + $this->value=Utils::form_text($value); settype($value, "integer"); return $value; diff --git a/src/CoreFields/TextField.php b/src/CoreFields/TextField.php index d8c4b32..28dd8ff 100644 --- a/src/CoreFields/TextField.php +++ b/src/CoreFields/TextField.php @@ -32,7 +32,7 @@ class TextField extends PhangoField { //Delete Javascript tags and simple quotes. $this->value=$value; - return form_text($value, $this->br); + return Utils::form_text($value, $this->br); } diff --git a/src/Webmodel.php b/src/Webmodel.php index 72227dc..74d709e 100644 --- a/src/Webmodel.php +++ b/src/Webmodel.php @@ -37,6 +37,8 @@ class Webmodel { static public $pass_db=array(); + static public $type_db='mysql'; + /** * Connection to db. */ @@ -145,7 +147,7 @@ class Webmodel { public $related_models=array(); /** - * An array where the model save the name of the related models via ForeignKeyField. You need use $this->set_component method for fill this array. + * An array where the model save the name of the related models via ForeignKeyField. You need use $this->register method for fill this array. */ public $related_models_delete=array(); @@ -298,8 +300,8 @@ class Webmodel { public function connect_to_db() { - include(__DIR__.'/database/'.TYPE_DB.'.php'); - //load_libraries(array('database/'.TYPE_DB), Webmodel::$base_path); + include(__DIR__.'/database/'.Webmodel::$type_db.'.php'); + //load_libraries(array('database/'.Webmodel::$type_db), Webmodel::$base_path); if(!webtsys_connect( Webmodel::$host_db[$this->db_selected], Webmodel::$login_db[$this->db_selected], Webmodel::$pass_db[$this->db_selected] , $this->db_selected)) { @@ -892,7 +894,7 @@ class Webmodel { /** * This method delete rows for the sql condition * - * This method is used for delete rows based in a sql conditions. If you use $this->set_component method for create new fields for model, $this->delete will delete all rows from model with foreignkeys related with this model. This thing is necessary because foreignkeys need to be deleted if you deleted its related model. + * This method is used for delete rows based in a sql conditions. If you use $this->register method for create new fields for model, $this->delete will delete all rows from model with foreignkeys related with this model. This thing is necessary because foreignkeys need to be deleted if you deleted its related model. * * @param string $conditions Conditions have same sintax that $conditions from $this->select method */ @@ -1165,7 +1167,7 @@ class Webmodel { * @param array $arr_components Array with fields names that you want delete from model. */ - public function unset_components($arr_components=array()) + public function unregisters($arr_components=array()) { foreach($arr_components as $value) @@ -1385,7 +1387,7 @@ 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 set_component($name, $type, $arguments, $required=0) + public function register($name, $type, $arguments, $required=0) { $rc=new \ReflectionClass($type);