Overview

Packages

  • alpha::controller
  • alpha::controller::front
  • alpha::exceptions
  • alpha::model
  • alpha::model::types
  • alpha::tasks
  • alpha::tests
  • alpha::util
  • alpha::util::cache
  • alpha::util::codehighlight
  • alpha::util::convertors
  • alpha::util::feeds
  • alpha::util::filters
  • alpha::util::graphs
  • alpha::util::helpers
  • alpha::util::metrics
  • alpha::util::search
  • alpha::view
  • alpha::view::renderers
  • alpha::view::widgets

Classes

  • AlphaController
  • CacheManager
  • Create
  • CreateArticle
  • Detail
  • Edit
  • EditArticle
  • EditDEnum
  • EditTags
  • GenSecureQueryStrings
  • Install
  • ListAll
  • ListBusinessObjects
  • ListDEnums
  • ListSequences
  • Login
  • Logout
  • PreviewArticle
  • Search
  • TagManager
  • ViewArticle
  • ViewArticleFile
  • ViewArticlePDF
  • ViewArticlePrint
  • ViewArticleTitle
  • ViewAttachment
  • ViewExcel
  • ViewFeed
  • ViewImage
  • ViewLog
  • ViewMetrics
  • ViewRecordSelector
  • ViewTestResults

Interfaces

  • AlphaControllerInterface
  • Overview
  • Package
  • Class
  • Tree
  • Deprecated
  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:  *
 13:  * Controller used to list all of the business objects for the system
 14:  *
 15:  * @package alpha::controller
 16:  * @since 1.0
 17:  * @author John Collins <dev@alphaframework.org>
 18:  * @version $Id: ListBusinessObjects.php 1651 2013-02-22 16:50:48Z alphadevx $
 19:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 20:  * @copyright Copyright (c) 2013, 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 ListBusinessObjects extends AlphaController implements AlphaControllerInterface {
 57:     /**
 58:      * Trace logger
 59:      *
 60:      * @var Logger
 61:      * @since 1.0
 62:      */
 63:     private static $logger = null;
 64: 
 65:     /**
 66:      * the constructor
 67:      *
 68:      * @since 1.0
 69:      */
 70:     public function __construct() {
 71:         self::$logger = new Logger('ListBusinessObjects');
 72:         self::$logger->debug('>>__construct()');
 73: 
 74:         global $config;
 75: 
 76:         // ensure that the super class constructor is called, indicating the rights group
 77:         parent::__construct('Admin');
 78: 
 79:         // set up the title and meta details
 80:         $this->setTitle('Listing all business objects in the system');
 81:         $this->setDescription('Page to list all business objects.');
 82:         $this->setKeywords('list,all,business,objects');
 83: 
 84:         self::$logger->debug('<<__construct');
 85:     }
 86: 
 87:     /**
 88:      * Handle GET requests
 89:      *
 90:      * @param array $params
 91:      * @since 1.0
 92:      */
 93:     public function doGET($params) {
 94:         self::$logger->debug('>>doGET($params=['.var_export($params, true).'])');
 95: 
 96:         echo AlphaView::displayPageHead($this);
 97: 
 98:         $this->displayBodyContent();
 99: 
100:         echo AlphaView::displayPageFoot($this);
101: 
102:         self::$logger->debug('<<doGET');
103:     }
104: 
105:     /**
106:      * Handle POST requests
107:      *
108:      * @param array $params
109:      * @since 1.0
110:      */
111:     public function doPOST($params) {
112:         self::$logger->debug('>>doPOST($params=['.var_export($params, true).'])');
113: 
114:         global $config;
115: 
116:         echo AlphaView::displayPageHead($this);
117: 
118:         try {
119:             // check the hidden security fields before accepting the form POST data
120:             if(!$this->checkSecurityFields())
121:                 throw new SecurityException('This page cannot accept post data from remote servers!');
122: 
123:             if(isset($params['createTableBut'])) {
124:                 try {
125:                     $classname = $params['createTableClass'];
126:                     AlphaDAO::loadClassDef($classname);
127: 
128:                     $BO = new $classname();
129:                     $BO->makeTable();
130: 
131:                     self::$logger->action('Created the table for class '.$classname);
132: 
133:                     echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully created.');
134:                 }catch(AlphaException $e) {
135:                     self::$logger->error($e->getMessage());
136:                     echo AlphaView::displayErrorMessage('Error creating the table for the class '.$classname.', check the log!');
137:                 }
138:             }
139: 
140:             if(isset($params['createHistoryTableBut'])) {
141:                 try {
142:                     $classname = $params['createTableClass'];
143:                     AlphaDAO::loadClassDef($classname);
144: 
145:                     $BO = new $classname();
146:                     $BO->makeHistoryTable();
147: 
148:                     self::$logger->action('Created the history table for class '.$classname);
149: 
150:                     echo AlphaView::displayUpdateMessage('The history table for the class '.$classname.' has been successfully created.');
151:                 }catch(AlphaException $e) {
152:                     self::$logger->error($e->getMessage());
153:                     echo AlphaView::displayErrorMessage('Error creating the history table for the class '.$classname.', check the log!');
154:                 }
155:             }
156: 
157:             if(isset($params['recreateTableClass']) && $params['admin_'.$params['recreateTableClass'].'_button_pressed'] == 'recreateTableBut') {
158:                 try {
159:                     $classname = $params['recreateTableClass'];
160:                     AlphaDAO::loadClassDef($classname);
161:                     $BO = new $classname();
162:                     $BO->rebuildTable();
163: 
164:                     self::$logger->action('Recreated the table for class '.$classname);
165: 
166:                     echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully recreated.');
167:                 }catch(AlphaException $e) {
168:                     self::$logger->error($e->getMessage());
169:                     echo AlphaView::displayErrorMessage('Error recreating the table for the class '.$classname.', check the log!');
170:                 }
171:             }
172: 
173:             if(isset($params['updateTableClass']) && $params['admin_'.$params['updateTableClass'].'_button_pressed'] == 'updateTableBut') {
174:                 try {
175:                     $classname = $params['updateTableClass'];
176:                     AlphaDAO::loadClassDef($classname);
177: 
178:                     $BO = new $classname();
179:                     $missingFields = $BO->findMissingFields();
180: 
181:                     $count = count($missingFields);
182: 
183:                     for($i = 0; $i < $count; $i++)
184:                         $BO->addProperty($missingFields[$i]);
185: 
186:                     self::$logger->action('Updated the table for class '.$classname);
187: 
188:                     echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully updated.');
189:                 }catch(AlphaException $e) {
190:                     self::$logger->error($e->getMessage());
191:                     echo AlphaView::displayErrorMessage('Error updating the table for the class '.$classname.', check the log!');
192:                 }
193:             }
194:         }catch(SecurityException $e) {
195:             echo AlphaView::displayErrorMessage($e->getMessage());
196:             self::$logger->warn($e->getMessage());
197:         }
198: 
199:         $this->displayBodyContent();
200: 
201:         echo AlphaView::displayPageFoot($this);
202: 
203:         self::$logger->debug('<<doPOST');
204:     }
205: 
206:     /**
207:      * Private method to display the main body HTML for this page
208:      *
209:      * @since 1.0
210:      */
211:     private function displayBodyContent() {
212: 
213:         $classNames = AlphaDAO::getBOClassNames();
214:         $loadedClasses = array();
215: 
216:         foreach($classNames as $classname) {
217:             AlphaDAO::loadClassDef($classname);
218:             array_push($loadedClasses, $classname);
219:         }
220: 
221:         foreach($loadedClasses as $classname) {
222:             try {
223:                 $BO = new $classname();
224:                 $BO_View = AlphaView::getInstance($BO);
225:                 $BO_View->adminView();
226:             }catch (AlphaException $e) {
227:                 self::$logger->error("[$classname]:".$e->getMessage());
228:                 // its possible that the exception occured due to the table schema being out of date
229:                 if($BO->checkTableExists() && $BO->checkTableNeedsUpdate()) {
230:                     $missingFields = $BO->findMissingFields();
231: 
232:                     $count = count($missingFields);
233: 
234:                     for($i = 0; $i < $count; $i++)
235:                         $BO->addProperty($missingFields[$i]);
236: 
237:                     // now try again...
238:                     $BO = new $classname();
239:                     $BO_View = AlphaView::getInstance($BO);
240:                     $BO_View->adminView();
241:                 }
242:             }catch (Exception $e) {
243:                 self::$logger->error($e->getMessage());
244:                 echo AlphaView::displayErrorMessage('Error accessing the class ['.$classname.'], check the log!');
245:             }
246:         }
247:     }
248: 
249:     /**
250:      * Use this callback to inject in the admin menu template fragment
251:      *
252:      * @since 1.2
253:      */
254:     public function after_displayPageHead_callback() {
255:         $menu = AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
256: 
257:         return $menu;
258:     }
259: }
260: 
261: // now build the new controller
262: if(basename($_SERVER['PHP_SELF']) == 'ListBusinessObjects.php') {
263:     $controller = new ListBusinessObjects();
264: 
265:     if(!empty($_POST)) {
266:         $controller->doPOST($_REQUEST);
267:     }else{
268:         $controller->doGET($_GET);
269:     }
270: }
271: 
272: ?>
Alpha Framework 1.2.4 API Documentation API documentation generated by ApiGen 2.8.0