Source for file StoredObject.inc

Documentation is available at StoredObject.inc

  1. <?php
  2. /**
  3. * StoredObject Class.
  4. *
  5. * A base class that contains tools for storing
  6. * and retrieving objects from a database
  7. * This is effectively an abstract class and
  8. * shuld never be instantiated directly.
  9. *
  10. * This file is part of CompInaBox.
  11. * @copyright Copyright 2001-2005. Eric D. Nielsen, All rights reserverd.
  12. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  13. * @author Eric D. Nielsen <nielsene@alum.mit.edu>
  14. *
  15. * @package ObjectRelationalMappingLayer
  16. */
  17.  
  18. /**
  19. * StoredObject
  20. *
  21. * A base class that contains tools for storing
  22. * and retrieving objects from a database
  23. * @package ObjectRelationalMappingLayer
  24. * @access public
  25. * @abstract
  26. */
  27. class StoredObject
  28. {
  29. /**
  30. * Acts as DB primary key
  31. * @var string
  32. * @access private
  33. */
  34. var $primeField;
  35. /**#@+
  36. * @access private
  37. */
  38. /** Storeable member variables
  39. * @var array
  40. */
  41. var $fields;
  42. /** List of tables in the DB that the subtype uses
  43. * @var array
  44. */
  45. var $tables;
  46. /** What fields are out of date with the DB
  47. * @var array
  48. */
  49. var $dirty;
  50. /** Mapping member variabbles to column(s) in the DB's table(s)
  51. * @var array
  52. */
  53. var $fieldsToTables;
  54. /** Inverse mapping of {@link StoredObject::$fieldsToTables}
  55. * @var array
  56. */
  57. var $tablesToFields;
  58. /** Order in which tables should be processed
  59. * @var array
  60. */
  61. var $tableOrder;
  62. /**#@-*/
  63.  
  64. /**
  65. * Database Abstraction Connection
  66. * @access private
  67. * @var DB
  68. */
  69. var $db;
  70.  
  71. /**
  72. * StoredObject Constructor
  73. * @param DB $db the databasse to interact with
  74. */
  75. function StoredObject($db=0)
  76. {
  77. # note this is a abstract class, $primekey must be set
  78. $this->db=$db;
  79. $this->fields=array();
  80. $this->tables=array();
  81. $this->dirty=array();
  82. $this->fieldsToTables=array();
  83. $this->tablesToFields=array();
  84. $this->tableOrder=array();
  85. }
  86.  
  87.  
  88. /**
  89. * Generate a select statement for a given table.
  90. * Generates a select statement, selecting all registered
  91. * columns from a given single table, by the tables's primary
  92. * key columnm.
  93. * @access private
  94. * @param string $tableName the table a SELECT is needed for
  95. * @param array $table information about the table
  96. * @param boolean $multi do we need to subindex the member variables
  97. * @param int $m the subindex to use
  98. * @return string a full SELECT statement
  99. * @todo why passing $table not using $this->tables[$tableName]?
  100. * @todo why not default $multi and $m
  101. */
  102. function getSelectByIDString($tableName, $table,$multi,$m)
  103. {
  104. $result = "SELECT " . arrayToCSL($table[1]) . " FROM $tableName ";
  105. $tableKey = $table[0];
  106. $result .= "WHERE $tableKey = '";
  107. # echo printArray($this->tablesToFields);
  108. # echo printArray($this->fields);
  109. $fieldName = $this->tablesToFields[$tableKey][$tableName];
  110. if ($multi==1)
  111. $result .= $this->fields[$fieldName] . "';";
  112. else
  113. $result .= $this->fields[$fieldName][$m] . "';";
  114. return $result;
  115. }
  116. /**
  117. * Remove this stored object from the database.
  118. * Completely remove this stored object from the database. This
  119. * method relies on the the ON DELETE behavoir of the referenced
  120. * tabes to work. Only the row referenced by the primeField is deleted,
  121. * directly.
  122. * @access public
  123. * @todo add error reporting when ON DELETE RESTRICT?
  124. */
  125. function remove()
  126. {
  127. $tableName = $this->tableOrder[0];
  128. $tableKey = $this->tables[$tableName][0];
  129. $prime = $this->fields[$this->primeField];
  130. $query = "DELETE FROM $tableName WHERE $tableKey=$prime;";
  131. $this->db->query($query);
  132. }
  133.  
  134. /**
  135. * Load the identified records into memory.
  136. * Fetch the referenced object from the database. If an $id is
  137. * passed in use that, if not, attempt to use $this->getID, if
  138. * neither fail.
  139. * @access public
  140. * @param mixed $id the primary key of the object to load
  141. * @return int 1 on success, 0 on fail
  142. */
  143. function retrieve($id=0)
  144. {
  145. $db=$this->db;
  146. if ($id!=0)
  147. $this->setID($id);
  148. $currentID = $this->getID();
  149. if (!$currentID)
  150. return 0; #no ID set
  151. $numTables = count($this->tables);
  152. for ($i=0;$i<$numTables;$i++)
  153. {
  154. $tableName = $this->tableOrder[$i];
  155. $table = $this->tables[$tableName];
  156. $tableKey = $this->tablesToFields[$table[0]][$tableName];
  157. $tableKeyValue = $this->fields[$tableKey];
  158. if (!is_array($tableKeyValue))
  159. $tableKeyValue = array($tableKeyValue);
  160. $numValues = count($tableKeyValue);
  161. for ($m=0;$m<$numValues;$m++)
  162. {
  163. if (!isset($this->fields[$tableKey]) || $tableKeyValue[$m]=="") continue;
  164. $query = $this->getSelectByIDString($tableName,$table,$numValues,$m);
  165. # echo $query . "<br>";
  166. $result = $db->query($query);
  167. $numFields = count($table[1]);
  168. switch($numRows = $result->numRows())
  169. {
  170. case 0 : break;
  171. case 1 :
  172. $temp = $result->getRowAt(0);
  173. for ($k=0;$k<$numFields;$k++)
  174. {
  175. $level1 = $table[1][$k];
  176. $field = $this->tablesToFields[$level1][$tableName];
  177. if ($numValues==1)
  178. $this->fields[$field] = $temp[$k];
  179. else
  180. $this->fields[$field][$m] = $temp[$k];
  181. }
  182. break;
  183. default:
  184. for ($j=0;$j<$numRows;$j++)
  185. {
  186. $temp = $result->getRowAt($j);
  187. for ($k=0;$k<$numFields;$k++)
  188. {
  189. $level1= $table[1][$k];
  190. $field = $this->tablesToFields[$level1][$tableName];
  191. if ($numValues==1)
  192. $this->fields[$field][$j] = $temp[$k];
  193. else
  194. $this->fields[$field][$m][$j] = $temp[$k];
  195. }
  196. }
  197. }
  198. }
  199. }
  200. return 1;
  201. }
  202. /**
  203. * Save/Update the object to the Database.
  204. * Either INSERTS or UPDATES, as appropriate, into the
  205. * database to bring the db upto date with the state of the
  206. * object. Does NOT do any checking for stale data.
  207. *
  208. * Clears the status of all dirty bits to reflect clean status.
  209. * @access public
  210. * @return mixed the primary key of the object
  211. */
  212. function postToDB()
  213. {
  214. if ($this->fields[$this->primeField]=="")
  215. $result = $this->insertNew();
  216. else
  217. $result = $this->update($this->fields[$this->primeField]);
  218. reset($this->fields);
  219. while ($aField = each($this->fields))
  220. {
  221. $temp=$aField['key'];
  222. $this->dirty[$temp]=FALSE;
  223. }
  224. return $this->fields[$this->primeField];
  225. }
  226.  
  227. /**
  228. * INSERTS the object to the Database.
  229. * INSERTS into the
  230. * database to bring the db upto date with the state of the
  231. * object. Does NOT do any checking for stale data.
  232. *
  233. * @access private
  234. * @return mixed the primary key of the object
  235. */
  236. function insertNew()
  237. {
  238. reset($this->fields);
  239. $tablesInvolved = array();
  240. while ($field = each($this->fields))
  241. {
  242. if ($field['value']=="" ) continue;
  243. $tablesAffectedByField = $this->fieldsToTables[$field['key']];
  244. reset($tablesAffectedByField);
  245. while ($aTable = each($tablesAffectedByField))
  246. {
  247. if (in_array($aTable['key'],array_keys($tablesInvolved)))
  248. array_push($tablesInvolved[$aTable['key']],$this->fieldsToTables[$field['key']][$aTable['key']]);
  249. else
  250. $tablesInvolved[$aTable['key']]=array($this->fieldsToTables[$field['key']][$aTable['key']]);
  251. }
  252. }
  253. reset($tablesInvolved);
  254. while ($aTable = each($tablesInvolved))
  255. {
  256. $primeColumn = $this->tables[$aTable['key']][0];
  257. $tableName = $aTable['key'];
  258. $columns = $aTable['value'];
  259. $tablePrimeField = $this->tablesToFields[$primeColumn][$tableName];
  260. $arrayDepth=1;
  261. $numColumns = count($columns);
  262. for ($i=0;$i<$numColumns;$i++)
  263. {
  264. $tempFieldName = $this->tablesToFields[$columns[$i]][$tableName];
  265. $aColumn = $this->fields[$tempFieldName];
  266. if (is_array($aColumn) && (count($aColumn) > $arrayDepth))
  267. $arrayDepth = count($aColumn);
  268. }
  269. for ($i=0;$i<$arrayDepth;$i++)
  270. {
  271. $query = "INSERT INTO $tableName (";
  272. $queryPart2 = "values (";
  273. $first = TRUE;
  274. $tablePrimeValue = $this->fields[$tablePrimeField];
  275. if ($tablePrimeValue!="")
  276. {
  277. $needPrime=FALSE;
  278. if (!in_array($primeColumn,$columns))
  279. {
  280. $query .= "$primeColumn";
  281. $keyValue = $this->fields[$this->tablesToFields[$primeColumn][$tableName]];
  282. $queryPart2 .= "'$keyValue'";
  283. $first=FALSE;
  284. }
  285. }
  286. else
  287. {
  288. $needPrime=TRUE;
  289. # $primeSelect = "SELECT $primeColumn from $tableName WHERE ";
  290. }
  291. reset($columns);
  292. while ($aColumn = each($columns))
  293. {
  294. $columnName = $aColumn['value'];
  295. $fieldValue = $this->fields[$this->tablesToFields[$columnName][$tableName]];
  296. if (!$first)
  297. {
  298. $queryPart2 .= ", ";
  299. $query .= ", ";
  300. # if ($needPrime) $primeSelect .= "AND ";
  301. }
  302. else
  303. $first=FALSE;
  304. $query .= "$columnName";
  305. if (is_array($fieldValue))
  306. $queryPart2 .= "'$fieldValue[$i]'";
  307. else
  308. $queryPart2 .= "'$fieldValue'";
  309. # if ($needPrime)
  310. # {
  311. # if (is_array($fieldValue))
  312. # $primeSelect .= "$columnNames='fieldValue[$i]'";
  313. # else
  314. # $primeSelect .= "$columnName='$fieldValue'";
  315. # }
  316. }
  317. $query .= ") $queryPart2);";
  318. # echo "<br>".$query;
  319. $result = $this->db->query($query);
  320. if ($needPrime)
  321. {
  322. $lastOID = $this->db->getLastOID();
  323. $query = "SELECT $primeColumn FROM $tableName WHERE oid=$lastOID;";
  324. $result = $this->db->query($query);
  325. # $primeSelect .= ";";
  326. # $result = $this->db->query($primeSelect);
  327. $temp = $result->getRowAt(0);
  328. $keyField = $this->tablesToFields[$primeColumn][$tableName];
  329. $this->fields[$keyField] = $temp[0];
  330. }
  331. }
  332. }
  333. return $this->fields[$this->primeField];
  334. }
  335.  
  336. /**
  337. * UPDATES the object to the Database.
  338. * UPDATES into the
  339. * database to bring the db upto date with the state of the
  340. * object. (This can include some INSERTS/DELETES when dealingn
  341. * with multi-valued variables -- aka lists.
  342. *
  343. * @access private
  344. * @return mixed the primary key of the object
  345. */
  346. function update($id)
  347. {
  348. $dirtyTables = array();
  349. reset($this->dirty);
  350. while ($aField = each($this->dirty))
  351. {
  352. if ($aField['value'])
  353. {
  354. $affectedTables = $this->fieldsToTables[$aField['key']];
  355. reset($affectedTables);
  356. while ($aTable = each($affectedTables))
  357. {
  358. if (in_array($aTable['key'],array_keys($dirtyTables)))
  359. array_push($dirtyTables[$aTable['key']],$this->fieldsToTables[$aField['key']][$aTable['key']]);
  360. else
  361. $dirtyTables[$aTable['key']]=array($this->fieldsToTables[$aField['key']][$aTable['key']]);
  362. }
  363. }
  364. }
  365. reset($dirtyTables);
  366. while ($aTable = each($dirtyTables))
  367. {
  368. $tableName = $aTable['key'];
  369. $primeColumn = $this->tables[$tableName][0];
  370. $columns = $aTable['value'];
  371. $tablePrimeField = $this->tablesToFields[$primeColumn][$tableName];
  372. $arrayDepth=0;
  373. $fieldIsArray=array();
  374. $numColumns= count($columns);
  375. for ($i=0;$i<$numColumns;$i++)
  376. {
  377. $tempFieldName = $this->tablesToFields[$columns[$i]][$tableName];
  378. $fieldIsArray[$tempFieldName]=FALSE;
  379. $aColumn = $this->fields[$tempFieldName];
  380. if (is_array($aColumn))
  381. {
  382. $fieldIsArray[$tempFieldName]=TRUE;
  383. if (count($aColumn) > $arrayDepth)
  384. $arrayDepth = count($aColumn);
  385. }
  386. }
  387. if (!$arrayDepth) # normal update
  388. {
  389. $tableKey = $this->tables[$tableName][0];
  390. $query = "UPDATE $tableName SET ";
  391. $dirtyFields = $aTable['value'];
  392. reset($dirtyFields);
  393. $first=TRUE;
  394. while ($aField = each($dirtyFields))
  395. {
  396. $columnName = $aField['value'];
  397. $fieldValue = $this->fields[$this->tablesToFields[$columnName][$tableName]];
  398. if (!$first) $query .= ", ";
  399. $query .= " $columnName ='$fieldValue' ";
  400. $first=FALSE;
  401. }
  402. $query .= "WHERE $tableKey = '$id';";
  403. # echo $query;
  404. $this->db->query($query);
  405. }
  406. else
  407. {
  408. #######################
  409. $objectType = get_class($this);
  410. $tempObject = new $objectType($this->db);
  411. $tempObject->setID($this->getID());
  412. $tempObject->retrieve();
  413. # echo printArray($tempObject);
  414. # find the array(s)
  415. $storedFields = $tempObject->fields;
  416. $storedIsArray = array();
  417. $storedDepth =1;
  418. reset($storedFields);
  419. while ($aField = each($storedFields))
  420. {
  421. if (is_array($aField['value']))
  422. {
  423. $storedIsArray[$aField['key']]=TRUE;
  424. if (($tempCount=count($aField['value']))>$storedDepth)
  425. $storedDepth=$tempCount;
  426. }
  427. }
  428. $inserts = array(); # for now we'll delete everything
  429. $deletes = array(); # and reinsert, later well also check
  430. # for updates to avoid delete/insert pairs
  431. for ($i=0;$i<$storedDepth;$i++)
  432. $deletes[$i][0]=$tempObject->fields[$tablePrimeField];
  433. reset($columns);
  434. $j=0;
  435. while ($aColumn = each($columns))
  436. {
  437. if ($primeColumn==$aColumn['value']) continue;
  438. $j++;
  439. $columnName = $aColumn['value'];
  440. $fieldValue = $tempObject->fields[$this->tablesToFields[$columnName][$tableName]];
  441. if (is_array($fieldValue))
  442. for ($i=0;$i<$storedDepth;$i++)
  443. $deletes[$i][$j] = $fieldValue[$i];
  444. else
  445. for ($i=0;$i<$storedDepth;$i++)
  446. $deletes[$i][$j]=$fieldValue;
  447. }
  448. for ($i=0;$i<$arrayDepth;$i++)
  449. $inserts[$i][0]=$this->fields[$tablePrimeField];
  450. reset($columns);
  451. $j=0;
  452. while ($aColumn = each($columns))
  453. {
  454. if ($primeColumn==$aColumn['value']) continue;
  455. $j++;
  456. $columnName = $aColumn['value'];
  457. $fieldValue = $this->fields[$this->tablesToFields[$columnName][$tableName]];
  458. if (is_array($fieldValue))
  459. for ($i=0;$i<$arrayDepth;$i++)
  460. $inserts[$i][$j] = $fieldValue[$i];
  461. else
  462. for ($i=0;$i<$arrayDepth;$i++)
  463. $inserts[$i][$j]=$fieldValue;
  464. }
  465. for ($i=0;$i<$storedDepth;$i++)
  466. {
  467. $query = "DELETE FROM $tableName WHERE $primeColumn ='";
  468. $query .= $deletes[$i][0];
  469. reset($columns);
  470. $j=0;
  471. while ($aColumn=each($columns))
  472. {
  473. if ($primeColumn==$aColumn['value']) continue;
  474. $j++;
  475. $query .= "' AND ";
  476. $query .= $aColumn['value'] . " = '";
  477. $query .= $deletes[$i][$j];
  478. }
  479. $query .= "';";
  480. $result = $this->db->query($query);
  481. }
  482. for ($i=0;$i<$arrayDepth;$i++)
  483. {
  484. $query = "INSERT INTO $tableName ($primeColumn";
  485. $query2 = "('".$inserts[$i][0]."'";
  486. reset($columns);
  487. $j=0;
  488. while ($aColumn=each($columns))
  489. {
  490. if ($primeColumn==$aColumn['value']) continue;
  491. $j++;
  492. $query .= ", " . $aColumn['value'];
  493. $query2 .= ", '" . $inserts[$i][$j] ."'";
  494. }
  495. $query .= ") values $query2 );";
  496. $result = $this->db->query($query);
  497. }
  498. }
  499. }
  500.  
  501. return 1;
  502. }
  503. /**
  504. * Search on non-key data.
  505. * Searches for matching record(s) using whatever fields
  506. * have been set.
  507. *
  508. * @access public
  509. * @return mixed 0 on no match, list of primary keys if found
  510. */
  511. function searchDB()
  512. {
  513. $matches = array();
  514. reset($this->fields);
  515. $tablesInvolved = array();
  516. while ($field = each($this->fields))
  517. {
  518. if ($field['value']=="" ) continue;
  519. $tablesAffectedByField = $this->fieldsToTables[$field['key']];
  520. reset($tablesAffectedByField);
  521. while ($aTable = each($tablesAffectedByField))
  522. {
  523. if (in_array($aTable['key'],array_keys($tablesInvolved)))
  524. array_push($tablesInvolved[$aTable['key']],$this->fieldsToTables[$field['key']][$aTable['key']]);
  525. else
  526. $tablesInvolved[$aTable['key']]=array($this->fieldsToTables[$field['key']][$aTable['key']]);
  527. }
  528. }
  529. reset($tablesInvolved);
  530. $intermediateKeys=array();
  531. while ($aTable = each($tablesInvolved))
  532. {
  533. $primeColumn = $this->tables[$aTable['key']][0];
  534. $tableName = $aTable['key'];
  535. $columns = $aTable['value'];
  536.  
  537. $query = "SELECT $primeColumn FROM $tableName WHERE ";
  538. reset($columns);
  539. $first=TRUE;
  540. while ($aColumn = each($columns))
  541. {
  542. $columnName = $aColumn['value'];
  543. $fieldValue = $this->fields[$this->tablesToFields[$columnName][$tableName]];
  544. if ($fieldValue == "")
  545. $fieldValue = $intermediateKeys[$columnName];
  546. if (!$first)
  547. $query .= "AND ";
  548. else
  549. $first=FALSE;
  550. $query .= "$columnName = '$fieldValue'";
  551. }
  552. $query .= ";";
  553. $result = $this->db->query($query);
  554. $numResults = $result->numRows();
  555. if ($numResults ==0) continue;
  556. $intermediateMatches = array();
  557. for ($i=0;$i<$numResults;$i++)
  558. {
  559. $aRow = $result->getRowAt($i);
  560. array_push($intermediateMatches, $aRow[0]);
  561. }
  562. if ($this->tablesToFields[$primeColumn][$tableName]==
  563. $this->primeField)
  564. {
  565. if (count($matches))
  566. $matches = array_intersect($matches,$intermediateMatches);
  567. else
  568. $matches= $intermediateMatches;
  569. }
  570. else
  571. $intermediateKeys[$primeColumn] = $intermediateMatches[0];
  572. }
  573. return $matches;
  574. }
  575.  
  576. /**
  577. * Generic Getter.
  578. * Returns the value of the requested member variable.
  579. *
  580. * @access public
  581. * @param string $key member variable name
  582. * @return mixed the value of $key
  583. * @todo add check for $key in fields.
  584. */
  585. function getGeneralData($key)
  586. {
  587. return $this->fields["$key"];
  588. }
  589.  
  590. /**
  591. * Get Primary Key.
  592. * Returns the value of the object's database primary key
  593. *
  594. * @access public
  595. * @return mixed the primary key value, or null if the item hasn't been saved
  596. */
  597. function getID()
  598. {
  599. return $this->fields[$this->primeField];
  600. }
  601.  
  602. /**
  603. * Generic Setter.
  604. * Updates the referenced member variable to the new value and
  605. * sets the dirty bit for the member variable.
  606. *
  607. * @access public
  608. * @param string $key member variable name
  609. * @param mixed $value the value to set member variable $key to
  610. * @return int 1 on success, 0 otherwise
  611. */
  612. function setGeneralData($key, $value)
  613. {
  614. if (!in_array($key, array_keys($this->fields)))
  615. return 0;
  616. if ($this->fields[$key]!=$value)
  617. {
  618. $this->fields[$key]=$value;
  619. $this->dirty[$key]=TRUE;
  620. }
  621. return 1;
  622. }
  623.  
  624. /**
  625. * Prime ID Setter.
  626. * Normally only used to set the ID before called retrieve,
  627. * support is questionable, probably broken for changing an
  628. * items primary key via this.
  629. *
  630. * @access public
  631. * @param mixed $id the prime key to use
  632. * @return int 1 on success
  633. */
  634. function setID($id)
  635. {
  636. $this->fields[$this->primeField] = $id;
  637. $this->dirty[$this->primeField] = TRUE;
  638. return 1;
  639. }
  640.  
  641. /**
  642. * Register a table with the Object Relational Mapper.
  643. * Normally used in the constructor of a subtype to configure the
  644. * table->fields mapping.
  645. *
  646. * @access protected
  647. * @param string $tableName the name of the table to register
  648. * @param string $keyName the primary key column in the database
  649. * @param string $keyField the name of the corresponding field
  650. * @param array $columnNames a list of other columns to include
  651. * @param array $fieldNames a list of fields, index matched against $columnNames
  652. * @return int 1 on success, 0 on failure
  653. */
  654. function addTable($tableName,
  655. $keyName,$keyField,
  656. $columnNames, $fieldNames)
  657. {
  658. $numColumns = count($columnNames);
  659. $numFields = count($fieldNames);
  660. if ($numColumns != $numFields)
  661. return 0;
  662. if (!in_array($keyField,$this->fields))
  663. {
  664. $this->fields[$keyField]="";
  665. $this->dirty[$keyField]="";
  666. }
  667. if (!in_array($tableName,array_keys($this->tables)))
  668. {
  669. $this->tables[$tableName]=array($keyName,$columnNames);
  670. $this->tablesToFields[$keyName][$tableName]=$keyField;
  671. $this->fieldsToTables[$keyField][$tableName]=$keyName;
  672. $this->tableOrder[count($this->tableOrder)]=$tableName;
  673. }
  674. else
  675. {
  676. $cols = $this->tables[$tableName][1];
  677. $cols = array_unique(array_merge($cols,$columnNames));
  678. $this->tables[$tableName][1]=$cols;
  679. }
  680. for ($i=0;$i<$numColumns;$i++)
  681. {
  682. if (!in_array($fieldNames[$i],$this->fields))
  683. {
  684. $this->fields[$fieldNames[$i]]="";
  685. $this->dirty[$fieldNames[$i]]="";
  686. }
  687. $this->tablesToFields[$columnNames[$i]][$tableName]=$fieldNames[$i];
  688. $this->fieldsToTables[$fieldNames[$i]][$tableName]=$columnNames[$i];
  689. }
  690. return 1;
  691. }
  692.  
  693. /**
  694. * De-Register a table with the Object Relational Mapper.
  695. * Provided for symmetry -- never used I beleive....
  696. *
  697. * @access protected
  698. * @param string $tableName the name of the table to de-register
  699. */
  700. function removeTable($table)
  701. {
  702. list($keyName, $columns) = $this->tables[$table];
  703. reset($columns);
  704. while($aColumn = each($columns))
  705. {
  706. $fieldName = $this->tablesToFields[$aColumn['value']][$table];
  707. unset($this->tablesToFields[$aColumn['value']][$table]);
  708. unset($this->fieldsToTables[$fieldName][$table]);
  709. if (!count($this->tablesToFields[$aColumn['value']]))
  710. unset($this->tablesToFields[$aColumn['value']]);
  711. if (!count($this->fieldsToTables[$fieldName]))
  712. {
  713. unset($this->fields[$fieldName]);
  714. unset($this->dirty[$fieldName]);
  715. unset($this->fieldsToTables[$fieldName]);
  716. }
  717. }
  718. unset($this->tables[$table]);
  719. $start = $this->tableOrder[$table];
  720. $end = count($this->tableOrder);
  721. for ($i=$start;$i<$end-1;$i++)
  722. $this->tableOrder[$i]=$this->tableOrder[$i+1];
  723. unset($this->tableOrder[$i]);
  724.  
  725. }
  726.  
  727. }
  728. ?>

Documentation generated on Tue, 25 Apr 2006 13:11:11 -0400 by phpDocumentor 1.3.0RC3