Source for file DEnum.inc
Documentation is available at DEnum.inc
require_once $config->get('sysRoot'). 'alpha/model/types/AlphaTypeInterface.inc';
* The DEnum (Dynamic Enum) complex data type. Similiar to Enum,
* except list items are stored in a database table and are editable.
* @package alpha::model::types
* @author John Collins <dev@alphaframework.org>
* @version $Id: DEnum.inc 1341 2011-03-17 15:02:02Z johnc $
* @license http://www.opensource.org/licenses/bsd-license.php The BSD License
* @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
* Redistribution and use in source and binary forms, with or
* without modification, are permitted provided that the
* following conditions are met:
* * Redistributions of source code must retain the above
* copyright notice, this list of conditions and the
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the
* following disclaimer in the documentation and/or other
* materials provided with the distribution.
* * Neither the name of the Alpha Framework nor the names
* of its contributors may be used to endorse or promote
* products derived from this software without specific
* prior written permission.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* An array of valid DEnum options
* The currently selected DEnum option
* The name of the DEnum used in the database
* The name of the database table for the class
* An array of data display labels for the class properties
protected $dataLabels = array("OID"=> "DEnum ID#","name"=> "Name");
* The message to display to the user when validation fails
protected $helper = 'Not a valid denum option!';
* Constructor that sets up the DEnum options
// ensure to call the parent constructor
// DEnum does not exist so create it
* Setter for the name of the DEnum used in the database
* Get the array of DEnum options from the database
* @param boolean $alphaSort
$sqlQuery = 'SELECT * FROM '. self::TABLE_NAME. ' WHERE name = \''. $this->name->getValue(). '\';';
// now build an array of item indexes to be returned
$row = $result->fetch_array(MYSQLI_ASSOC);
foreach($tmp->loadItems($row["OID"]) as $DEnumItem) {
$this->options[$DEnumItem->getID()] = $DEnumItem->getValue();
* Getter for the validation helper string
* Set the validation helper text
* Used to get the current DEnum item selected index value
* Used to get the current DEnum item string value
// check to see if the options have already been loaded from the DB
* Used to select the current DEnum item
// check to see if the options have already been loaded from the DB
// confirm that the item ID provided is a valid key for the options array
* Gets the count from the database of the DEnumItems associated with this object
$sqlQuery = 'SELECT COUNT(OID) AS item_count FROM DEnumItem WHERE DEnumID = \''. $this->getID(). '\';';
throw new AlphaException('Failed to get the item count for the DEnum.');
$row = $result->fetch_array(MYSQLI_ASSOC);
if (isset ($row['item_count'])) {
return $row['item_count'];
* Used to get the DenumItem ID for the given option name
* @param string $optionName
$denumItem->loadByAttribute('value', $optionName);
$id = $denumItem->getID();
* Used to convert the object to a printable string
|