Source for file arraychoicelist.php
Documentation is available at arraychoicelist.php
* a choice list like DBChoiceList *not* based on an SQL statement
* @author Stuart Prescott
* @copyright Copyright Stuart Prescott
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @subpackage FormsLibrary
/** Load ancillary functions */
require_once 'inc/typeinfo.php';
* Provide a non-database filled (i.e. array-filled) version of DBChoiceList
* See DBChoiceList for more details of interface.
* @subpackage FormsLibrary
/** @var string id value currently selected */
/** @var boolean list is editable */
/** @var boolean list is extensible by user */
/** @var boolean list has changed */
/** @var array list of array($listKey => $unique_name, $displayKey => $displayed_value) */
/** @var integer number of items in the list */
/** @var string array index in which to store the unique_name */
/** @var string array index in which to store the displayed_value */
/** @var integer status code for out-of-band error reporting */
/** @var string error message for out-of-band error reporting */
/** @var integer debug level for object 0=off. */
* Create a new ArrayChoiceList object
* @param array $array list of unique_name => displayed_value
* @param string $iv index in which the unique_name should be stored in the ChoiceList
* @param string $dv index in which the displayed_value should be stored in the ChoiceList
foreach ($array as $internalVal =>
$displayVal) {
* Construct an array suitable for storing the field and the values it takes for later reuse
* @param array $values list of values to be displayed
* @param Field $field Field object associated with these values
* append a special field (such as "Create new:") to the choicelist
* This method is much simpler than the DB equivalent as we won't need to remember them.
* @see DBChoiceList::append()
* @param array $values list of values to be displayed
* @param Field $field (optional) a field class object to be placed next to this entry, if possible
function append($values, $field=
'') {
* prepend a special field (such as "Create new:") to the choicelist
* This method is much simpler than the DB equivalent as we won't need to remember them.
* @param array $values list of values to be displayed
* @param Field $field (optional) a field class object to be placed next to this entry, if possible
function prepend($values, $field=
'') {
* display the contents of the list
* @return string text representation of the field
* display the contents of the list
* @return string text representation of the field
* update the value of the list based on user data:
* - if it is within the range of current values, then take the value
* - if the field contains a new value (and is allowed to) then keep
* an illegal value, mark as being changed, and wait until later for
* the field to be updated
* - if the field contains a new value (and is not allowed to) or an
* out-of-range value, then flag as being invalid
* @param string $newval the (possibly) new value for the field
* @param array ancillary user data (passed on to any appended or prepended fields)
function update($newval, $data) {
echo
'ArrayChoiceList update: ';
//check to see if the newval is legal (does it exist on our choice list?)
if ($this->DEBUG) echo
"($isExisting:".
$v['id'].
":$newval)";
if ($v['id'] ==
$newval &&
$v['id'] >=
0) {
// it is a legal, existing value, so we adopt it
if ($this->DEBUG) echo
'isExisting';
//isValid handling done by the Field that inherits it
// then it is a new value and we should accept it
if ($this->DEBUG) echo
'isExtending';
//If we are extending the list, then we should have a negative
//number as the current value to trip the creation of the new
//entry later on in sync()
if (isset
($v['_field']) &&
$v['_field'] !=
"") {
$this->isValid +=
$this->choicelist[$k]['_field']->isValid();
if ($this->DEBUG) echo
'isInvalid';
// else, it's a new value and we should not accept it
#echo " DBchoiceList::changed=$this->changed<br />";
* set the currently selected value
* @param string $value new value to use as curretly selected
#echo "DBchoiceList::set = $value<br/>";
* synchronise: but we have nothing to do as we are not attached to the db
* (provided to give interface to normal Field database)
* @return boolean false -- there was nothing to do
* generate name=value pairs in case someone actually wants them!
* @return string of form name='value'
#echo "This has changed";
if (isset
($v['_field'])) {
$vals[] =
$v['_field']->name .
"=".
qw($v['_field']->value);
#echo "<pre>"; print_r($this->choicelist); echo "</pre>";
#echo "<pre>"; print_r($this->fields); echo "</pre>";
#echo "<pre>"; print_r($vals); echo "</pre>";
* determine whih values are selected and return them
* @param boolean $returnArray return an array of values
* @return mixed list of selected values (array) or current value (string)
//echo "H:$this->idfield, $k, $v, $this->id";
foreach ($this->fields as $f) {
* set which option in the selection list is the default option
* @param string $val default value to use
//echo "ArrayChoiceList::setDefault: $val";
if (isset
($this->id) ||
$this->id <
0) {
} // class ArrayChoiceList
Documentation generated on Tue, 06 Mar 2007 10:00:33 +0000 by phpDocumentor 1.3.0