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

Source for file ViewRecordSelector.php

Documentation is available at ViewRecordSelector.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/util/Logger.inc';
  11. require_once $config->get('sysRoot').'alpha/view/widgets/RecordSelector.inc';
  12. require_once $config->get('sysRoot').'alpha/controller/AlphaControllerInterface.inc';
  13.  
  14. /**
  15.  *
  16.  * Controller for viewing a RecordSelector widget.
  17.  * 
  18.  * @package alpha::controller
  19.  * @since 1.0
  20.  * @author John Collins <dev@alphaframework.org>
  21.  * @version $Id: ViewRecordSelector.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.     /**
  60.      * Trace logger
  61.      * 
  62.      * @var Logger 
  63.      * @since 1.0
  64.      */
  65.     private static $logger null;
  66.     
  67.     /**
  68.      * Constructor
  69.      * 
  70.      * @since 1.0
  71.      */
  72.     public function __construct({
  73.         self::$logger new Logger('ViewRecordSelector');
  74.         self::$logger->debug('>>__construct()');
  75.         
  76.         // ensure that the super class constructor is called, indicating the rights group
  77.         parent::__construct('Public');
  78.         
  79.         self::$logger->debug('<<__construct');
  80.     }
  81.     
  82.     /**
  83.      * Handles get requests
  84.      *
  85.      * @param array $params 
  86.      * @since 1.0
  87.      * @throws ResourceNotFoundException
  88.      */
  89.     public function doGet($params{
  90.         self::$logger->debug('>>doGet(params=['.var_export($paramstrue).'])');
  91.         
  92.         $relationObject new Relation();
  93.         
  94.         try {
  95.             $relationType $params['relationType'];
  96.             $value $params['value'];
  97.         }catch (Exception $e{
  98.             self::$logger->error('Required param missing for ViewRecordSelector controller['.$e->getMessage().']');
  99.             throw new ResourceNotFoundException('File not found');
  100.         }
  101.     
  102.         if($_GET['relationType'== 'MANY-TO-MANY'{
  103.             try {
  104.                 $relatedClassLeft $params['relatedClassLeft'];                
  105.                 $relatedClassLeftDisplayField $params['relatedClassLeftDisplayField'];
  106.                 $relatedClassRight $params['relatedClassRight'];
  107.                 $relatedClassRightDisplayField $params['relatedClassRightDisplayField'];                
  108.                 $field $params['field'];
  109.                 $accessingClassName $params['accessingClassName'];
  110.                 $lookupOIDs $params['lookupOIDs'];
  111.             }catch (Exception $e{
  112.                 self::$logger->error('Required param missing for ViewRecordSelector controller['.$e->getMessage().']');
  113.                 throw new ResourceNotFoundException('File not found');
  114.             }
  115.             
  116.             $relationObject->setRelatedClass($relatedClassLeft'left');
  117.             $relationObject->setRelatedClassDisplayField($relatedClassLeftDisplayField'left');
  118.             $relationObject->setRelatedClass($relatedClassRight'right');
  119.             $relationObject->setRelatedClassDisplayField($relatedClassRightDisplayField'right');
  120.             $relationObject->setRelationType($relationType);
  121.             $relationObject->setValue($value);
  122.             
  123.             $recSelector new RecordSelector($relationObject''$field$accessingClassName);
  124.             echo $recSelector->renderSelector(explode(','$lookupOIDs));
  125.         }else{
  126.             try {
  127.                 $relatedClass $params['relatedClass'];                
  128.                 $relatedClassField $params['relatedClassField'];
  129.                 $relatedClassDisplayField $params['relatedClassDisplayField'];
  130.             }catch (Exception $e{
  131.                 self::$logger->error('Required param missing for ViewRecordSelector controller['.$e->getMessage().']');
  132.                 throw new ResourceNotFoundException('File not found');
  133.             }
  134.             
  135.             $relationObject->setRelatedClass($relatedClass);
  136.             $relationObject->setRelatedClassField($relatedClassField);
  137.             $relationObject->setRelatedClassDisplayField($relatedClassDisplayField);
  138.             $relationObject->setRelationType($relationType);
  139.             $relationObject->setValue($value);
  140.             
  141.             $recSelector new RecordSelector($relationObject);
  142.             echo $recSelector->renderSelector();
  143.         }
  144.         
  145.         self::$logger->debug('<<__doGet');
  146.     }
  147.     
  148.     /**
  149.      * Handle POST requests
  150.      * 
  151.      * @param array $params 
  152.      * @since 1.0
  153.      */
  154.     public function doPOST($params{
  155.         self::$logger->debug('>>doPOST($params=['.var_export($paramstrue).'])');        
  156.         
  157.         self::$logger->debug('<<doPOST');
  158.     }
  159.     
  160. }
  161.  
  162. // now build the new controller if this file is called directly
  163. if ('ViewRecordSelector.php' == basename($_SERVER['PHP_SELF'])) {
  164.     $controller new ViewRecordSelector();
  165.     
  166.     if(!empty($_POST)) {            
  167.         $controller->doPOST($_POST);
  168.     }else{
  169.         $controller->doGET($_GET);
  170.     }
  171. }
  172.  
  173. ?>

Documentation generated on Thu, 17 Mar 2011 16:45:12 +0000 by phpDocumentor 1.4.3