Commit | Line | Data |
---|---|---|
71e5aa5c ARW |
1 | <?php |
2 | ||
3 | /** | |
4 | * Description of a one-way link between two entities | |
5 | * | |
11626cf1 | 6 | * This is a basic SQL foreign key. |
71e5aa5c | 7 | */ |
11626cf1 | 8 | class CRM_Core_Reference_Basic implements CRM_Core_Reference_Interface { |
71e5aa5c ARW |
9 | protected $refTable; |
10 | protected $refKey; | |
11 | protected $refTypeColumn; | |
12 | protected $targetTable; | |
13 | protected $targetKey; | |
14 | ||
15 | function __construct($refTable, $refKey, $targetTable = NULL, $targetKey = 'id', $refTypeColumn = NULL) { | |
16 | $this->refTable = $refTable; | |
17 | $this->refKey = $refKey; | |
18 | $this->targetTable = $targetTable; | |
19 | $this->targetKey = $targetKey; | |
20 | $this->refTypeColumn = $refTypeColumn; | |
21 | } | |
22 | ||
23 | function getReferenceTable() { | |
24 | return $this->refTable; | |
25 | } | |
26 | ||
27 | function getReferenceKey() { | |
28 | return $this->refKey; | |
29 | } | |
30 | ||
31 | function getTypeColumn() { | |
32 | return $this->refTypeColumn; | |
33 | } | |
34 | ||
35 | function getTargetTable() { | |
36 | return $this->targetTable; | |
37 | } | |
38 | ||
39 | function getTargetKey() { | |
40 | return $this->targetKey; | |
41 | } | |
42 | ||
11626cf1 TO |
43 | public function matchesTargetTable($tableName) { |
44 | return ($this->getTargetTable() === $tableName); | |
71e5aa5c | 45 | } |
de49f39c | 46 | |
de49f39c | 47 | public function findReferences($targetDao) { |
de49f39c | 48 | $targetColumn = $this->getTargetKey(); |
11626cf1 TO |
49 | $params = array( |
50 | 1 => array($targetDao->$targetColumn, 'String') | |
51 | ); | |
de49f39c TO |
52 | $sql = <<<EOS |
53 | SELECT id | |
54 | FROM {$this->getReferenceTable()} | |
11626cf1 | 55 | WHERE {$this->getReferenceKey()} = %1 |
de49f39c | 56 | EOS; |
11626cf1 | 57 | |
de49f39c TO |
58 | $daoName = CRM_Core_DAO_AllCoreTables::getClassForTable($this->getReferenceTable()); |
59 | $result = CRM_Core_DAO::executeQuery($sql, $params, TRUE, $daoName); | |
60 | return $result; | |
61 | } | |
71e5aa5c | 62 | } |