Source for file RSDEngineDB.php

Documentation is available at RSDEngineDB.php


1 <?php
2 // RSDEngine: The Rapid and Secure Development Engine
3 // Copyright (C) 2003 Lukas Feiler
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 /**This file is part of the RSDEngine.
20 *
21 * @author Lukas Feiler <lukas.feiler@chello.at>
22 * @version 0.1.9
23 * @copyright Lukas Feiler 2003
24 * @package RSDEngine
25 * @filesource
26 */
27
28 /**RSDEngineDB extends PEAR.
29 */
30 require_once('PEAR.php');
31
32 /**The class capable of handling tables defined in $this->config['sql'].
33 */
34 require_once('RSDEngineDBTable.php');
35
36 /**Base class for all File-Classes
37 */
38 require_once('RSDEngineFile.php');
39
40 /**Base class for all Class-Classes
41 */
42 require_once('RSDEngineClass.php');
43
44 /**Base class for all Function-Classes
45 */
46 require_once('RSDEngineFunction.php');
47
48 /**This class provides the power of creating classes that simplify the acccess of database tables.
49 *
50 * @author Lukas Feiler <lukas.feiler@chello.at>
51 * @version 0.1.9
52 * @copyright Lukas Feiler 2003
53 * @package RSDEngine
54 */
55 class RSDEngineDB extends PEAR{
56
57 /**An array containing instances of RSDEngineDBTable.
58 * @var Array
59 * @see RSDEngineDBTable
60 */
61 var $tables = array();
62
63 /**An array containing instances of RSDEngineRelation.
64 * @var Array
65 * @see RSDEngineRelation
66 */
67 var $relations = array();
68
69 /**The Database schema in SQL DDL. Gets set inside the constructor method.
70 * @var String
71 */
72 var $sql = "";
73
74 /**The project name. Gets set inside the constructor method.
75 * @var String
76 */
77 var $projectName = "";
78
79 /**The authors, each stored as one array element. Gets set inside the constructor method.
80 * @var Array
81 */
82 var $authors = "";
83
84 /**The copyright information. This string must not contain newlines. Gets set inside the constructor method.
85 * @var String
86 */
87 var $copyright = "";
88
89 /**The table prefix used for all tables in $this->sql. Often t_ or an shorthand for the project name of the form prj_. Providing a table prefix makes the generated code more readable because the prefix can be remove where appropriate. Set in the construtor method.
90 * @var String
91 */
92 var $tablePrefix = "";
93
94 /**The column prefix used for all columns in $this->sql. Often f_. Providing a column prefix makes the generated code more readable because the prefix can be remove where appropriate. Set in the construtor method.
95 * @var String
96 */
97 var $columnPrefix = "";
98
99 /**An associative array containing all configuration options. Gets set inside the constructor method.
100 * @var Array
101 */
102 var $config = array();
103
104
105 /**Initializes this instance.
106 *
107 * @see projectName
108 * @see authors
109 * @see copyright
110 * @see sql
111 * @see tablePrefix
112 * @see columnPrefix
113 * @param Array $config An associativ array containing the elements 'projectName', 'authors', 'copyright', 'sql', 'tablePrefix', 'columnPrefix'.
114 */
115 function RSDEngineDB($config)
116 {
117 $this->config = $config;
118 $this->projectName = $config['projectName'];
119 if (is_array($config['authors'])) {
120 $this->authors = $config['authors'];
121 } else {
122 $this->authors = split("\n",$config['authors']);
123 }
124 $this->copyright = $config['copyright'];
125 $this->sql = $config['sql'];
126 $this->tablePrefix = $config['tablePrefix'];
127 $this->columnPrefix = $config['columnPrefix'];
128
129 $this->_parse();
130 }
131
132 /**Parses the provided SQL DDL stored in the property $this->sql and generates a RSDEngineDBTable
133 * object for each table, stores it in $this->tables.
134 * @see sql
135 * @see tables
136 *
137 * @access private
138 */
139 function _parse()
140 {
141 //remove C-like comments (starting with /* and ending with */
142 $sql = preg_replace("/\/\*([^*]*)\*\//","", $this->sql);
143
144 //old approach: did not allow the specification of a table type
145 //$tableBodys = split("\);",$sql);
146 $tableBodys = preg_split("/[\r\n]{1}\)\s*(TYPE\s*=\s*[a-zA-Z0-9_]*\s*)?;/i", $sql);
147 while (list($key, $tableBody) = each($tableBodys)) {
148 if (strpos(strtoupper($tableBody),"CREATE TABLE") !== false) {
149 $rsdEngineDBTable = new RSDEngineDBTable(
150 "$tableBody);",
151 $this->projectName,
152 $this->authors,
153 $this->copyright,
154 $this->tablePrefix,
155 $this->columnPrefix,
156 $this
157 );
158 if (!$rsdEngineDBTable->ignore) {
159 $this->_addTable($rsdEngineDBTable);
160 }
161 }
162 }
163 $this->_collectRelations();
164 $this->_setIsKeyForAllColumns();
165 $this->_createKeyMethods();
166 }
167
168 /**Generates and returns the base and the child class for each table defined in $this->sql.
169 *
170 * The generation is performed by $this->_parse().
171 * Each class is stored as an instance of RSDEngineClass.
172 * @see _parse
173 *
174 * @return Array An associative array containing all classes the class names are used as the keys.
175 */
176 function getClasses()
177 {
178 $this->classes = array();
179 reset($this->tables);
180 while (list($tableName, $table) = each($this->tables)) {
181 $this->classes[$table->getClassName()] = new RSDEngineClass(
182 $this->config,
183 $table->getClassName(),
184 $table->getInstanceName(),
185 $table->getCode()
186 );
187 $write = $table->getFileOptionProperty('baseClass', 'write');
188 $this->classes[$table->getClassName()]->setWrite($write);
189
190 $this->classes[$table->getChildClassName()] = new RSDEngineClass(
191 $this->config,
192 $table->getChildClassName(),
193 $table->getChildClassInstanceName(),
194 $table->getChildClassCode()
195 );
196 $write = $table->getFileOptionProperty('childClass', 'write');
197 $this->classes[$table->getChildClassName()]->setWrite($write);
198 }
199 return $this->classes;
200 }
201
202 function getControllerFiles(&$argConfig)
203 {
204 $controllerFiles = array();
205 reset($this->tables);
206 while (list($key, $val) = each($this->tables)) {
207 unset($config);
208 $config = array();
209 reset($argConfig);
210 while (list($key3, $val3) = each($argConfig)) {
211 $config[$key3] =& $argConfig[$key3];
212 }
213 $config['table'] =& $this->tables[$key];
214
215 $file = new RSDEngineDBControllerFileGet($config);
216 $controllerFiles[$file->getFilename()] = $file;
217
218 $file = new RSDEngineDBControllerFileGetOne($config);
219 $controllerFiles[$file->getFilename()] = $file;
220
221 $file = new RSDEngineDBControllerFileSearch($config);
222 $controllerFiles[$file->getFilename()] = $file;
223
224 $file = new RSDEngineDBControllerFileCreate($config);
225 $controllerFiles[$file->getFilename()] = $file;
226
227 $file = new RSDEngineDBControllerFileDelete($config);
228 $controllerFiles[$file->getFilename()] = $file;
229
230 $file = new RSDEngineDBControllerFileUpdate($config);
231 $controllerFiles[$file->getFilename()] = $file;
232
233 while (list($key2, $column) = each($this->tables[$key]->columns)) {
234 if ($column->getIsValidFileOptions() != null) {
235 $config2 =& $config;
236 $config2['column'] =& $this->tables[$key]->columns[$key2];
237 $file = new RSDEngineDBControllerFileGetStored($config2);
238 $controllerFiles[$file->getFilename()] = $file;
239 } elseif (count($column->editLiveUserRightOptions) > 0) {
240 $config2 =& $config;
241 $config2['column'] =& $this->tables[$key]->columns[$key2];
242 $file = new RSDEngineDBControllerFileUpdateRight($config2);
243 $controllerFiles[$file->getFilename()] = $file;
244 } elseif (count($column->editLiveUserAreaOptions) > 0) {
245 $config2 =& $config;
246 $config2['column'] =& $this->tables[$key]->columns[$key2];
247 $file = new RSDEngineDBControllerFileUpdateArea($config2);
248 $controllerFiles[$file->getFilename()] = $file;
249 } elseif (count($column->editLiveUserGroupOptions) > 0) {
250 $config2 =& $config;
251 $config2['column'] =& $this->tables[$key]->columns[$key2];
252 $file = new RSDEngineDBControllerFileUpdateGroup($config2);
253 $controllerFiles[$file->getFilename()] = $file;
254 }
255 }
256 }
257 return $controllerFiles;
258 }
259
260 /**Returns an associative array containing instances of child classes of RSDEngineFile.
261 * @return Array An associative array.
262 */
263 function getTemplateFiles(&$argConfig)
264 {
265 $templateFiles = array();
266 reset($this->tables);
267 while (list($key, $val) = each($this->tables)) {
268 unset($config);
269 $config = array();
270 reset($argConfig);
271 while (list($key3, $val3) = each($argConfig)) {
272 $config[$key3] =& $argConfig[$key3];
273 }
274 $config['table'] =& $this->tables[$key];
275
276
277 $file = new RSDEngineDBTemplateFileGet($config);
278 $templateFiles[$file->getFilename()] = $file;
279
280 $file = new RSDEngineDBTemplateFileGetRecord($config);
281 $templateFiles[$file->getFilename()] = $file;
282
283 $file = new RSDEngineDBTemplateFileGetOne($config);
284 $templateFiles[$file->getFilename()] = $file;
285
286 $file = new RSDEngineDBTemplateFileSearch($config);
287 $templateFiles[$file->getFilename()] = $file;
288
289 $file = new RSDEngineDBTemplateFileSearchRecord($config);
290 $templateFiles[$file->getFilename()] = $file;
291
292 $file = new RSDEngineDBTemplateFileCreate($config);
293 $templateFiles[$file->getFilename()] = $file;
294
295 $file = new RSDEngineDBTemplateFileDelete($config);
296 $templateFiles[$file->getFilename()] = $file;
297
298 $file = new RSDEngineDBTemplateFileUpdate($config);
299 $templateFiles[$file->getFilename()] = $file;
300
301 while (list($key2, $column) = each($this->tables[$key]->columns)) {
302 if (count($column->editLiveUserRightOptions) > 0) {
303 $config2 =& $config;
304 $config2['column'] =& $this->tables[$key]->columns[$key2];
305 $file = new RSDEngineDBTemplateFileUpdateRight($config2);
306 $templateFiles[$file->getFilename()] = $file;
307 } elseif (count($column->editLiveUserAreaOptions) > 0) {
308 $config2 =& $config;
309 $config2['column'] =& $this->tables[$key]->columns[$key2];
310 $file = new RSDEngineDBTemplateFileUpdateArea($config2);
311 $templateFiles[$file->getFilename()] = $file;
312 } elseif (count($column->editLiveUserGroupOptions) > 0) {
313 $config2 =& $config;
314 $config2['column'] =& $this->tables[$key]->columns[$key2];
315 $file = new RSDEngineDBTemplateFileUpdateGroup($config2);
316 $templateFiles[$file->getFilename()] = $file;
317 }
318 }
319 }
320 return $templateFiles;
321 }
322
323 /**Returns the functions generated by RSDEngineDB in an associative array.
324 *
325 * Each function is stored as an instance of RSDEngineFunction.
326 * By now now functions are created at all!
327 *
328 * @return Array An associative array.
329 */
330 function getFunctions()
331 {
332 $this->functions = array();
333 return $this->functions;
334 }
335
336 /**Calls the method RSDEngineDBTable::createKeyMethods for all RSDEngineDBTable objects.
337 * @see RSDEngineDBTable::createKeyMethods
338 * @access private
339 */
340 function _createKeyMethods()
341 {
342 reset($this->tables);
343 while (list($tableName, $table) = each($this->tables)) {
344 $this->tables[$tableName]->parseTableOptions();
345 }
346 $this->_checkColumnDuplicates();
347 $this->_createJoinFunctions();
348 if (!is_array($this->tables)) {
349 return false;
350 }
351 reset($this->tables);
352 while (list($tableName, $table) = each($this->tables)) {
353 $this->tables[$tableName]->createKeyMethods();
354 }
355 }
356
357 /**Produces warnings for columns that are not unique.
358 *
359 * Column names should be unique because when fetching records from a query joining multiple tables into an
360 * assocciative array with the column names as keys, one column might overwrite the other.
361 */
362 function _checkColumnDuplicates()
363 {
364 $columnNames = array();
365 reset($this->tables);
366 while (list($tableName, $table) = each($this->tables)) {
367 while (list($columnName, $column) = each($this->tables[$tableName]->columns)) {
368 if (isset($columnNames[$columnName])) {
369 $this->config['rsdEngine']->logWarn("Column name $column->fullName is not unique: already taken by " . $columnNames[$columnName]->fullName . "; Column names should be unique because when fetching records from a query joining multiple tables into an assocciative array with the column names as keys, one column might overwrite the other.");
370 } else {
371 $columnNames[$columnName] =& $this->tables[$tableName]->columns[$columnName];
372 }
373 }
374 }
375 }
376 /**Adds an instance of RSDEngineDBTable to the internal stack of RSDEngineDBTable object.
377 *
378 * The instance passed as argument is added to the property array tables.
379 * @see tables
380 * @access private
381 *
382 * @param RSDEngineDBTable $table An instance of RSDEngineDBTable
383 * @return mixed If a table with such a name already exists or the table name is an empty string an instance of RSError is returned otherwise true.
384 */
385 function _addTable($table)
386 {
387 if ($this->tableExists($table->name)) {
388 return RSErrorManager::raiseRSError($table->name, null, "RSDEngineDB::_addTable", "The table $table->name is defined two times!", RSERROR_FATAL_ERROR);
389 }
390 if ($table->name == "") {
391 if (get_class($table) == "rsdenginedbtable") {
392 $message = "The property name of the RSDEngineDBTable instance passed to _addTable was empty! The table was defined as: $table->contents";
393 return RSErrorManager::raiseRSError(RSDEngineDB, null, "RSDEngineDB::_addTable", $message, RSERROR_FATAL_ERROR);
394 } else {
395 return RSErrorManager::raiseRSError(RSDEngineDB, null, "RSDEngineDB::_addTable", "_addTable was called with an argument that is not an instance of RSDEngineDBTable. This probably means that the your SQL syntax was not correct.", RSERROR_FATAL_ERROR);
396 }
397 }
398 $this->tables[$table->name] =& $table;
399 return true;
400 }
401
402 /**Copies all RSDRelation objects hold by the RSDEngineDBTable instances in RSDEngineDBTable::realations to RSDEngine::relations.
403 *
404 * @see relations
405 * @see RSDEngineDBTable::relations
406 * @access private
407 */
408 function _collectRelations()
409 {
410 while (list($tableName, $table) = each($this->tables)) {
411 if (is_array($table->relations)) {
412 while (list($key,$relation) = each($table->relations)) {
413 $this->relations[] = $relation;
414 }
415 }
416 }
417 }
418
419 /**Set foreign/primary key related properties for all RSDEngineDBTable objects.
420 *
421 * @access private
422 */
423 function _setIsKeyForAllColumns()
424 {
425 reset($this->relations);
426 while (list($key, $relation) = each($this->relations)) {
427 $fromTable =& $this->getTable($relation->fromTable);
428 $fromTable =& $this->tables[$fromTable->name];
429
430 $fromColumn =& $fromTable->getColumn($relation->fromColumn);
431 $fromColumn =& $fromTable->columns[$fromColumn->name];
432 $fromColumn->setKey("foreign");
433 $fromColumn->setForeignKeyTarget($relation->to);
434
435 //if the foreign key target was not defined as any key, set it to an undefined key
436 $toTable =& $this->getTable($relation->toTable);
437 $toTable =& $this->tables[$toTable->name];
438 $toColumn =& $toTable->getColumn($relation->toColumn);
439 $toColumn =& $toTable->columns[$toColumn->name];
440 if ($toColumn->isAnyKey() == false) {
441 $toColumn->setKey("undefined");
442 }
443 }
444 }
445
446 /**Calls createJoin _createJoinFunctionsForTable for each instance of RSDEngineDBTable.
447 *
448 * @see _createJoinFunctionsForTable
449 * @access private
450 */
451 function _createJoinFunctions()
452 {
453 ///$this->config['rsdEngine']->logInfo("Method called: _createJoinFunctions()");
454 reset($this->tables);
455 while (list($tableName, $table) = each($this->tables)) {
456 $this->config['rsdEngine']->logInfo("Generating all possible selectIncluding* methods for '$tableName'");
457 $this->_createJoinFunctionsForTable($tableName);
458 }
459 }
460
461 /**Calls RSDEngineDBTable::createSelectIncludingMethod for each combination of relations valid for a table.
462 *
463 * RSDEngine::_generateNameForCreateSelectIncludingMethod is used to genertae the method name.
464 *
465 * @access private
466 * @param String $tableName The name of the table.
467 * @return boolean False if $tableName was an empty string, otherwise true.
468 */
469 function _createJoinFunctionsForTable($tableName)
470 {
471 if ($tableName == "") {
472 return false;
473 }
474 ///$this->config['rsdEngine']->logInfo("Method called: _createJoinFunctionsForTable($tableName)");
475 $relations = $this->_getRelationsRelatedToTable($tableName);
476
477 /*if (count($relations) > 8 ) {
478 return false;
479 }
480 */
481 $this->_checkRelations($relations);
482 ///$this->config['rsdEngine']->logInfo("Calling RSArrayUtil::getAllCombinations [relations count=" . count($relations) . " in _createJoinFunctionsForTable($tableName)");
483 $combinations = RSArrayUtil::getAllCombinations($relations, new RSToStringComparator(), RSARRAYUTIL_IGNORE_ORDER, false, array(), 4);
484
485 $validCombinations = array();
486 while (list($key, $relationCombination) = each($combinations)) {
487 if ($this->_isValidRelationCombination($tableName, $relationCombination)) {
488 $validCombinations[] = $relationCombination;
489 } else {
490 //$selectMethodName = $this->_generateNameForCreateSelectIncludingMethod($relationCombination);
491 //echo "INVALID: selectMethodName=$selectMethodName<br>";
492 }
493 }
494
495 reset($validCombinations);
496 while (list($key, $relationCombination) = each($validCombinations)) {
497 $selectMethodName = $this->_generateNameForCreateSelectIncludingMethod($relationCombination);
498 $rsdTable =& $this->getTable($tableName);
499 $rsdTable->prepareSelectIncludingMethod($selectMethodName,$relationCombination);
500 }
501
502 reset($validCombinations);
503 while (list($key, $relationCombination) = each($validCombinations)) {
504 $selectMethodName = $this->_generateNameForCreateSelectIncludingMethod($relationCombination);
505 $rsdTable =& $this->getTable($tableName);
506 $rsdTable->createSelectIncludingMethod($selectMethodName,$relationCombination);
507 }
508
509 $rsdTable =& $this->getTable($tableName);
510 $rsdTable =& $this->tables[$rsdTable->name];
511 $rsdTable->createSelectIncludingMethod('selectIncludingAll', $relations);
512
513 $relations = $this->_getRelationsByFromTable($tableName);
514 $rsdTable->createSelectIncludingMethod('selectIncludingDirectlyRelated', $relations);
515 return true;
516 }
517
518 /**Returns true if the table specified by it's name passed as first argument exists.
519 * @see tables
520 *
521 * @return boolean True if the table exists, false otherwise.
522 */
523 function tableExists($tableName)
524 {
525 return isset($this->tables[$tableName]);
526 }
527
528 /**Returns the table named $tableName or an instance of RSError on failure.
529 * @see tables
530 *
531 * @return mixed An instance of RSDEngineDBTable or an instance of RSError.
532 */
533 function &getTable($tableName)
534 {
535 if ($this->tableExists($tableName)) {
536 return $this->tables[$tableName];
537 } else {
538 return RSErrorManager::raiseRSError("RSDEngineDB", $tableName, "getTable", "The table $tableName does not exists.", RSERROR_FATAL_ERROR);
539 }
540 }
541
542 /**Returns an Array or relations that start from the table $tableName or from the tables these relations point to.
543 *
544 * @access private
545 * @param String $fromTable The name of the table - the starting point.
546 * @param Array $relations The array of relations in which to search. This argument is optional. The default is to search in the property relations.
547 * @param Array $tables An array of strings (table names). Each string represents a table that was already processed.
548 * @return Array The relations found.
549 * @see relations
550 */
551 function _getRelationsRelatedToTable($tableName,$relations = false, $tables = false)
552 {
553 ///$this->config['rsdEngine']->logInfo("Method called: _getRelationsRelatedToTable($tableName)");
554 if ($tables == false) {
555 $tables = array();
556 }
557 $tables[] = $tableName;
558
559 //Passing the array $tables to _getRelationsByFromTable as third argument prevents an endless loop
560 //in case of a back-reference.
561 $primaryRelations = $this->_getRelationsByFromTable($tableName, $relations, $tables);
562 while (list($key, $relation) = each($primaryRelations)) {
563 $elementsToAdd =& $this->_getRelationsRelatedToTable($relation->toTable, $relations, $tables);
564 if (count($primaryRelations) + count($elementsToAdd) > 10) {
565 break;
566 }
567 RSArrayUtil::addElements($primaryRelations, $elementsToAdd);
568 }
569 return RSArrayUtil::removeDuplicates($primaryRelations, new RSToStringComparator());
570 }
571
572 /**Returns an Array containing all relations that have the table specified by the first argument as starting point.
573 *
574 * @access private
575 * @param String $fromTable The name of the table from wich all relations have to start.
576 * @param Array $relations The array of relations in which to search. This argument is optional.
577 * The default is to search in the property relations.
578 * @param Array $excludedTargetTables An array of table names (strings) the relations must not lead to.
579 * This feature is required by _getRelationsRelatedToTable to prevent endless loops. If set to false
580 * it is ignored. This argument is optional. The default is false.
581 * @see relations
582 */
583 function _getRelationsByFromTable($fromTable, $relations = false, $excludedTargetTables = array())
584 {
585 ///$this->config['rsdEngine']->logInfo("Method called: _getRelationsByFromTable($fromTable)");
586 if (!is_array($relations)) {
587 $relations = $this->relations;
588 }
589 if (!is_array($relations)) {
590 return array();
591 }
592
593 $ret = array();
594 reset($relations);
595 while (list($key, $relation) = each($relations)) {
596 if ($relation->fromTable == $fromTable) {
597 if (!RSArrayUtil::hasElement($excludedTargetTables, $relation->toTable, new RSPrimitiveComparator())) {
598 $ret[] = $relation;
599 }
600 }
601 }
602 return $ret;
603 }
604
605 /**Returns true if the combination of relations passed as array as second argument is valid for the table name passed as first argument.
606 *
607 * @access private
608 * @param String $tableName The name of the table.
609 * @param Array $relations The combination of relations.
610 * @return boolean True if the combination is valid, false otherwise.
611 */
612 function _isValidRelationCombination($tableName, $relations)
613 {
614 ///$this->config['rsdEngine']->logInfo("Method called: _isValidRelationCombination($tableName)");
615 if (!is_array($relations)) {
616 return false;
617 }
618 $relatedRelations = $this->_getRelationsRelatedToTable($tableName, $relations);
619 return RSArrayUtil::hasElements($relatedRelations, $relations, new RSToStringComparator());
620 }
621
622 /**Checks if all relations in the array passed as argument have existing starting points and destinations.
623 *
624 * The properties fromTable, fromColumn, toTable, toColumn are checked for all relations.
625 * @access private
626 */
627 function _checkRelations($relations)
628 {
629 ///$this->config['rsdEngine']->logInfo("Method Called: _checkRelations($relations)");
630 reset($relations);
631 while (list($key, $relation) = each($relations)) {
632 $fromTable =& $this->getTable($relation->fromTable);
633 $fromColumn =& $fromTable->getColumn($relation->fromColumn);
634
635 $toTable =& $this->getTable($relation->toTable);
636 $toColumn =& $toTable->getColumn($relation->toColumn);
637 /*
638 if (!$this->tableExists($relation->fromTable)) {
639 return RSErrorManager::raiseRSError("RSDEngineDB", $relation->fromTable, "RSDEngineDB::_checkRelations", "The table $relation->fromTable does not exist. It is used in this relation: " . $relation->toString(), RSERROR_NOT_OBJECT);
640 } elseif (!$this->tables[$relation->fromTable]->columnExists($relation->fromColumn)) {
641 return RSErrorManager::raiseRSError($relation->fromTable, $relation->fromColumn, "RSDEngineDB::_checkRelations", "The column $relation->from does not exist. It is used in the relation " . $relation->toString(), RSERROR_NOT_OBJECT);
642 }
643 if (!$this->tableExists($relation->toTable)) {
644 $this->_warning("The table " . $relation->toTable . " does not exist. It is used in this relation: <i>" . $relation->toString() . "</i>");
645 } elseif(!$this->tables[$relation->toTable]->columnExists($relation->toColumn)) {
646 $this->_warning("The column " . $relation->to . " does not exist. It is used in this relation: <i>" . $relation->toString() . "</i>");
647 }
648 */
649 }
650 }
651
652 /**Returns a name for a selectIncluding* method which is determinated by the relations passed as argument.
653 *
654 * @param Array $relations An array of relations.
655 * @return String The name of the selectIncluding* method.
656 * @access private
657 */
658 function _generateNameForCreateSelectIncludingMethod($relations)
659 {
660 reset($relations);
661 $name = "";
662 while (list($key,$relation) = each($relations)) {
663 if ($name != "") {
664 $name .= "And";
665 }
666 $name .= ucfirst(strtolower($this->_removeTablePrefix($relation->toTable)));
667 }
668 return "selectIncluding$name";
669 }
670
671 /**Strips the table prefix from a table name and returns it.
672 *
673 * @access private
674 * @see tablePrefix
675 * @param String $tableName The name of the table (with prefix).
676 * @return String The name of the table with the prefix removed.
677 */
678 function _removeTablePrefix($tableName)
679 {
680 if ($this->tablePrefix == "") {
681 return $tableName;
682 }
683 return preg_replace('/^' . $this->tablePrefix . '/i','', $tableName);
684 }
685 }
686 ?>

Documentation generated on Mon, 8 Dec 2003 13:10:48 +0100 by phpDocumentor 1.2.3