New onsite patient portal, take 4.
[openemr.git] / portal / patient / fwk / libs / verysimple / DB / Reflection / DBConstraint.php
blob8d65f6fd3e6046e23f9a29eb3c93285ef01312e7
1 <?php
2 /** @package verysimple::DB::Reflection */
4 /**
5 * DBSet is an object representation of foreign key constraint
7 * @package verysimple::DB::Reflection
8 * @author Jason Hinkle
9 * @copyright 1997-2007 VerySimple, Inc.
10 * @license http://www.gnu.org/licenses/lgpl.html LGPL
11 * @version 1.0
13 class DBConstraint {
14 public $Table;
15 public $Name;
16 public $KeyColumn;
17 public $ReferenceTable;
18 public $ReferenceTableName;
19 public $ReferenceKeyColumn;
20 public $NameNoPrefix;
21 public $KeyColumnNoPrefix;
22 public $ReferenceKeyColumnNoPrefix;
23 public $GetterName;
25 /**
26 * Instantiate new DBConstraint
28 * @access public
29 * @param DBTable $table
30 * that is the dependent/child table
31 * @param Array $row
32 * array that is result from parsing show create table
34 function __construct($table, $row) {
35 $this->Table = & $table;
37 $this->Name = $row [0];
38 $this->KeyColumn = $row [1];
39 $this->ReferenceTableName = $row [2];
40 $this->ReferenceKeyColumn = $row [3];
42 $this->ReferenceTable = $this->Table->Schema->Tables [$this->ReferenceTableName];
43 // print "<p><b>" . $this->Table->Name . " constraint references " . $reftable->Name . "</b></p>";
45 $this->NameNoPrefix = $this->Table->RemovePrefix ( $this->Name );
46 $this->KeyColumnNoPrefix = $this->Table->RemovePrefix ( $this->KeyColumn );
47 $this->ReferenceKeyColumnNoPrefix = $this->ReferenceTable->RemovePrefix ( $this->ReferenceKeyColumn );
49 // intelligently decide what a good name for this constraint might be
50 $tmp1 = str_replace ( "__", "_", str_replace ( $this->ReferenceTableName, "", str_replace ( "_id", "", $this->KeyColumnNoPrefix ) ) . "_" );
51 $tmp2 = $this->ReferenceTableName;
52 $this->GetterName = ($tmp1 == "_") ? $tmp2 : ($tmp1 . $tmp2);