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

Source for file ListDEnums.php

Documentation is available at ListDEnums.php

  1. <?php
  2.  
  3. // include the config file
  4. if(!isset($config)) {
  5.     require_once '../util/configLoader.inc';
  6.     $config configLoader::getInstance();
  7. }
  8.  
  9. require_once $config->get('sysRoot').'alpha/controller/ListAll.php';
  10. require_once $config->get('sysRoot').'alpha/model/types/DEnum.inc';
  11. require_once $config->get('sysRoot').'alpha/model/types/DEnumItem.inc';
  12. require_once $config->get('sysRoot').'alpha/view/DEnumView.inc';
  13. require_once $config->get('sysRoot').'alpha/controller/AlphaControllerInterface.inc';
  14.  
  15. /**
  16.  * 
  17.  * Controller used to list all DEnums
  18.  * 
  19.  * @package alpha::controller
  20.  * @since 1.0
  21.  * @author John Collins <dev@alphaframework.org>
  22.  * @version $Id: ListDEnums.php 1453 2011-12-04 15:12:54Z johnc $
  23.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  24.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  25.  *  All rights reserved.
  26.  * 
  27.  *  <pre>
  28.  *  Redistribution and use in source and binary forms, with or
  29.  *  without modification, are permitted provided that the
  30.  *  following conditions are met:
  31.  * 
  32.  *  * Redistributions of source code must retain the above
  33.  *    copyright notice, this list of conditions and the
  34.  *    following disclaimer.
  35.  *  * Redistributions in binary form must reproduce the above
  36.  *    copyright notice, this list of conditions and the
  37.  *    following disclaimer in the documentation and/or other
  38.  *    materials provided with the distribution.
  39.  *  * Neither the name of the Alpha Framework nor the names
  40.  *    of its contributors may be used to endorse or promote
  41.  *    products derived from this software without specific
  42.  *    prior written permission.
  43.  *   
  44.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  45.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  46.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  47.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  48.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  49.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  50.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  51.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  52.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  53.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  54.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  55.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  56.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  57.  *  </pre>
  58.  *  
  59.  */
  60. class ListDEnums extends ListAll implements AlphaControllerInterface {
  61.     /**
  62.      * Trace logger
  63.      * 
  64.      * @var Logger 
  65.      * @since 1.0
  66.      */
  67.     private static $logger null;
  68.     
  69.     /**
  70.      * constructor to set up the object
  71.      * 
  72.      * @since 1.0
  73.      */
  74.     public function __construct({
  75.         self::$logger new Logger('ListDEnums');
  76.         self::$logger->debug('>>__construct()');
  77.         
  78.         // ensure that the super class constructor is called, indicating the rights group
  79.         parent::__construct('Admin');
  80.         
  81.         $this->BO = new DEnum();
  82.         
  83.         // make sure that the DEnum tables exist
  84.         if(!$this->BO->checkTableExists()) {
  85.             echo AlphaView::displayErrorMessage('Warning! The DEnum tables do not exist, attempting to create them now...');
  86.             $this->createDEnumTables();
  87.         }
  88.         
  89.         $this->BOname = 'DEnum';
  90.         
  91.         $this->BOView = AlphaView::getInstance($this->BO);
  92.         
  93.         // set up the title and meta details
  94.         $this->setTitle('Listing all DEnums');
  95.         $this->setDescription('Page to list all DEnums.');
  96.         $this->setKeywords('list,all,DEnums');
  97.         
  98.         self::$logger->debug('<<__construct');
  99.     }
  100.     
  101.     /**
  102.      * Handle GET requests
  103.      * 
  104.      * @param array $params 
  105.      * @since 1.0
  106.      */
  107.     public function doGET($params{
  108.         self::$logger->debug('>>doGET($params=['.var_export($paramstrue).'])');
  109.         
  110.         echo AlphaView::displayPageHead($this);
  111.         
  112.         // get all of the BOs and invoke the list_view on each one
  113.         $temp new DEnum();
  114.         // set the start point for the list pagination
  115.         if (isset($params['start']$this->startPoint = $params['start']$this->startPoint = 1);
  116.             
  117.         $objects $temp->loadAll($this->startPoint);
  118.         
  119.         AlphaDAO::disconnect();
  120.             
  121.         $this->BOCount = $this->BO->getCount();
  122.         
  123.         echo AlphaView::renderDeleteForm();
  124.         
  125.         foreach($objects as $object{
  126.             $temp AlphaView::getInstance($object);
  127.             echo $temp->listView();
  128.         }
  129.         
  130.         echo AlphaView::displayPageFoot($this);
  131.         
  132.         self::$logger->debug('<<doGET');        
  133.     }
  134.     
  135.     /**
  136.      * Handle POST requests
  137.      * 
  138.      * @param array $params 
  139.      * @since 1.0
  140.      */
  141.     public function doPOST($params{
  142.         self::$logger->debug('>>doPOST($params=['.var_export($paramstrue).'])');
  143.         
  144.         self::$logger->debug('<<doPOST');        
  145.     }
  146.     
  147.     /**
  148.      * Method to create the DEnum tables if they don't exist
  149.      * 
  150.      * @since 1.0
  151.      */
  152.     private function createDEnumTables({
  153.         $tmpDEnum new DEnum();
  154.  
  155.         echo '<p>Attempting to build table '.DEnum::TABLE_NAME.' for class DEnum : </p>';
  156.         
  157.         try {
  158.             $tmpDEnum->makeTable();
  159.             echo AlphaView::displayUpdateMessage('Successfully re-created the database table '.DEnum::TABLE_NAME);
  160.         }catch(AlphaException $e{
  161.             echo AlphaView::displayErrorMessage('Failed re-created the database table '.DEnum::TABLE_NAME.', check the log');
  162.             self::$logger->error($e->getMessage());
  163.         }
  164.         
  165.         $tmpDEnumItem new DEnumItem();
  166.         
  167.         echo '<p>Attempting to build table '.DEnumItem::TABLE_NAME.' for class DEnumItem : </p>';
  168.         
  169.         try {
  170.             $tmpDEnumItem->makeTable();
  171.             echo AlphaView::displayUpdateMessage('Successfully re-created the database table '.DEnumItem::TABLE_NAME);
  172.         }catch(AlphaException $e{
  173.             echo AlphaView::displayErrorMessage('Failed re-created the database table '.DEnumItem::TABLE_NAME.', check the log');
  174.             self::$logger->error($e->getMessage());
  175.         }            
  176.     }
  177. }
  178.  
  179. // now build the new controller if this file is called directly
  180. if ('ListDEnums.php' == basename($_SERVER['PHP_SELF'])) {
  181.     $controller new ListDEnums();
  182.     
  183.     if(!empty($_POST)) {            
  184.         $controller->doPOST($_POST);
  185.     }else{
  186.         $controller->doGET($_GET);
  187.     }
  188. }
  189.  
  190. ?>

Documentation generated on Tue, 13 Dec 2011 20:27:09 +0000 by phpDocumentor 1.4.3