Added new fields type

This commit is contained in:
Antonio de la Rosa 2015-04-21 04:23:56 +02:00
parent fce1896c8d
commit 0402ebebf0
6 changed files with 328 additions and 1902 deletions

View file

@ -0,0 +1,92 @@
<?php
/**
* Booleanfield is a field for boolean values.
*/
namespace PhangoApp\PhaModels\CoreFields;
class BooleanField extends PhangoField {
public $size=1;
public $value=0;
public $label="";
public $required=0;
public $form="";
public $quot_open='\'';
public $quot_close='\'';
public $std_error='';
public $default_value=0;
function __construct()
{
$this->size=1;
$this->form='SelectForm';
}
function check($value)
{
//$this->value=form_text($value);
settype($value, "integer");
if($value!=0 && $value!=1)
{
$value=0;
}
return $value;
}
function get_type_sql()
{
//Int for simple compatibility with sql dbs.
return 'INT('.$this->size.') NOT NULL';
}
/**
* This function is used for show the value on a human format
*/
public function show_formatted($value)
{
switch($value)
{
default:
return PhangoVar::$l_['common']->lang('no', 'No');
break;
case 1:
return PhangoVar::$l_['common']->lang('yes', 'Yes');
break;
}
}
function get_parameters_default()
{
$arr_values=array($this->default_value, PhangoVar::$l_['common']->lang('no', 'No'), 0, PhangoVar::$l_['common']->lang('yes', 'Yes'), 1);;
return array($this->name_component, '', $arr_values);
}
}
?>

View file

@ -0,0 +1,64 @@
<?php
/**
* CharField is a PhangoField that define a varchar element in the model-table.
*
* A simple PhangoField that define in the database a varchar element with the size that you like.
*/
namespace PhangoApp\PhaModels\CoreFields;
class CharField extends PhangoField {
//Basic variables that define the field
/**
* Size of field in database
*/
public $size=20;
/**
* Construct field with basic data...
*
* @param integer $size The size of the varchar. If you put 250, for example, you will can put strings with 250 characters on this.
* @param boolean $multilang Don't use, don't need for nothing.
*
*/
function __construct($size=20)
{
$this->size=$size;
$this->form='TextForm';
}
/**
* This function is used for show the value on a human format
*/
public function show_formatted($value)
{
return $value;
}
/**
* This function is for check if the value for field is valid
*/
public function check($value)
{
//Delete Javascript tags and simple quotes.
$this->value=form_text($value);
return form_text($value);
}
}
?>

View file

@ -0,0 +1,65 @@
<?php
/**
* Doublefield is a field for doubles values.
*/
namespace PhangoApp\PhaModels\CoreFields;
class DoubleField extends PhangoField {
public $size=11;
public $value=0;
public $label="";
public $required=0;
public $form="";
public $quot_open='\'';
public $quot_close='\'';
public $std_error='';
function __construct($size=11)
{
$this->size=$size;
$this->form='TextForm';
}
function check($value)
{
$this->value=form_text($value);
settype($value, "double");
return $value;
}
function get_type_sql()
{
return 'DOUBLE NOT NULL';
}
/**
* This function is used for show the value on a human format
*/
public function show_formatted($value)
{
return $value;
}
function get_parameters_default()
{
return array($this->name_component, '', 0);
}
}
?>

View file

@ -0,0 +1,90 @@
<?php
/**
* Integerfield is a field for integers values.
*
*/
namespace PhangoApp\PhaModels\CoreFields;
class IntegerField extends PhangoField {
public $size=11;
public $value=0;
public $label="";
public $required=0;
public $only_positive=false;
public $min_num=0;
public $max_num=0;
function __construct($size=11, $only_positive=false, $min_num=0, $max_num=0)
{
$this->size=$size;
$this->form='TextForm';
$this->only_positive=$only_positive;
$this->min_num=$min_num;
$this->max_num=$max_num;
}
function check($value)
{
$this->value=form_text($value);
settype($value, "integer");
if($this->only_positive==true && $value<0)
{
$value=0;
}
if($this->min_num<>0 && $value<$this->min_num)
{
$value=$this->min_num;
}
if($this->max_num<>0 && $value>$this->max_num)
{
$value=$this->max_num;
}
return $value;
}
function get_type_sql()
{
return 'INT('.$this->size.') NOT NULL';
}
/**
* This function is used for show the value on a human format
*/
public function show_formatted($value)
{
return $value;
}
function get_parameters_default()
{
return array($this->name_component, '', 0);
}
}
?>

File diff suppressed because it is too large Load diff

View file

@ -1168,7 +1168,7 @@ class Webmodel {
//Create form from model's components
$this->forms[$component_name]=new ModelForm($this->name, $component_name, $component->form, set_name_default($component_name), $component, $component->required, '');
$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]->set_all_parameters_form($component->get_parameters_default());
@ -1336,10 +1336,10 @@ class Webmodel {
public function set_component($name, $type, $arguments, $required=0)
{
$rc=new ReflectionClass($type);
$rc=new \ReflectionClass($type);
$this->components[$name]=$rc->newInstanceArgs($arguments);
//Set first label...
$this->components[$name]->label=set_name_default($name);
$this->components[$name]->label=Webmodel::set_name_default($name);
$this->components[$name]->name_model=$this->name;
$this->components[$name]->name_component=$name;
$this->components[$name]->required=$required;
@ -1396,6 +1396,20 @@ class Webmodel {
return $this->components[$name_component]->check($value);
}
/**
* A internal helper function
*
* @param string $name Name for process
*
*/
static public function set_name_default($name)
{
return ucfirst(str_replace('_', ' ', $name));
}
}
?>