[
class tree: tangra_lib
] [
index: tangra_lib
] [
all elements
]
tangra_lib
Packages:
tangra_lib
Source for file form_field_integer_limited.class.php
Documentation is available at
form_field_integer_limited.class.php
<?php
// *** Tangra (Application Framework and Tools for PHP)
// $Id$
//
/**
* Contains class Form_Field_Date
*
*
@package
tangra_lib
*
@subpackage
form
*/
/**
*
*/
require_once
(
TANGRA_MAIN_DIR
.
'form/fields/integer/form_field_integer.class.php'
)
;
/**
* Represents text field that accepts limited integer
*
*
@package
tangra_lib
*
@subpackage
form
*/
class
Form_Field_Integer_Limited
extends
Form_Field_Integer
{
/**
* Minumum value
*
*
@var
integer
*
@internal
*/
private
$min_val
;
/**
* Maximum value
*
*
@var
integer
*
@internal
*/
private
$max_val
;
/**
* Constructor
*
*
@param
string
$name
Name of the field
*
@param
integer
$min_val
Minimum accepted value
*
@param
integer
$max_val
maximum accepted value
*
@param
boolean
$required
Is field required. Default is false
*
@param
integer
$maxlength
Maximum length of the text. Default is 10
*
@param
integer
$value
Default value
*/
function
__construct
(
$name
,
$min_val
,
$max_val
,
$required
=
false
,
$maxlength
=
100
,
$value
=
NULL
)
{
parent
::
__construct
(
$name
,
$required
,
$maxlength
,
$value
)
;
$this
->
set_min_val
(
$min_val
)
;
$this
->
set_max_val
(
$max_val
)
;
$this
->
add_potential_error
(
'integer_greater'
)
;
$this
->
add_potential_error
(
'integer_smaller'
)
;
}
/**
* Sets minimum accepted value
*
*
@param
integer
$min_val
*/
public
function
set_min_val
(
$min_val
)
{
tangra_if_not_int_throw_e
(
$min_val
)
;
$this
->
min_val
=
$min_val
;
}
/**
* Sets maximum accepted value
*
*
@param
integer
$max_val
*/
public
function
set_max_val
(
$max_val
)
{
tangra_if_not_int_throw_e
(
$max_val
)
;
$this
->
max_val
=
$max_val
;
}
/**
* Returns minimum accepted value
*
*
@return
integer
*/
public
function
get_min_val
(
)
{
return
$this
->
min_val
;
}
/**
* Returns maximum accepted value
*
*
@return
integer
*/
public
function
get_max_val
(
)
{
return
$this
->
max_val
;
}
/**
* Performs basic check for validity
*
*
@return
boolean
*
@internal
*/
public
function
basic_check
(
)
{
$has_errors
=
parent
::
basic_check
(
)
;
if
(
!
$has_errors
)
{
if
(
$this
->
get_html_value
(
)
<
$this
->
get_min_val
(
))
{
$this
->
set_error
(
'integer_smaller'
)
;
$has_errors
=
true
;
}
else
{
if
(
$this
->
get_html_value
(
)
>
$this
->
get_max_val
(
))
{
$this
->
set_error
(
'integer_greater'
)
;
$has_errors
=
true
;
}
}
}
return
$has_errors
;
}
/**
* Returns array with field properties
*
*
@return
array
*
@internal
*/
public
function
get_properties_array
(
)
{
$ret
=
parent
::
get_properties_array
(
)
;
$ret
[
'min_val'
]
=
$this
->
get_min_val
(
)
;
$ret
[
'max_val'
]
=
$this
->
get_max_val
(
)
;
return
$ret
;
}
}