      1: <?php
      2:
      3: // include the config file
      4: if(!isset($config)) {
      5:     require_once '../util/configLoader.inc';
      6:     $config = configLoader::getInstance();
      7:
      8:     require_once $config->get('app.root').'alpha/util/AlphaAutoLoader.inc';
      9: }
     10:
     11: /**
     12:  *
     13:  * Controller used to list all DEnums
     14:  *
     15:  * @package alpha::controller
     16:  * @since 1.0
     17:  * @author John Collins <dev@alphaframework.org>
     18:  * @version $Id: ListDEnums.php 1757 2014-04-09 22:18:37Z alphadevx $
     19:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
     20:  * @copyright Copyright (c) 2014, John Collins (founder of Alpha Framework).
     21:  * All rights reserved.
     22:  *
     23:  * <pre>
     24:  * Redistribution and use in source and binary forms, with or
     25:  * without modification, are permitted provided that the
     26:  * following conditions are met:
     27:  *
     28:  * * Redistributions of source code must retain the above
     29:  *   copyright notice, this list of conditions and the
     30:  *   following disclaimer.
     31:  * * Redistributions in binary form must reproduce the above
     32:  *   copyright notice, this list of conditions and the
     33:  *   following disclaimer in the documentation and/or other
     34:  *   materials provided with the distribution.
     35:  * * Neither the name of the Alpha Framework nor the names
     36:  *   of its contributors may be used to endorse or promote
     37:  *   products derived from this software without specific
     38:  *   prior written permission.
     39:  *
     40:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
     41:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
     42:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     43:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     44:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     45:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     46:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     47:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     48:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     49:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     50:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
     51:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
     52:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     53:  * </pre>
     54:  *
     55:  */
     56: class ListDEnums extends ListAll implements AlphaControllerInterface {
     57:     /**
     58:      * Trace logger
     59:      *
     60:      * @var Logger
     61:      * @since 1.0
     62:      */
     63:     private static $logger = null;
     64:
     65:     /**
     66:      * constructor to set up the object
     67:      *
     68:      * @since 1.0
     69:      */
     70:     public function __construct() {
     71:         self::$logger = new Logger('ListDEnums');
     72:         self::$logger->debug('>>__construct()');
     73:
     74:         // ensure that the super class constructor is called, indicating the rights group
     75:         parent::__construct('Admin');
     76:
     77:         $this->BO = new DEnum();
     78:
     79:         // make sure that the DEnum tables exist
     80:         if(!$this->BO->checkTableExists()) {
     81:             echo AlphaView::displayErrorMessage('Warning! The DEnum tables do not exist, attempting to create them now...');
     82:             $this->createDEnumTables();
     83:         }
     84:
     85:         $this->BOname = 'DEnum';
     86:
     87:         $this->BOView = AlphaView::getInstance($this->BO);
     88:
     89:         // set up the title and meta details
     90:         $this->setTitle('Listing all DEnums');
     91:         $this->setDescription('Page to list all DEnums.');
     92:         $this->setKeywords('list,all,DEnums');
     93:
     94:         self::$logger->debug('<<__construct');
     95:     }
     96:
     97:     /**
     98:      * Handle GET requests
     99:      *
    100:      * @param array $params
    101:      * @since 1.0
    102:      */
    103:     public function doGET($params) {
    104:         self::$logger->debug('>>doGET($params=['.var_export($params, true).'])');
    105:
    106:         echo AlphaView::displayPageHead($this);
    107:
    108:         // get all of the BOs and invoke the list_view on each one
    109:         $temp = new DEnum();
    110:         // set the start point for the list pagination
    111:         if (isset($params['start']) ? $this->startPoint = $params['start']: $this->startPoint = 1);
    112:
    113:         $objects = $temp->loadAll($this->startPoint);
    114:
    115:         AlphaDAO::disconnect();
    116:
    117:         $this->BOCount = $this->BO->getCount();
    118:
    119:         echo AlphaView::renderDeleteForm();
    120:
    121:         foreach($objects as $object) {
    122:             $temp = AlphaView::getInstance($object);
    123:             echo $temp->listView();
    124:         }
    125:
    126:         echo AlphaView::displayPageFoot($this);
    127:
    128:         self::$logger->debug('<<doGET');
    129:     }
    130:
    131:     /**
    132:      * Handle POST requests
    133:      *
    134:      * @param array $params
    135:      * @since 1.0
    136:      */
    137:     public function doPOST($params) {
    138:         self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
    139:
    140:         self::$logger->debug('<<doPOST');
    141:     }
    142:
    143:     /**
    144:      * Method to create the DEnum tables if they don't exist
    145:      *
    146:      * @since 1.0
    147:      */
    148:     private function createDEnumTables() {
    149:         $tmpDEnum = new DEnum();
    150:
    151:         echo '<p>Attempting to build table '.DEnum::TABLE_NAME.' for class DEnum : </p>';
    152:
    153:         try {
    154:             $tmpDEnum->makeTable();
    155:             echo AlphaView::displayUpdateMessage('Successfully re-created the database table '.DEnum::TABLE_NAME);
    156:             self::$logger->action('Re-created the table '.DEnum::TABLE_NAME);
    157:         }catch(AlphaException $e) {
    158:             echo AlphaView::displayErrorMessage('Failed re-created the database table '.DEnum::TABLE_NAME.', check the log');
    159:             self::$logger->error($e->getMessage());
    160:         }
    161:
    162:         $tmpDEnumItem = new DEnumItem();
    163:
    164:         echo '<p>Attempting to build table '.DEnumItem::TABLE_NAME.' for class DEnumItem : </p>';
    165:
    166:         try {
    167:             $tmpDEnumItem->makeTable();
    168:             echo AlphaView::displayUpdateMessage('Successfully re-created the database table '.DEnumItem::TABLE_NAME);
    169:             self::$logger->action('Re-created the table '.DEnumItem::TABLE_NAME);
    170:         }catch(AlphaException $e) {
    171:             echo AlphaView::displayErrorMessage('Failed re-created the database table '.DEnumItem::TABLE_NAME.', check the log');
    172:             self::$logger->error($e->getMessage());
    173:         }
    174:     }
    175:
    176:     /**
    177:      * Use this callback to inject in the admin menu template fragment
    178:      *
    179:      * @since 1.2
    180:      */
    181:     public function after_displayPageHead_callback() {
    182:         $menu = AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
    183:
    184:         return $menu;
    185:     }
    186: }
    187:
    188: // now build the new controller if this file is called directly
    189: if ('ListDEnums.php' == basename($_SERVER['PHP_SELF'])) {
    190:     $controller = new ListDEnums();
    191:
    192:     if(!empty($_POST)) {
    193:         $controller->doPOST($_POST);
    194:     }else{
    195:         $controller->doGET($_GET);
    196:     }
    197: }
    198:
    199: ?>