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 1453 2011-12-04 15:12:54Z 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.      * @param string $visibility The name of the rights group that can access this controller.
  96.      * @since 1.0
  97.      */
  98.     public function __construct($visibility='Standard'{
  99.         self::$logger new Logger('Detail');
  100.         self::$logger->debug('>>__construct()');
  101.         
  102.         global $config;
  103.                 
  104.         // ensure that the super class constructor is called, indicating the rights group
  105.         parent::__construct($visibility);
  106.         
  107.         self::$logger->debug('<<__construct');
  108.     }
  109.     
  110.     /**
  111.      * Handle GET requests
  112.      * 
  113.      * @param array $params 
  114.      * @throws ResourceNotFoundException
  115.      * @throws IllegalArguementException
  116.      * @since 1.0
  117.      */
  118.     public function doGET($params{
  119.         self::$logger->debug('>>doGET(params=['.var_export($paramstrue).'])');
  120.         
  121.         try{
  122.             // load the business object (BO) definition
  123.             if (isset($params['bo']&& isset($params['oid'])) {
  124.                 if(!AlphaValidator::isInteger($params['oid']))
  125.                     throw new IllegalArguementException('Invalid oid ['.$params['oid'].'] provided on the request!');
  126.                 
  127.                 $BOName $params['bo'];
  128.                 AlphaDAO::loadClassDef($BOName);
  129.                 
  130.                 /*
  131.                  *  check and see if a custom create controller exists for this BO, and if it does use it otherwise continue
  132.                  */
  133.                 if($this->getCustomControllerName($BOName'view'!= null)
  134.                     $this->loadCustomController($BOName'view');
  135.                 
  136.                 $this->BO = new $BOName();
  137.                 $this->BO->load($params['oid']);                
  138.                 AlphaDAO::disconnect();
  139.                             
  140.                 $this->BOName $BOName;        
  141.                 $this->BOView AlphaView::getInstance($this->BO);
  142.                 
  143.                 echo AlphaView::displayPageHead($this);                
  144.                 echo AlphaView::renderDeleteForm();                
  145.                 echo $this->BOView->detailedView();
  146.             }else{
  147.                 throw new IllegalArguementException('No BO available to display!');
  148.             }
  149.         }catch(IllegalArguementException $e{
  150.             self::$logger->warn($e->getMessage());
  151.             throw new ResourceNotFoundException('The file that you have requested cannot be found!');
  152.         }catch(BONotFoundException $e{
  153.             self::$logger->warn($e->getMessage());
  154.             throw new ResourceNotFoundException('The item that you have requested cannot be found!');
  155.         }
  156.         
  157.         echo AlphaView::displayPageFoot($this);
  158.         self::$logger->debug('<<doGET');
  159.     }
  160.     
  161.     /**
  162.      * Method to handle POST requests
  163.      * 
  164.      * @param array $params 
  165.      * @throws IllegalArguementException
  166.      * @throws SecurityException
  167.      * @since 1.0
  168.      */
  169.     public function doPOST($params{
  170.         self::$logger->debug('>>doPOST(params=['.var_export($paramstrue).'])');
  171.         
  172.         global $config;
  173.         
  174.         echo AlphaView::displayPageHead($this);
  175.         
  176.         try {
  177.             // check the hidden security fields before accepting the form POST data
  178.             if(!$this->checkSecurityFields())
  179.                 throw new SecurityException('This page cannot accept post data from remote servers!');
  180.             
  181.             // load the business object (BO) definition
  182.             if (isset($params['bo'])) {
  183.                 $BOName $params['bo'];
  184.                 AlphaDAO::loadClassDef($BOName);
  185.                 
  186.                 $this->BO = new $BOName();
  187.                 $this->BOname $BOName;        
  188.                 $this->BOView AlphaView::getInstance($this->BO);
  189.         
  190.                 if (!empty($params['deleteOID'])) {
  191.                     if(!AlphaValidator::isInteger($params['deleteOID']))
  192.                         throw new IllegalArguementException('Invalid deleteOID ['.$params['deleteOID'].'] provided on the request!');
  193.                     
  194.                     $temp new $BOName();
  195.                     $temp->load($params['deleteOID']);
  196.                     
  197.                     try {
  198.                         AlphaDAO::begin();
  199.                         $temp->delete();
  200.                         AlphaDAO::commit();
  201.  
  202.                         echo AlphaView::displayUpdateMessage($BOName.' '.$params['deleteOID'].' deleted successfully.');
  203.                                         
  204.                         echo '<center>';
  205.                         
  206.                         $temp new Button("document.location = '".FrontController::generateSecureURL('act=ListAll&bo='.get_class($this->BO))."'",
  207.                             'Back to List','cancelBut');
  208.                         echo $temp->render();
  209.                         
  210.                         echo '</center>';
  211.                     }catch(AlphaException $e{
  212.                         self::$logger->error($e->getMessage());
  213.                         echo AlphaView::displayErrorMessage('Error deleting the BO of OID ['.$params['deleteOID'].'], check the log!');
  214.                         AlphaDAO::rollback();
  215.                     }
  216.                     
  217.                     AlphaDAO::disconnect();
  218.                 }
  219.             }else{
  220.                 throw new IllegalArguementException('No BO available to display!');
  221.             }
  222.         }catch(SecurityException $e{
  223.             self::$logger->warn($e->getMessage());
  224.             throw new ResourceNotAllowedException($e->getMessage());
  225.         }catch(IllegalArguementException $e{
  226.             self::$logger->warn($e->getMessage());
  227.             throw new ResourceNotFoundException('The file that you have requested cannot be found!');
  228.         }catch(BONotFoundException $e{
  229.             self::$logger->warn($e->getMessage());
  230.             throw new ResourceNotFoundException('The item that you have requested cannot be found!');
  231.         }
  232.         
  233.         echo AlphaView::displayPageFoot($this);
  234.         self::$logger->debug('<<doPOST');
  235.     }
  236.     
  237.     /**
  238.      * Sets up the title etc.
  239.      * 
  240.      * @since 1.0
  241.      */
  242.     public function before_displayPageHead_callback({
  243.         if($this->title == '')
  244.             $this->setTitle('Displaying '.$this->BOName.' number '.$this->BO->getID());
  245.         if($this->description == '')
  246.             $this->setDescription('Page to display '.$this->BOName.' number '.$this->BO->getID());
  247.         if($this->keywords == '')
  248.             $this->setKeywords('display,details,'.$this->BOName);
  249.     }
  250. }
  251.  
  252. // now build the new controller
  253. if(basename($_SERVER['PHP_SELF']== 'Detail.php'{
  254.     $controller new Detail();
  255.     
  256.     if(!empty($_POST)) {            
  257.         $controller->doPOST($_REQUEST);
  258.     }else{
  259.         $controller->doGET($_GET);
  260.     }
  261. }
  262.  
  263. ?>

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