      1: <?php
      2:
      3: // include the config file
      4: if(!isset($config)) {
      5:     require_once '../util/AlphaConfig.inc';
      6:     $config = AlphaConfig::getInstance();
      7:
      8:     require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
      9: }
     10:
     11: /**
     12:  * Controller for viewing a RecordSelector widget.
     13:  *
     14:  * @package alpha::controller
     15:  * @since 1.0
     16:  * @author John Collins <dev@alphaframework.org>
     17:  * @version $Id: ViewRecordSelector.php 1654 2013-03-08 17:13:14Z alphadevx $
     18:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
     19:  * @copyright Copyright (c) 2013, John Collins (founder of Alpha Framework).
     20:  * All rights reserved.
     21:  *
     22:  * <pre>
     23:  * Redistribution and use in source and binary forms, with or
     24:  * without modification, are permitted provided that the
     25:  * following conditions are met:
     26:  *
     27:  * * Redistributions of source code must retain the above
     28:  *   copyright notice, this list of conditions and the
     29:  *   following disclaimer.
     30:  * * Redistributions in binary form must reproduce the above
     31:  *   copyright notice, this list of conditions and the
     32:  *   following disclaimer in the documentation and/or other
     33:  *   materials provided with the distribution.
     34:  * * Neither the name of the Alpha Framework nor the names
     35:  *   of its contributors may be used to endorse or promote
     36:  *   products derived from this software without specific
     37:  *   prior written permission.
     38:  *
     39:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
     40:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
     41:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     42:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     43:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     44:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     45:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     46:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     47:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     48:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     49:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     50:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     51:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     52:  * </pre>
     53:  *
     54:  */
     55: class ViewRecordSelector extends AlphaController implements AlphaControllerInterface {
     56:     /**
     57:      * Trace logger
     58:      *
     59:      * @var Logger
     60:      * @since 1.0
     61:      */
     62:     private static $logger = null;
     63:
     64:     /**
     65:      * Constructor
     66:      *
     67:      * @since 1.0
     68:      */
     69:     public function __construct() {
     70:         self::$logger = new Logger('ViewRecordSelector');
     71:         self::$logger->debug('>>__construct()');
     72:
     73:         // ensure that the super class constructor is called, indicating the rights group
     74:         parent::__construct('Public');
     75:
     76:         self::$logger->debug('<<__construct');
     77:     }
     78:
     79:     /**
     80:      * Handles get requests
     81:      *
     82:      * @param array $params
     83:      * @since 1.0
     84:      * @throws ResourceNotFoundException
     85:      */
     86:     public function doGet($params) {
     87:         self::$logger->debug('>>doGet(params=['.var_export($params, true).'])');
     88:
     89:         $relationObject = new Relation();
     90:
     91:         try {
     92:             $relationType = $params['relationType'];
     93:             $value = $params['value'];
     94:         }catch (Exception $e) {
     95:             self::$logger->error('Required param missing for ViewRecordSelector controller['.$e->getMessage().']');
     96:             throw new ResourceNotFoundException('File not found');
     97:         }
     98:
     99:         if($_GET['relationType'] == 'MANY-TO-MANY') {
    100:             try {
    101:                 $relatedClassLeft = $params['relatedClassLeft'];
    102:                 $relatedClassLeftDisplayField = $params['relatedClassLeftDisplayField'];
    103:                 $relatedClassRight = $params['relatedClassRight'];
    104:                 $relatedClassRightDisplayField = $params['relatedClassRightDisplayField'];
    105:                 $field = $params['field'];
    106:                 $accessingClassName = $params['accessingClassName'];
    107:                 $lookupOIDs = $params['lookupOIDs'];
    108:             }catch (Exception $e) {
    109:                 self::$logger->error('Required param missing for ViewRecordSelector controller['.$e->getMessage().']');
    110:                 throw new ResourceNotFoundException('File not found');
    111:             }
    112:
    113:             $relationObject->setRelatedClass($relatedClassLeft, 'left');
    114:             $relationObject->setRelatedClassDisplayField($relatedClassLeftDisplayField, 'left');
    115:             $relationObject->setRelatedClass($relatedClassRight, 'right');
    116:             $relationObject->setRelatedClassDisplayField($relatedClassRightDisplayField, 'right');
    117:             $relationObject->setRelationType($relationType);
    118:             $relationObject->setValue($value);
    119:
    120:             $recSelector = new RecordSelector($relationObject, '', $field, $accessingClassName);
    121:             echo $recSelector->renderSelector(explode(',', $lookupOIDs));
    122:         }else{
    123:             try {
    124:                 $relatedClass = $params['relatedClass'];
    125:                 $relatedClassField = $params['relatedClassField'];
    126:                 $relatedClassDisplayField = $params['relatedClassDisplayField'];
    127:             }catch (Exception $e) {
    128:                 self::$logger->error('Required param missing for ViewRecordSelector controller['.$e->getMessage().']');
    129:                 throw new ResourceNotFoundException('File not found');
    130:             }
    131:
    132:             $relationObject->setRelatedClass($relatedClass);
    133:             $relationObject->setRelatedClassField($relatedClassField);
    134:             $relationObject->setRelatedClassDisplayField($relatedClassDisplayField);
    135:             $relationObject->setRelationType($relationType);
    136:             $relationObject->setValue($value);
    137:
    138:             $recSelector = new RecordSelector($relationObject);
    139:             echo $recSelector->renderSelector();
    140:         }
    141:
    142:         self::$logger->debug('<<__doGet');
    143:     }
    144:
    145:     /**
    146:      * Handle POST requests
    147:      *
    148:      * @param array $params
    149:      * @since 1.0
    150:      */
    151:     public function doPOST($params) {
    152:         self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
    153:
    154:         self::$logger->debug('<<doPOST');
    155:     }
    156: }
    157:
    158: // now build the new controller if this file is called directly
    159: if ('ViewRecordSelector.php' == basename($_SERVER['PHP_SELF'])) {
    160:     $controller = new ViewRecordSelector();
    161:
    162:     if(!empty($_POST)) {
    163:         $controller->doPOST($_POST);
    164:     }else{
    165:         $controller->doGET($_GET);
    166:     }
    167: }
    168:
    169: ?>