Fixes for adapt to the new framework
This commit is contained in:
parent
d76b4df139
commit
ea3bbc91e4
12 changed files with 245 additions and 18 deletions
|
|
@ -2,8 +2,7 @@
|
||||||
"name": "phangoapp/phamodel",
|
"name": "phangoapp/phamodel",
|
||||||
"description": "A simple class for create models",
|
"description": "A simple class for create models",
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
"phpunit/phpunit": "~4.8@dev",
|
"phpunit/phpunit": "~4.8@dev"
|
||||||
"phautils/utils": "dev-master"
|
|
||||||
},
|
},
|
||||||
"license": "GPL",
|
"license": "GPL",
|
||||||
"authors": [
|
"authors": [
|
||||||
|
|
@ -12,8 +11,9 @@
|
||||||
"email": "webmaster@web-t-sys.com"
|
"email": "webmaster@web-t-sys.com"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"minimum-stability": "dev-master",
|
"minimum-stability": "dev",
|
||||||
"require": {},
|
"require": {
|
||||||
|
},
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"PhangoApp\\PhaRouter\\": "src"
|
"PhangoApp\\PhaRouter\\": "src"
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
|
||||||
class CharField extends PhangoField {
|
class CharField extends PhangoField {
|
||||||
|
|
||||||
|
|
@ -53,7 +54,7 @@ class CharField extends PhangoField {
|
||||||
{
|
{
|
||||||
|
|
||||||
//Delete Javascript tags and simple quotes.
|
//Delete Javascript tags and simple quotes.
|
||||||
$this->value=form_text($value);
|
$this->value=Utils::form_text($value);
|
||||||
return form_text($value);
|
return form_text($value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -69,7 +69,7 @@ class ChoiceField extends PhangoField {
|
||||||
|
|
||||||
case 'string':
|
case 'string':
|
||||||
|
|
||||||
$value=form_text($value);
|
$value=Utils::form_text($value);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
|
||||||
class DoubleField extends PhangoField {
|
class DoubleField extends PhangoField {
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ class DoubleField extends PhangoField {
|
||||||
function check($value)
|
function check($value)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->value=form_text($value);
|
$this->value=Utils::form_text($value);
|
||||||
settype($value, "double");
|
settype($value, "double");
|
||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
|
|
|
||||||
83
src/CoreFields/EmailField.php
Normal file
83
src/CoreFields/EmailField.php
Normal file
|
|
@ -0,0 +1,83 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emailfield is a field that only accepts emails
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
|
||||||
|
class EmailField extends PhangoField {
|
||||||
|
|
||||||
|
public $size=200;
|
||||||
|
public $value="";
|
||||||
|
public $label="";
|
||||||
|
public $form="TextForm";
|
||||||
|
public $class="";
|
||||||
|
public $required=0;
|
||||||
|
public $quot_open='\'';
|
||||||
|
public $quot_close='\'';
|
||||||
|
public $std_error='';
|
||||||
|
|
||||||
|
function __construct($size=200)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->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;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
use PhangoApp\PhaI18n\I18n;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ForeignKeyfield is a relantioship between two models...
|
* ForeignKeyfield is a relantioship between two models...
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
|
||||||
class IntegerField extends PhangoField {
|
class IntegerField extends PhangoField {
|
||||||
|
|
||||||
|
|
@ -31,7 +32,7 @@ class IntegerField extends PhangoField {
|
||||||
function check($value)
|
function check($value)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->value=form_text($value);
|
$this->value=Utils::form_text($value);
|
||||||
|
|
||||||
settype($value, "integer");
|
settype($value, "integer");
|
||||||
|
|
||||||
|
|
|
||||||
138
src/CoreFields/ParentField.php
Normal file
138
src/CoreFields/ParentField.php
Normal file
|
|
@ -0,0 +1,138 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class ParentField extends IntegerField{
|
||||||
|
|
||||||
|
//field related in the model...
|
||||||
|
public $parent_model='';
|
||||||
|
|
||||||
|
function __construct($parent_model, $size=11)
|
||||||
|
{
|
||||||
|
|
||||||
|
$this->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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
?>
|
||||||
|
|
@ -14,6 +14,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
|
||||||
class PhangoField {
|
class PhangoField {
|
||||||
|
|
||||||
|
|
@ -101,7 +102,7 @@ class PhangoField {
|
||||||
function search_field($value)
|
function search_field($value)
|
||||||
{
|
{
|
||||||
|
|
||||||
return form_text($value);
|
return Utils::form_text($value);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace PhangoApp\PhaModels\CoreFields;
|
namespace PhangoApp\PhaModels\CoreFields;
|
||||||
|
use PhangoApp\PhaUtils\Utils;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PrimaryField is used for primary keys for models
|
* PrimaryField is used for primary keys for models
|
||||||
|
|
@ -43,7 +44,7 @@ class PrimaryField extends PhangoField {
|
||||||
public function check($value)
|
public function check($value)
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->value=form_text($value);
|
$this->value=Utils::form_text($value);
|
||||||
settype($value, "integer");
|
settype($value, "integer");
|
||||||
return $value;
|
return $value;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class TextField extends PhangoField {
|
||||||
|
|
||||||
//Delete Javascript tags and simple quotes.
|
//Delete Javascript tags and simple quotes.
|
||||||
$this->value=$value;
|
$this->value=$value;
|
||||||
return form_text($value, $this->br);
|
return Utils::form_text($value, $this->br);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,8 @@ class Webmodel {
|
||||||
|
|
||||||
static public $pass_db=array();
|
static public $pass_db=array();
|
||||||
|
|
||||||
|
static public $type_db='mysql';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection to db.
|
* Connection to db.
|
||||||
*/
|
*/
|
||||||
|
|
@ -145,7 +147,7 @@ class Webmodel {
|
||||||
public $related_models=array();
|
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();
|
public $related_models_delete=array();
|
||||||
|
|
@ -298,8 +300,8 @@ class Webmodel {
|
||||||
public function connect_to_db()
|
public function connect_to_db()
|
||||||
{
|
{
|
||||||
|
|
||||||
include(__DIR__.'/database/'.TYPE_DB.'.php');
|
include(__DIR__.'/database/'.Webmodel::$type_db.'.php');
|
||||||
//load_libraries(array('database/'.TYPE_DB), Webmodel::$base_path);
|
//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))
|
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 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
|
* @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.
|
* @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)
|
foreach($arr_components as $value)
|
||||||
|
|
@ -1385,7 +1387,7 @@ class Webmodel {
|
||||||
* @param string $arguments Array with arguments for construct the new field
|
* @param string $arguments Array with arguments for construct the new field
|
||||||
* @param boolean $required A boolean used for set the default required value
|
* @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);
|
$rc=new \ReflectionClass($type);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue