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

Source for file Detail.php

Documentation is available at Detail.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. require_once $config->get('sysRoot').'alpha/util/helpers/AlphaValidator.inc';
  13.  
  14. /**
  15.  * 
  16.  * Controller used to display the details of a BO, which must be supplied in GET vars
  17.  * 
  18.  * @package alpha::controller
  19.  * @since 1.0
  20.  * @author John Collins <dev@alphaframework.org>
  21.  * @version $Id: Detail.php 1341 2011-03-17 15:02:02Z johnc $
  22.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  23.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  24.  *  All rights reserved.
  25.  * 
  26.  *  <pre>
  27.  *  Redistribution and use in source and binary forms, with or
  28.  *  without modification, are permitted provided that the
  29.  *  following conditions are met:
  30.  * 
  31.  *  * Redistributions of source code must retain the above
  32.  *    copyright notice, this list of conditions and the
  33.  *    following disclaimer.
  34.  *  * Redistributions in binary form must reproduce the above
  35.  *    copyright notice, this list of conditions and the
  36.  *    following disclaimer in the documentation and/or other
  37.  *    materials provided with the distribution.
  38.  *  * Neither the name of the Alpha Framework nor the names
  39.  *    of its contributors may be used to endorse or promote
  40.  *    products derived from this software without specific
  41.  *    prior written permission.
  42.  *   
  43.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  44.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  45.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  46.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  47.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  48.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  49.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  50.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  51.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  52.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  53.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  54.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  55.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  56.  *  </pre>
  57.  *  
  58.  */
  59. class Detail extends AlphaController implements AlphaControllerInterface {
  60.     /**
  61.      * The BO to be displayed
  62.      * 
  63.      * @var AlphaDAO 
  64.      * @since 1.0
  65.      */
  66.     protected $BO;
  67.     
  68.     /**
  69.      * The name of the BO
  70.      * 
  71.      * @var string 
  72.      * @since 1.0
  73.      */
  74.     private $BOName;
  75.     
  76.     /**
  77.      * The default AlphaView object used for rendering the business object
  78.      * 
  79.      * @var AlphaView 
  80.      * @since 1.0
  81.      */
  82.     private $BOView;
  83.     
  84.     /**
  85.      * Trace logger
  86.      * 
  87.      * @var Logger 
  88.      * @since 1.0
  89.      */
  90.     private static $logger null;
  91.     
  92.     /**
  93.      * constructor to set up the object
  94.      * 
  95.      * @since 1.0
  96.      */
  97.     public function __construct({
  98.         self::$logger new Logger('Detail');
  99.         self::$logger->debug('>>__construct()');
  100.         
  101.         global $config;
  102.                 
  103.         // ensure that the super class constructor is called, indicating the rights group
  104.         parent::__construct('Standard');
  105.         
  106.         self::$logger->debug('<<__construct');
  107.     }
  108.     
  109.     /**
  110.      * Handle GET requests
  111.      * 
  112.      * @param array $params 
  113.      * @throws ResourceNotFoundException
  114.      * @throws IllegalArguementException
  115.      * @since 1.0
  116.      */
  117.     public function doGET($params{
  118.         self::$logger->debug('>>doGET(params=['.var_export($paramstrue).'])');
  119.         
  120.         try{
  121.             // load the business object (BO) definition
  122.             if (isset($params['bo']&& isset($params['oid'])) {
  123.                 if(!AlphaValidator::isInteger($params['oid']))
  124.                     throw new IllegalArguementException('Invalid oid ['.$params['oid'].'] provided on the request!');
  125.                 
  126.                 $BOName $params['bo'];
  127.                 AlphaDAO::loadClassDef($BOName);
  128.                 
  129.                 /*
  130.                  *  check and see if a custom create controller exists for this BO, and if it does use it otherwise continue
  131.                  */
  132.                 if($this->getCustomControllerName($BOName'view'!= null)
  133.                     $this->loadCustomController($BOName'view');
  134.                 
  135.                 $this->BO = new $BOName();
  136.                 $this->BO->load($params['oid']);                
  137.                 AlphaDAO::disconnect();
  138.                             
  139.                 $this->BOName $BOName;        
  140.                 $this->BOView AlphaView::getInstance($this->BO);
  141.                 
  142.                 echo AlphaView::displayPageHead($this);                
  143.                 echo AlphaView::renderDeleteForm();                
  144.                 echo $this->BOView->detailedView();
  145.             }else{
  146.                 throw new IllegalArguementException('No BO available to display!');
  147.             }
  148.         }catch(IllegalArguementException $e{
  149.             self::$logger->warn($e->getMessage());
  150.             throw new ResourceNotFoundException('The file that you have requested cannot be found!');
  151.         }catch(BONotFoundException $e{
  152.             self::$logger->warn($e->getMessage());
  153.             throw new ResourceNotFoundException('The item that you have requested cannot be found!');
  154.         }
  155.         
  156.         echo AlphaView::displayPageFoot($this);
  157.         self::$logger->debug('<<doGET');
  158.     }
  159.     
  160.     /**
  161.      * Method to handle POST requests
  162.      * 
  163.      * @param array $params 
  164.      * @throws IllegalArguementException
  165.      * @throws SecurityException
  166.      * @since 1.0
  167.      */
  168.     public function doPOST($params{
  169.         self::$logger->debug('>>doPOST(params=['.var_export($paramstrue).'])');
  170.         
  171.         global $config;
  172.         
  173.         echo AlphaView::displayPageHead($this);
  174.         
  175.         try {
  176.             // check the hidden security fields before accepting the form POST data
  177.             if(!$this->checkSecurityFields())
  178.                 throw new SecurityException('This page cannot accept post data from remote servers!');
  179.             
  180.             // load the business object (BO) definition
  181.             if (isset($params['bo'])) {
  182.                 $BOName $params['bo'];
  183.                 AlphaDAO::loadClassDef($BOName);
  184.                 
  185.                 $this->BO = new $BOName();
  186.                 $this->BOname $BOName;        
  187.                 $this->BOView AlphaView::getInstance($this->BO);
  188.         
  189.                 if (!empty($params['deleteOID'])) {
  190.                     if(!AlphaValidator::isInteger($params['deleteOID']))
  191.                         throw new IllegalArguementException('Invalid deleteOID ['.$params['deleteOID'].'] provided on the request!');
  192.                     
  193.                     $temp new $BOName();
  194.                     $temp->load($params['deleteOID']);
  195.                     
  196.                     try {
  197.                         AlphaDAO::begin();
  198.                         $temp->delete();
  199.                         AlphaDAO::commit();
  200.  
  201.                         echo AlphaView::displayUpdateMessage($BOName.' '.$params['deleteOID'].' deleted successfully.');
  202.                                         
  203.                         echo '<center>';
  204.                         
  205.                         $temp new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'",
  206.                             'Back to List','cancelBut');
  207.                         echo $temp->render();
  208.                         
  209.                         echo '</center>';
  210.                     }catch(AlphaException $e{
  211.                         self::$logger->error($e->getMessage());
  212.                         echo AlphaView::displayErrorMessage('Error deleting the BO of OID ['.$params['deleteOID'].'], check the log!');
  213.                         AlphaDAO::rollback();
  214.                     }
  215.                     
  216.                     AlphaDAO::disconnect();
  217.                 }
  218.             }else{
  219.                 throw new IllegalArguementException('No BO available to display!');
  220.             }
  221.         }catch(SecurityException $e{
  222.             self::$logger->warn($e->getMessage());
  223.             throw new ResourceNotAllowedException($e->getMessage());
  224.         }catch(IllegalArguementException $e{
  225.             self::$logger->warn($e->getMessage());
  226.             throw new ResourceNotFoundException('The file that you have requested cannot be found!');
  227.         }catch(BONotFoundException $e{
  228.             self::$logger->warn($e->getMessage());
  229.             throw new ResourceNotFoundException('The item that you have requested cannot be found!');
  230.         }
  231.         
  232.         echo AlphaView::displayPageFoot($this);
  233.         self::$logger->debug('<<doPOST');
  234.     }
  235.     
  236.     /**
  237.      * Sets up the title etc.
  238.      * 
  239.      * @since 1.0
  240.      */
  241.     public function before_displayPageHead_callback({
  242.         $this->setTitle('Displaying '.$this->BOName.' number '.$this->BO->getID());
  243.         $this->setDescription('Page to display '.$this->BOName.' number '.$this->BO->getID());
  244.         $this->setKeywords('display,details,'.$this->BOName);
  245.     }
  246. }
  247.  
  248. // now build the new controller
  249. if(basename($_SERVER['PHP_SELF']== 'Detail.php'{
  250.     $controller new Detail();
  251.     
  252.     if(!empty($_POST)) {            
  253.         $controller->doPOST($_REQUEST);
  254.     }else{
  255.         $controller->doGET($_GET);
  256.     }
  257. }
  258.  
  259. ?>

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