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

Source for file ListBusinessObjects.php

Documentation is available at ListBusinessObjects.php

  1. <?php
  2.  
  3. // include the config file
  4. if(!isset($config)) {
  5.     require_once '../util/AlphaConfig.inc';
  6.     $config AlphaConfig::getInstance();
  7. }
  8.  
  9. require_once $config->get('sysRoot').'alpha/controller/AlphaController.inc';
  10. require_once $config->get('sysRoot').'alpha/view/AlphaView.inc';
  11. require_once $config->get('sysRoot').'alpha/controller/AlphaControllerInterface.inc';
  12.  
  13. /**
  14.  * 
  15.  * Controller used to list all of the business objects for the system
  16.  * 
  17.  * @package alpha::controller
  18.  * @since 1.0
  19.  * @author John Collins <dev@alphaframework.org>
  20.  * @version $Id: ListBusinessObjects.php 1341 2011-03-17 15:02:02Z johnc $
  21.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  22.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  23.  *  All rights reserved.
  24.  * 
  25.  *  <pre>
  26.  *  Redistribution and use in source and binary forms, with or
  27.  *  without modification, are permitted provided that the
  28.  *  following conditions are met:
  29.  * 
  30.  *  * Redistributions of source code must retain the above
  31.  *    copyright notice, this list of conditions and the
  32.  *    following disclaimer.
  33.  *  * Redistributions in binary form must reproduce the above
  34.  *    copyright notice, this list of conditions and the
  35.  *    following disclaimer in the documentation and/or other
  36.  *    materials provided with the distribution.
  37.  *  * Neither the name of the Alpha Framework nor the names
  38.  *    of its contributors may be used to endorse or promote
  39.  *    products derived from this software without specific
  40.  *    prior written permission.
  41.  *   
  42.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  43.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  44.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  45.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  46.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  47.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  48.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  49.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  50.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  51.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  52.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  53.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  54.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  55.  *  </pre>
  56.  *  
  57.  */
  58.     /**
  59.      * Trace logger
  60.      * 
  61.      * @var Logger 
  62.      * @since 1.0
  63.      */
  64.     private static $logger null;
  65.     
  66.     /**
  67.      * the constructor
  68.      * 
  69.      * @since 1.0
  70.      */
  71.     public function __construct({
  72.         self::$logger new Logger('ListBusinessObjects');
  73.         self::$logger->debug('>>__construct()');
  74.         
  75.         global $config;
  76.         
  77.         // ensure that the super class constructor is called, indicating the rights group
  78.         parent::__construct('Admin');
  79.         
  80.         // set up the title and meta details
  81.         $this->setTitle('Listing all business objects in the system');
  82.         $this->setDescription('Page to list all business objects.');
  83.         $this->setKeywords('list,all,business,objects');
  84.         
  85.         self::$logger->debug('<<__construct');
  86.     }
  87.     
  88.     /**
  89.      * Handle GET requests
  90.      * 
  91.      * @param array $params 
  92.      * @since 1.0
  93.      */
  94.     public function doGET($params{
  95.         self::$logger->debug('>>doGET($params=['.var_export($paramstrue).'])');
  96.         
  97.         echo AlphaView::displayPageHead($this);
  98.         
  99.         $this->displayBodyContent();
  100.         
  101.         echo AlphaView::displayPageFoot($this);
  102.         
  103.         self::$logger->debug('<<doGET');
  104.     }
  105.     
  106.     /**
  107.      * Handle POST requests
  108.      * 
  109.      * @param array $params 
  110.      * @since 1.0
  111.      */
  112.     public function doPOST($params{
  113.         self::$logger->debug('>>doPOST($params=['.var_export($paramstrue).'])');
  114.         
  115.         global $config;
  116.         
  117.         echo AlphaView::displayPageHead($this);
  118.         
  119.         try {
  120.             // check the hidden security fields before accepting the form POST data
  121.             if(!$this->checkSecurityFields())
  122.                 throw new SecurityException('This page cannot accept post data from remote servers!');
  123.         
  124.             if(isset($params['createTableBut'])) {
  125.                 try {                    
  126.                     $classname $params['createTableClass'];
  127.                     AlphaDAO::loadClassDef($classname);
  128.                         
  129.                     $BO new $classname();    
  130.                     $BO->makeTable();
  131.                 
  132.                     echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully created.');
  133.                 }catch(AlphaException $e{
  134.                     self::$logger->error($e->getMessage());
  135.                     echo AlphaView::displayErrorMessage('Error creating the table for the class '.$classname.', check the log!');
  136.                 }
  137.             }
  138.             
  139.             if(isset($params['recreateTableClass']&& $params['admin_'.$params['recreateTableClass'].'_button_pressed'== 'recreateTableBut'{
  140.                 try {                    
  141.                     $classname $params['recreateTableClass'];
  142.                     AlphaDAO::loadClassDef($classname);                    
  143.                     $BO new $classname();    
  144.                     $BO->rebuildTable();
  145.                     
  146.                     echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully recreated.');
  147.                 }catch(AlphaException $e{
  148.                     self::$logger->error($e->getTraceAsString());
  149.                     echo AlphaView::displayErrorMessage('Error recreating the table for the class '.$classname.', check the log!');
  150.                 }
  151.             }
  152.             
  153.             if(isset($params['updateTableClass']&& $params['admin_'.$params['updateTableClass'].'_button_pressed'== 'updateTableBut'{
  154.                 try {
  155.                     $classname $params['updateTableClass'];
  156.                     AlphaDAO::loadClassDef($classname);
  157.                         
  158.                     $BO new $classname();
  159.                     $missingFields $BO->findMissingFields();
  160.                     
  161.                     $count count($missingFields);
  162.                     
  163.                     for($i 0$i $count$i++)
  164.                         $BO->addProperty($missingFields[$i]);
  165.                     
  166.                     echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully updated.');
  167.                 }catch(AlphaException $e{
  168.                     self::$logger->error($e->getTraceAsString());
  169.                     echo AlphaView::displayErrorMessage('Error updating the table for the class '.$classname.', check the log!');
  170.                 }
  171.             }
  172.         }catch(SecurityException $e{
  173.             echo AlphaView::displayErrorMessage($e->getMessage());
  174.             self::$logger->warn($e->getMessage());
  175.         }
  176.         
  177.         $this->displayBodyContent();
  178.                 
  179.         echo AlphaView::displayPageFoot($this);
  180.         
  181.         self::$logger->debug('<<doPOST');
  182.     }
  183.     
  184.     /**
  185.      * Private method to display the main body HTML for this page
  186.      * 
  187.      * @since 1.0
  188.      */
  189.     private function displayBodyContent({
  190.         $classNames AlphaDAO::getBOClassNames();
  191.         $loadedClasses array();
  192.         
  193.         foreach($classNames as $classname{
  194.             AlphaDAO::loadClassDef($classname);
  195.             array_push($loadedClasses$classname);
  196.         }
  197.         
  198.         foreach($loadedClasses as $classname{
  199.             try {
  200.                 $BO new $classname();
  201.                 $BO_View AlphaView::getInstance($BO);                
  202.                 $BO_View->adminView();                
  203.             }catch (AlphaException $e{
  204.                 self::$logger->error("[$classname]:".$e->getMessage());
  205.                 // its possible that the exception occured due to the table schema being out of date
  206.                 if($BO->checkTableExists(&& $BO->checkTableNeedsUpdate()) {                
  207.                     $missingFields $BO->findMissingFields();
  208.                 
  209.                     $count count($missingFields);
  210.                     
  211.                     for($i 0$i $count$i++)
  212.                         $BO->addProperty($missingFields[$i]);
  213.                         
  214.                     // now try again...
  215.                     $BO new $classname();
  216.                     $BO_View AlphaView::getInstance($BO);
  217.                     $BO_View->adminView();
  218.                 }
  219.             }catch (Exception $e{
  220.                 self::$logger->error($e->getMessage());
  221.                 echo AlphaView::displayErrorMessage('Error accessing the class ['.$classname.'], check the log!');
  222.             }
  223.         }
  224.     }
  225. }
  226.  
  227. // now build the new controller
  228. if(basename($_SERVER['PHP_SELF']== 'ListBusinessObjects.php'{
  229.     $controller new ListBusinessObjects();
  230.     
  231.     if(!empty($_POST)) {            
  232.         $controller->doPOST($_REQUEST);
  233.     }else{
  234.         $controller->doGET($_GET);
  235.     }
  236. }
  237.  
  238. ?>

Documentation generated on Thu, 17 Mar 2011 16:44:29 +0000 by phpDocumentor 1.4.3