4 * Description of a one-way link between two entities
6 * This is a basic SQL foreign key.
8 class CRM_Core_Reference_Basic
implements CRM_Core_Reference_Interface
{
11 protected $refTypeColumn;
12 protected $targetTable;
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;
23 function getReferenceTable() {
24 return $this->refTable
;
27 function getReferenceKey() {
31 function getTypeColumn() {
32 return $this->refTypeColumn
;
35 function getTargetTable() {
36 return $this->targetTable
;
39 function getTargetKey() {
40 return $this->targetKey
;
43 public function matchesTargetTable($tableName) {
44 return ($this->getTargetTable() === $tableName);
47 public function findReferences($targetDao) {
48 $targetColumn = $this->getTargetKey();
50 1 => array($targetDao->$targetColumn, 'String')
54 FROM {$this->getReferenceTable()}
55 WHERE {$this->getReferenceKey()} = %1
58 $daoName = CRM_Core_DAO_AllCoreTables
::getClassForTable($this->getReferenceTable());
59 $result = CRM_Core_DAO
::executeQuery($sql, $params, TRUE, $daoName);
63 public function getReferenceCount($targetDao) {
64 $targetColumn = $this->getTargetKey();
66 1 => array($targetDao->$targetColumn, 'String')
70 FROM {$this->getReferenceTable()}
71 WHERE {$this->getReferenceKey()} = %1
75 'name' => implode(':', array('sql', $this->getReferenceTable(), $this->getReferenceKey())),
76 'type' => get_class($this),
77 'table' => $this->getReferenceTable(),
78 'key' => $this->getReferenceKey(),
79 'count' => CRM_Core_DAO
::singleValueQuery($sql, $params)