Alpha Framework alpha--model--types
[ class tree: alpha--model--types ] [ index: alpha--model--types ] [ all elements ]

Source for file DEnumItem.inc

Documentation is available at DEnumItem.inc

  1. <?php
  2.  
  3. require_once $config->get('sysRoot').'alpha/model/types/AlphaTypeInterface.inc';
  4.  
  5. /**
  6.  * The DEnumItem (Dynamic Enum Item) complex data type.  Has a one-to-many
  7.  * relationship with the DEnum type.
  8.  * 
  9.  * @package alpha::model::types
  10.  * @since 1.0
  11.  * @author John Collins <dev@alphaframework.org>
  12.  * @version $Id: DEnumItem.inc 1453 2011-12-04 15:12:54Z johnc $
  13.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  14.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  15.  *  All rights reserved.
  16.  * 
  17.  *  <pre>
  18.  *  Redistribution and use in source and binary forms, with or
  19.  *  without modification, are permitted provided that the
  20.  *  following conditions are met:
  21.  * 
  22.  *  * Redistributions of source code must retain the above
  23.  *    copyright notice, this list of conditions and the
  24.  *    following disclaimer.
  25.  *  * Redistributions in binary form must reproduce the above
  26.  *    copyright notice, this list of conditions and the
  27.  *    following disclaimer in the documentation and/or other
  28.  *    materials provided with the distribution.
  29.  *  * Neither the name of the Alpha Framework nor the names
  30.  *    of its contributors may be used to endorse or promote
  31.  *    products derived from this software without specific
  32.  *    prior written permission.
  33.  *   
  34.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  35.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  36.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  37.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  39.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  41.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  42.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  43.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  44.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  45.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  46.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47.  *  </pre>
  48.  *  
  49.  */
  50. class DEnumItem extends AlphaDAO implements AlphaTypeInterface{
  51.     /**
  52.      * The value that will appear in the drop-down.
  53.      * 
  54.      * @var String 
  55.      * @since 1.0
  56.      */
  57.     protected $value;
  58.     
  59.     /**
  60.      * The ID of the parent DEnum object.
  61.      * 
  62.      * @var Integer 
  63.      * @since 1.0
  64.      */
  65.     protected $DEnumID;
  66.     
  67.     /**
  68.      * The name of the database table for the class
  69.      * 
  70.      * @var string 
  71.      * @since 1.0
  72.      */
  73.     const TABLE_NAME = 'DEnumItem';
  74.     
  75.     /**
  76.      * an array of data display labels for the class properties
  77.      * 
  78.      * @var array 
  79.      * @since 1.0
  80.      */
  81.     protected $dataLabels = array("OID"=>"DEnumItem ID#","value"=>"Dropdown value");
  82.     
  83.     /**
  84.      * The message to display to the user when validation fails
  85.      *
  86.      * @var string 
  87.      * @since 1.0
  88.      */
  89.     protected $helper = 'Not a valid DEnumItem value!';
  90.     
  91.     /**
  92.      * The constructor
  93.      * 
  94.      * @since 1.0
  95.      */
  96.     public function __construct({
  97.         // ensure to call the parent constructor
  98.         parent::__construct();
  99.         
  100.         $this->value = new String();
  101.         $this->value->setRule(AlphaValidator::REQUIRED_STRING);
  102.         $this->value->setHelper("A blank dropdown value is not allowed!");
  103.         $this->DEnumID = new Integer();
  104.         $this->markTransient('helper');        
  105.     }
  106.     
  107.     /**
  108.      * Loads all of the items for the given parent DEnum ID.
  109.      * 
  110.      * @param integer $EnumID The ID of the parent DEnum object.
  111.      * @return array 
  112.      * @since 1.0
  113.      * @throws AlphaException
  114.      */
  115.     public function loadItems($EnumID{        
  116.         global $config;
  117.         
  118.         $this->DEnumID->setValue($EnumID);
  119.         
  120.         $sqlQuery 'SELECT OID FROM '.self::TABLE_NAME.' WHERE DEnumID = \''.$EnumID.'\';';
  121.         
  122.         $provider AlphaDAOProviderFactory::getInstance($config->get('sysDBProviderName')$this);
  123.  
  124.         try{
  125.             $result $provider->query($sqlQuery);            
  126.         }catch(CustomQueryException $e{
  127.             throw new AlphaException('Failed to load objects, error is ['.$e->getMessage().']');
  128.             return array();
  129.         }
  130.         
  131.         // now build an array of objects to be returned
  132.         $objects array();
  133.         $count 0;        
  134.         
  135.         foreach($result as $row{
  136.             $obj new DEnumItem();
  137.             $obj->load($row['OID']);
  138.             $objects[$count$obj;
  139.             $count++;            
  140.         }        
  141.         
  142.         return $objects;    
  143.     }
  144.     
  145.     /**
  146.      * used to get the current DEnum item
  147.      * 
  148.      * @return String 
  149.      * @since 1.0
  150.      */
  151.     public function getValue({
  152.         return $this->value;
  153.     }
  154.     
  155.     /**
  156.      * used to set the current DEnum item
  157.      * 
  158.      * @param string $item 
  159.      * @since 1.0
  160.      */
  161.     public function setValue($item{
  162.         $this->value->setValue($item);        
  163.     }
  164.     
  165.     /**
  166.      * Getter for the validation helper string
  167.      * 
  168.      * @return string 
  169.      * @since 1.0
  170.      */    
  171.     public function getHelper({
  172.         return $this->helper;
  173.     }
  174.     
  175.     /**
  176.      * Set the validation helper text
  177.      *
  178.      * @param string $helper 
  179.      * @since 1.0
  180.      */
  181.     public function setHelper($helper{
  182.         $this->helper = $helper;
  183.     }
  184.     
  185.     /**
  186.      * Used to convert the object to a printable string
  187.      *
  188.      * @return string 
  189.      * @since 1.0
  190.      */
  191.     public function __toString({        
  192.         return strval($this->value);
  193.     }
  194. }

Documentation generated on Tue, 13 Dec 2011 20:26:41 +0000 by phpDocumentor 1.4.3