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

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