Fixes for adapt to the new framework

This commit is contained in:
Antonio de la Rosa 2015-04-24 04:17:13 +02:00
parent d76b4df139
commit ea3bbc91e4
12 changed files with 245 additions and 18 deletions

View file

@ -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"

View file

@ -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);
}

View file

@ -69,7 +69,7 @@ class ChoiceField extends PhangoField {
case 'string':
$value=form_text($value);
$value=Utils::form_text($value);
break;

View file

@ -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;

View 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\!\#$\%\'\*\+\-\/\=\?\^\`{\|\}\~]|&amp;)+@((((([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;
}
}
?>

View file

@ -1,7 +1,6 @@
<?php
namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaI18n\I18n;
/**
* ForeignKeyfield is a relantioship between two models...

View file

@ -6,6 +6,7 @@
*/
namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaUtils\Utils;
class IntegerField extends PhangoField {
@ -31,7 +32,7 @@ class IntegerField extends PhangoField {
function check($value)
{
$this->value=form_text($value);
$this->value=Utils::form_text($value);
settype($value, "integer");

View 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;
}
}
?>

View file

@ -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);
}

View file

@ -1,6 +1,7 @@
<?php
namespace PhangoApp\PhaModels\CoreFields;
use PhangoApp\PhaUtils\Utils;
/**
* PrimaryField is used for primary keys for models
@ -43,7 +44,7 @@ class PrimaryField extends PhangoField {
public function check($value)
{
$this->value=form_text($value);
$this->value=Utils::form_text($value);
settype($value, "integer");
return $value;

View file

@ -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);
}

View file

@ -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);