1: <?php
2:
3:
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: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55:
56: class ListBusinessObjects extends AlphaController implements AlphaControllerInterface {
57: 58: 59: 60: 61: 62:
63: private static $logger = null;
64:
65: 66: 67: 68: 69:
70: public function __construct() {
71: self::$logger = new Logger('ListBusinessObjects');
72: self::$logger->debug('>>__construct()');
73:
74: global $config;
75:
76:
77: parent::__construct('Admin');
78:
79:
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: 89: 90: 91: 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: 107: 108: 109: 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:
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: echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully created.');
132: }catch(AlphaException $e) {
133: self::$logger->error($e->getMessage());
134: echo AlphaView::displayErrorMessage('Error creating the table for the class '.$classname.', check the log!');
135: }
136: }
137:
138: if(isset($params['createHistoryTableBut'])) {
139: try {
140: $classname = $params['createTableClass'];
141: AlphaDAO::loadClassDef($classname);
142:
143: $BO = new $classname();
144: $BO->makeHistoryTable();
145:
146: echo AlphaView::displayUpdateMessage('The history table for the class '.$classname.' has been successfully created.');
147: }catch(AlphaException $e) {
148: self::$logger->error($e->getMessage());
149: echo AlphaView::displayErrorMessage('Error creating the history table for the class '.$classname.', check the log!');
150: }
151: }
152:
153: if(isset($params['recreateTableClass']) && $params['admin_'.$params['recreateTableClass'].'_button_pressed'] == 'recreateTableBut') {
154: try {
155: $classname = $params['recreateTableClass'];
156: AlphaDAO::loadClassDef($classname);
157: $BO = new $classname();
158: $BO->rebuildTable();
159:
160: echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully recreated.');
161: }catch(AlphaException $e) {
162: self::$logger->error($e->getMessage());
163: echo AlphaView::displayErrorMessage('Error recreating the table for the class '.$classname.', check the log!');
164: }
165: }
166:
167: if(isset($params['updateTableClass']) && $params['admin_'.$params['updateTableClass'].'_button_pressed'] == 'updateTableBut') {
168: try {
169: $classname = $params['updateTableClass'];
170: AlphaDAO::loadClassDef($classname);
171:
172: $BO = new $classname();
173: $missingFields = $BO->findMissingFields();
174:
175: $count = count($missingFields);
176:
177: for($i = 0; $i < $count; $i++)
178: $BO->addProperty($missingFields[$i]);
179:
180: echo AlphaView::displayUpdateMessage('The table for the class '.$classname.' has been successfully updated.');
181: }catch(AlphaException $e) {
182: self::$logger->error($e->getMessage());
183: echo AlphaView::displayErrorMessage('Error updating the table for the class '.$classname.', check the log!');
184: }
185: }
186: }catch(SecurityException $e) {
187: echo AlphaView::displayErrorMessage($e->getMessage());
188: self::$logger->warn($e->getMessage());
189: }
190:
191: $this->displayBodyContent();
192:
193: echo AlphaView::displayPageFoot($this);
194:
195: self::$logger->debug('<<doPOST');
196: }
197:
198: 199: 200: 201: 202:
203: private function displayBodyContent() {
204:
205: $classNames = AlphaDAO::getBOClassNames();
206: $loadedClasses = array();
207:
208: foreach($classNames as $classname) {
209: AlphaDAO::loadClassDef($classname);
210: array_push($loadedClasses, $classname);
211: }
212:
213: foreach($loadedClasses as $classname) {
214: try {
215: $BO = new $classname();
216: $BO_View = AlphaView::getInstance($BO);
217: $BO_View->adminView();
218: }catch (AlphaException $e) {
219: self::$logger->error("[$classname]:".$e->getMessage());
220:
221: if($BO->checkTableExists() && $BO->checkTableNeedsUpdate()) {
222: $missingFields = $BO->findMissingFields();
223:
224: $count = count($missingFields);
225:
226: for($i = 0; $i < $count; $i++)
227: $BO->addProperty($missingFields[$i]);
228:
229:
230: $BO = new $classname();
231: $BO_View = AlphaView::getInstance($BO);
232: $BO_View->adminView();
233: }
234: }catch (Exception $e) {
235: self::$logger->error($e->getMessage());
236: echo AlphaView::displayErrorMessage('Error accessing the class ['.$classname.'], check the log!');
237: }
238: }
239: }
240:
241: 242: 243: 244: 245:
246: public function after_displayPageHead_callback() {
247: $menu = AlphaView::loadTemplateFragment('html', 'adminmenu.phtml', array());
248:
249: return $menu;
250: }
251: }
252:
253:
254: if(basename($_SERVER['PHP_SELF']) == 'ListBusinessObjects.php') {
255: $controller = new ListBusinessObjects();
256:
257: if(!empty($_POST)) {
258: $controller->doPOST($_REQUEST);
259: }else{
260: $controller->doGET($_GET);
261: }
262: }
263:
264: ?>
265: