Overview

Namespaces

  • Alpha
    • Controller
      • Front
    • Exception
    • Model
      • Type
    • Task
    • Util
      • Backup
      • Cache
      • Code
        • Highlight
        • Metric
      • Config
      • Convertor
      • Email
      • Extension
      • Feed
      • File
      • Graph
      • Helper
      • Http
        • Filter
        • Session
      • Image
      • Logging
      • Search
      • Security
    • View
      • Renderer
        • Html
        • Json
      • Widget

Classes

  • ActiveRecordController
  • ArticleController
  • AttachmentController
  • CacheController
  • Controller
  • DEnumController
  • ExcelController
  • FeedController
  • GenSecureQueryStringController
  • ImageController
  • IndexController
  • InstallController
  • ListActiveRecordsController
  • LogController
  • LoginController
  • LogoutController
  • MetricController
  • PhpinfoController
  • RecordSelectorController
  • SearchController
  • SequenceController
  • TagController

Interfaces

  • ControllerInterface
  • Overview
  • Namespace
  • Class
  • Tree
  1: <?php
  2: 
  3: namespace Alpha\Controller;
  4: 
  5: use Alpha\Util\Logging\Logger;
  6: use Alpha\Util\Config\ConfigProvider;
  7: use Alpha\Util\Http\Request;
  8: use Alpha\Util\Http\Response;
  9: use Alpha\View\View;
 10: use Alpha\View\ViewState;
 11: use Alpha\Exception\SecurityException;
 12: use Alpha\Exception\AlphaException;
 13: use Alpha\Model\ActiveRecord;
 14: 
 15: /**
 16:  * Controller used to list all of the active record types in the system.
 17:  *
 18:  * @since 1.0
 19:  *
 20:  * @author John Collins <dev@alphaframework.org>
 21:  * @license http://www.opensource.org/licenses/bsd-license.php The BSD License
 22:  * @copyright Copyright (c) 2015, John Collins (founder of Alpha Framework).
 23:  * All rights reserved.
 24:  *
 25:  * <pre>
 26:  * Redistribution and use in source and binary forms, with or
 27:  * without modification, are permitted provided that the
 28:  * following conditions are met:
 29:  *
 30:  * * Redistributions of source code must retain the above
 31:  *   copyright notice, this list of conditions and the
 32:  *   following disclaimer.
 33:  * * Redistributions in binary form must reproduce the above
 34:  *   copyright notice, this list of conditions and the
 35:  *   following disclaimer in the documentation and/or other
 36:  *   materials provided with the distribution.
 37:  * * Neither the name of the Alpha Framework nor the names
 38:  *   of its contributors may be used to endorse or promote
 39:  *   products derived from this software without specific
 40:  *   prior written permission.
 41:  *
 42:  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 43:  * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
 44:  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 45:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 46:  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
 47:  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 48:  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 49:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 50:  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 51:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 52:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
 53:  * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 54:  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 55:  * </pre>
 56:  */
 57: class ListActiveRecordsController extends Controller implements ControllerInterface
 58: {
 59:     /**
 60:      * Trace logger.
 61:      *
 62:      * @var Alpha\Util\Logging\Logger
 63:      *
 64:      * @since 1.0
 65:      */
 66:     private static $logger = null;
 67: 
 68:     /**
 69:      * the constructor.
 70:      *
 71:      * @since 1.0
 72:      */
 73:     public function __construct()
 74:     {
 75:         self::$logger = new Logger('ListActiveRecordsController');
 76:         self::$logger->debug('>>__construct()');
 77: 
 78:         $config = ConfigProvider::getInstance();
 79: 
 80:         // ensure that the super class constructor is called, indicating the rights group
 81:         parent::__construct('Admin');
 82: 
 83:         // set up the title and meta details
 84:         $this->setTitle('Listing all active records in the system');
 85:         $this->setDescription('Page to list all active records.');
 86:         $this->setKeywords('list,all,active,records');
 87: 
 88:         $viewState = ViewState::getInstance();
 89:         $viewState->set('renderAdminMenu', true);
 90: 
 91:         self::$logger->debug('<<__construct');
 92:     }
 93: 
 94:     /**
 95:      * Handle GET requests.
 96:      *
 97:      * @param alpha\Util\Http\Request $request
 98:      *
 99:      * @return alpha\Util\Http\Response
100:      *
101:      * @since 1.0
102:      */
103:     public function doGET($request)
104:     {
105:         self::$logger->debug('>>doGET($request=['.var_export($request, true).'])');
106: 
107:         $body = View::displayPageHead($this);
108: 
109:         $body .= $this->displayBodyContent();
110: 
111:         $body .= View::displayPageFoot($this);
112: 
113:         self::$logger->debug('<<doGET');
114: 
115:         return new Response(200, $body, array('Content-Type' => 'text/html'));
116:     }
117: 
118:     /**
119:      * Handle POST requests.
120:      *
121:      * @param alpha\Util\Http\Request $request
122:      *
123:      * @return alpha\Util\Http\Response
124:      *
125:      * @since 1.0
126:      */
127:     public function doPOST($request)
128:     {
129:         self::$logger->debug('>>doPOST($request=['.var_export($request, true).'])');
130: 
131:         $params = $request->getParams();
132: 
133:         $config = ConfigProvider::getInstance();
134: 
135:         $body = View::displayPageHead($this);
136: 
137:         try {
138:             // check the hidden security fields before accepting the form POST data
139:             if (!$this->checkSecurityFields()) {
140:                 throw new SecurityException('This page cannot accept post data from remote servers!');
141:             }
142: 
143:             if (isset($params['createTableBut'])) {
144:                 try {
145:                     $classname = $params['createTableClass'];
146: 
147:                     $BO = new $classname();
148:                     $BO->makeTable();
149: 
150:                     self::$logger->action('Created the table for class '.$classname);
151: 
152:                     $body .= View::displayUpdateMessage('The table for the class '.$classname.' has been successfully created.');
153:                 } catch (AlphaException $e) {
154:                     self::$logger->error($e->getMessage());
155:                     $body .= View::displayErrorMessage('Error creating the table for the class '.$classname.', check the log!');
156:                 }
157:             }
158: 
159:             if (isset($params['createHistoryTableBut'])) {
160:                 try {
161:                     $classname = $params['createTableClass'];
162: 
163:                     $BO = new $classname();
164:                     $BO->makeHistoryTable();
165: 
166:                     self::$logger->action('Created the history table for class '.$classname);
167: 
168:                     $body .= View::displayUpdateMessage('The history table for the class '.$classname.' has been successfully created.');
169:                 } catch (AlphaException $e) {
170:                     self::$logger->error($e->getMessage());
171:                     $body .= View::displayErrorMessage('Error creating the history table for the class '.$classname.', check the log!');
172:                 }
173:             }
174: 
175:             if (isset($params['recreateTableClass']) && $params['admin_'.stripslashes($params['recreateTableClass']).'_button_pressed'] == 'recreateTableBut') {
176:                 try {
177:                     $classname = $params['recreateTableClass'];
178:                     $BO = new $classname();
179:                     $BO->rebuildTable();
180: 
181:                     self::$logger->action('Recreated the table for class '.$classname);
182: 
183:                     $body .= View::displayUpdateMessage('The table for the class '.$classname.' has been successfully recreated.');
184:                 } catch (AlphaException $e) {
185:                     self::$logger->error($e->getMessage());
186:                     $body .= View::displayErrorMessage('Error recreating the table for the class '.$classname.', check the log!');
187:                 }
188:             }
189: 
190:             if (isset($params['updateTableClass']) && $params['admin_'.stripslashes($params['updateTableClass']).'_button_pressed'] == 'updateTableBut') {
191:                 try {
192:                     $classname = $params['updateTableClass'];
193: 
194:                     $BO = new $classname();
195:                     $missingFields = $BO->findMissingFields();
196: 
197:                     $count = count($missingFields);
198: 
199:                     for ($i = 0; $i < $count; ++$i) {
200:                         $BO->addProperty($missingFields[$i]);
201:                     }
202: 
203:                     self::$logger->action('Updated the table for class '.$classname);
204: 
205:                     $body .= View::displayUpdateMessage('The table for the class '.$classname.' has been successfully updated.');
206:                 } catch (AlphaException $e) {
207:                     self::$logger->error($e->getMessage());
208:                     $body .= View::displayErrorMessage('Error updating the table for the class '.$classname.', check the log!');
209:                 }
210:             }
211:         } catch (SecurityException $e) {
212:             $body .= View::displayErrorMessage($e->getMessage());
213:             self::$logger->warn($e->getMessage());
214:         }
215: 
216:         $body .= $this->displayBodyContent();
217: 
218:         $body .= View::displayPageFoot($this);
219: 
220:         self::$logger->debug('<<doPOST');
221: 
222:         return new Response(200, $body, array('Content-Type' => 'text/html'));
223:     }
224: 
225:     /**
226:      * Private method to generate the main body HTML for this page.
227:      *
228:      * @since 1.0
229:      *
230:      * @return string
231:      */
232:     private function displayBodyContent()
233:     {
234:         $classNames = ActiveRecord::getBOClassNames();
235: 
236:         $body = '';
237: 
238:         $fields = array('formAction' => $this->request->getURI());
239: 
240:         foreach ($classNames as $className) {
241:             try {
242:                 $activeRecord = new $className();
243:                 $view = View::getInstance($activeRecord);
244:                 $body .= $view->adminView($fields);
245:             } catch (AlphaException $e) {
246:                 self::$logger->error("[$classname]:".$e->getMessage());
247:                 // its possible that the exception occured due to the table schema being out of date
248:                 if ($activeRecord->checkTableExists() && $activeRecord->checkTableNeedsUpdate()) {
249:                     $missingFields = $activeRecord->findMissingFields();
250: 
251:                     $count = count($missingFields);
252: 
253:                     for ($i = 0; $i < $count; ++$i) {
254:                         $activeRecord->addProperty($missingFields[$i]);
255:                     }
256: 
257:                     // now try again...
258:                     $activeRecord = new $className();
259:                     $view = View::getInstance($activeRecord);
260:                     $body .= $view->adminView($fields);
261:                 }
262:             } catch (\Exception $e) {
263:                 self::$logger->error($e->getMessage());
264:                 $body .= View::displayErrorMessage('Error accessing the class ['.$classname.'], check the log!');
265:             }
266:         }
267: 
268:         return $body;
269:     }
270: }
271: 
Alpha Framework 2.0.4 API Documentation API documentation generated by ApiGen 2.8.0