DBSet.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /** @package verysimple::DB::Reflection */
  3. /**
  4. * DBSet is an object representation of table dependency relationship
  5. *
  6. * @package verysimple::DB::Reflection
  7. * @author Jason Hinkle
  8. * @copyright 1997-2007 VerySimple, Inc.
  9. * @license http://www.gnu.org/licenses/lgpl.html LGPL
  10. * @version 1.0
  11. */
  12. class DBSet
  13. {
  14. public $Table;
  15. public $Name;
  16. public $KeyColumn;
  17. public $KeyComment;
  18. public $SetTableName;
  19. public $SetKeyColumn;
  20. public $SetKeyComment;
  21. public $NameNoPrefix;
  22. public $KeyColumnNoPrefix;
  23. public $SetKeyColumnNoPrefix;
  24. public $SetPrimaryKey;
  25. public $SetPrimaryKeyNoPrefix;
  26. public $GetterName;
  27. /**
  28. * Instantiate new DBSet
  29. *
  30. * @access public
  31. * @param DBTable $table that is the dependent/child table
  32. * @param Array $row array that is result from parsing show create table
  33. */
  34. function __construct($table, $row)
  35. {
  36. $this->Table =& $table->Schema->Tables[$row[2]];
  37. $this->Name = $row[0];
  38. $this->KeyColumn = $row[3];
  39. $this->KeyComment = $this->Table->Columns[$this->KeyColumn]->Comment;
  40. $this->SetTableName = $table->Name;
  41. $this->SetKeyColumn = $row[1];
  42. $this->SetKeyComment = $table->Columns[$this->SetKeyColumn]->Comment;
  43. $reftable = $this->Table->Schema->Tables[$this->SetTableName];
  44. // print "<p><b>" . $this->Table->Name . " set references " . $reftable->Name . "</b></p>";
  45. $this->SetPrimaryKey = $reftable->GetPrimaryKeyName(false);
  46. $this->NameNoPrefix = $this->Table->RemovePrefix($this->Name);
  47. $this->KeyColumnNoPrefix = $this->Table->RemovePrefix($this->KeyColumn);
  48. $this->SetKeyColumnNoPrefix = $reftable->RemovePrefix($this->SetKeyColumn);
  49. $this->SetPrimaryKeyNoPrefix = $reftable->RemovePrefix($this->SetPrimaryKey);
  50. // intelligently decide what a good name for this set would be
  51. $tmp1 = str_replace("__","_",str_replace($this->Table->Name,"", str_replace("_id","", $this->SetKeyColumnNoPrefix)) . "_");
  52. $tmp2 = $this->SetTableName . "s";
  53. $this->GetterName = ($tmp1 == "_") ? $tmp2 : ($tmp1 . $tmp2);
  54. }
  55. }
  56. ?>