Added new fields type
This commit is contained in:
parent
fce1896c8d
commit
0402ebebf0
6 changed files with 328 additions and 1902 deletions
90
src/CoreFields/IntegerField.php
Normal file
90
src/CoreFields/IntegerField.php
Normal 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);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue