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

Source for file EditDEnum.php

Documentation is available at EditDEnum.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/Edit.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. require_once $config->get('sysRoot').'alpha/exceptions/IllegalArguementException.inc';
  15. require_once $config->get('sysRoot').'alpha/exceptions/BONotFoundException.inc';
  16. require_once $config->get('sysRoot').'alpha/exceptions/FailedSaveException.inc';
  17.  
  18. /**
  19.  * 
  20.  * Controller used to edit DEnums and associated DEnumItems
  21.  * 
  22.  * @package alpha::controller
  23.  * @since 1.0
  24.  * @author John Collins <dev@alphaframework.org>
  25.  * @version $Id: EditDEnum.php 1453 2011-12-04 15:12:54Z johnc $
  26.  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
  27.  * @copyright Copyright (c) 2011, John Collins (founder of Alpha Framework).
  28.  *  All rights reserved.
  29.  * 
  30.  *  <pre>
  31.  *  Redistribution and use in source and binary forms, with or
  32.  *  without modification, are permitted provided that the
  33.  *  following conditions are met:
  34.  * 
  35.  *  * Redistributions of source code must retain the above
  36.  *    copyright notice, this list of conditions and the
  37.  *    following disclaimer.
  38.  *  * Redistributions in binary form must reproduce the above
  39.  *    copyright notice, this list of conditions and the
  40.  *    following disclaimer in the documentation and/or other
  41.  *    materials provided with the distribution.
  42.  *  * Neither the name of the Alpha Framework nor the names
  43.  *    of its contributors may be used to endorse or promote
  44.  *    products derived from this software without specific
  45.  *    prior written permission.
  46.  *   
  47.  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  48.  *  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  49.  *  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  50.  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  51.  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
  52.  *  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  53.  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  54.  *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  55.  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  56.  *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  57.  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  58.  *  OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  59.  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  60.  *  </pre>
  61.  *  
  62.  */
  63. class EditDEnum extends Edit implements AlphaControllerInterface {
  64.     /**
  65.      * Trace logger
  66.      * 
  67.      * @var Logger 
  68.      * @since 1.0
  69.      */
  70.     private static $logger null;
  71.     
  72.     /**
  73.      * constructor to set up the object
  74.      * 
  75.      * @since 1.0
  76.      */
  77.     public function __construct({
  78.         self::$logger new Logger('EditDEnum');
  79.         self::$logger->debug('>>__construct()');
  80.         
  81.         // ensure that the super class constructor is called, indicating the rights group
  82.         parent::__construct('Admin');
  83.         
  84.         // set up the title and meta details
  85.         $this->setTitle('Editing a DEnum');
  86.         $this->setDescription('Page to edit a DEnum.');
  87.         $this->setKeywords('edit,DEnum');
  88.         
  89.         $this->BO = new DEnum();
  90.         
  91.         self::$logger->debug('<<__construct');
  92.     }
  93.     
  94.     /**
  95.      * Handle GET requests
  96.      * 
  97.      * @param array $params 
  98.      * @since 1.0
  99.      */
  100.     public function doGET($params{
  101.         self::$logger->debug('>>doGET($params=['.var_export($paramstrue).'])');
  102.         
  103.         global $config;
  104.         
  105.         echo AlphaView::displayPageHead($this);
  106.         
  107.         // ensure that a OID is provided
  108.         if (isset($params['oid'])) {
  109.             $BOoid $params['oid'];
  110.         }else{
  111.             throw new IllegalArguementException('Could not load the DEnum object as an oid was not supplied!');
  112.             return;
  113.         }
  114.         
  115.         try {
  116.             $this->BO->load($BOoid);
  117.             
  118.             AlphaDAO::disconnect();
  119.             
  120.             $this->BOName = 'DEnum';
  121.             
  122.             $this->BOView AlphaView::getInstance($this->BO);            
  123.             
  124.             echo AlphaView::renderDeleteForm();            
  125.             
  126.             echo $this->BOView->editView();
  127.         }catch(BONotFoundException $e{
  128.             self::$logger->error('Unable to load the DEnum of id ['.$params['oid'].'], error was ['.$e->getMessage().']');
  129.         }
  130.         
  131.         echo AlphaView::displayPageFoot($this);
  132.         
  133.         self::$logger->debug('<<doGET');        
  134.     }
  135.     
  136.     /**
  137.      * Handle POST requests
  138.      * 
  139.      * @param array $params 
  140.      * @since 1.0
  141.      */
  142.     public function doPOST($params{
  143.         self::$logger->debug('>>doPOST($params=['.var_export($paramstrue).'])');
  144.         
  145.         try {
  146.             // check the hidden security fields before accepting the form POST data
  147.             if(!$this->checkSecurityFields()) {
  148.                 throw new SecurityException('This page cannot accept post data from remote servers!');
  149.                 self::$logger->debug('<<doPOST');
  150.             }
  151.         
  152.             // ensure that a OID is provided
  153.             if (isset($params['oid'])) {
  154.                 $BOoid $params['oid'];
  155.             }else{
  156.                 throw new IllegalArguementException('Could not load the DEnum object as an oid was not supplied!');
  157.             }
  158.             
  159.             if (isset($params['saveBut'])) {
  160.                 try {
  161.                     $this->BO->load($BOoid);
  162.                     // update the object from post data
  163.                     $this->BO->populateFromPost();
  164.                     
  165.                     AlphaDAO::begin();
  166.                     
  167.                     $this->BO->save();
  168.                     
  169.                     // now save the DEnumItems            
  170.                     $tmp new DEnumItem();
  171.                     $denumItems $tmp->loadItems($this->BO->getID());                        
  172.                     
  173.                     foreach ($denumItems as $item{
  174.                         $item->set('value'$params['value_'.$item->getID()]);
  175.                         $item->save();
  176.                     }
  177.                     
  178.                     // handle new DEnumItem if posted
  179.                     if(isset($params['new_value']&& trim($params['new_value']!= ''{
  180.                         $newItem new DEnumItem();
  181.                         $newItem->set('value'$params['new_value']);
  182.                         $newItem->set('DEnumID'$this->BO->getID());
  183.                         $newItem->save();
  184.                     }            
  185.                             
  186.                     AlphaDAO::commit();                    
  187.                     
  188.                     $this->setStatusMessage(AlphaView::displayUpdateMessage(get_class($this->BO).' '.$this->BO->getID().' saved successfully.'));
  189.                     
  190.                     $this->doGET($params);
  191.                 }catch (FailedSaveException $e{
  192.                     self::$logger->error('Unable to save the DEnum of id ['.$params['oid'].'], error was ['.$e->getMessage().']');
  193.                     AlphaDAO::rollback();
  194.                 }
  195.                 
  196.                 AlphaDAO::disconnect();
  197.             }
  198.         }catch(SecurityException $e{
  199.             echo AlphaView::displayErrorMessage($e->getMessage());
  200.             self::$logger->warn($e->getMessage());
  201.         }catch(IllegalArguementException $e{
  202.             echo AlphaView::displayErrorMessage($e->getMessage());
  203.             self::$logger->error($e->getMessage());
  204.         }catch(BONotFoundException $e{
  205.             self::$logger->warn($e->getMessage());
  206.             echo AlphaView::displayErrorMessage('Failed to load the requested item from the database!');
  207.         }
  208.                 
  209.         self::$logger->debug('<<doPOST');
  210.     }
  211.     
  212.     /**
  213.      * Using this callback to blank the new_value field when the page loads, regardless of anything being posted
  214.      * 
  215.      * @return string 
  216.      * @since 1.0
  217.      */
  218.     public function during_displayPageHead_callback({
  219.         $html '';
  220.         $html .= '<script language="javascript">';
  221.         $html .= 'function clearNewField() {';
  222.         $html .= '    document.getElementById("new_value").value = "";';
  223.         $html .= '}';
  224.         $html .= 'addOnloadEvent(clearNewField);';
  225.         $html .= '</script>';
  226.         return $html;
  227.     }
  228. }
  229.  
  230. // now build the new controller if this file is called directly
  231. if ('EditDEnum.php' == basename($_SERVER['PHP_SELF'])) {
  232.     $controller new EditDEnum();
  233.     
  234.     if(!empty($_POST)) {            
  235.         $controller->doPOST($_REQUEST);
  236.     }else{
  237.         $controller->doGET($_GET);
  238.     }
  239. }
  240.  
  241. ?>

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