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;
18 * @param null $targetTable
19 * @param string $targetKey
20 * @param null $refTypeColumn
22 function __construct($refTable, $refKey, $targetTable = NULL, $targetKey = 'id', $refTypeColumn = NULL) {
23 $this->refTable
= $refTable;
24 $this->refKey
= $refKey;
25 $this->targetTable
= $targetTable;
26 $this->targetKey
= $targetKey;
27 $this->refTypeColumn
= $refTypeColumn;
33 function getReferenceTable() {
34 return $this->refTable
;
40 function getReferenceKey() {
47 function getTypeColumn() {
48 return $this->refTypeColumn
;
54 function getTargetTable() {
55 return $this->targetTable
;
61 function getTargetKey() {
62 return $this->targetKey
;
66 * @param string $tableName
70 public function matchesTargetTable($tableName) {
71 return ($this->getTargetTable() === $tableName);
75 * @param CRM_Core_DAO $targetDao
79 public function findReferences($targetDao) {
80 $targetColumn = $this->getTargetKey();
82 1 => array($targetDao->$targetColumn, 'String')
86 FROM {$this->getReferenceTable()}
87 WHERE {$this->getReferenceKey()} = %1
90 $daoName = CRM_Core_DAO_AllCoreTables
::getClassForTable($this->getReferenceTable());
91 $result = CRM_Core_DAO
::executeQuery($sql, $params, TRUE, $daoName);
96 * @param CRM_Core_DAO $targetDao
100 public function getReferenceCount($targetDao) {
101 $targetColumn = $this->getTargetKey();
103 1 => array($targetDao->$targetColumn, 'String')
107 FROM {$this->getReferenceTable()}
108 WHERE {$this->getReferenceKey()} = %1
112 'name' => implode(':', array('sql', $this->getReferenceTable(), $this->getReferenceKey())),
113 'type' => get_class($this),
114 'table' => $this->getReferenceTable(),
115 'key' => $this->getReferenceKey(),
116 'count' => CRM_Core_DAO
::singleValueQuery($sql, $params)