4 * Description of a one-way link between two entities
6 * This is a generic, soft-foreign key based on a pair of columns (entity_id, entity_table).
8 class CRM_Core_Reference_Dynamic
extends CRM_Core_Reference_Basic
{
11 * @param string $tableName
15 public function matchesTargetTable($tableName) {
20 * Create a query to find references to a particular record.
22 * @param CRM_Core_DAO $targetDao
23 * The instance for which we want references.
24 * @return CRM_Core_DAO
25 * a query-handle (like the result of CRM_Core_DAO::executeQuery)
27 public function findReferences($targetDao) {
28 $refColumn = $this->getReferenceKey();
29 $targetColumn = $this->getTargetKey();
32 1 => [$targetDao->$targetColumn, 'String'],
33 // If anyone complains about $targetDao::getTableName(), then could use
34 // "{get_class($targetDao)}::getTableName();"
35 2 => [$targetDao::getTableName(), 'String'],
40 FROM {$this->getReferenceTable()}
41 WHERE {$refColumn} = %1
42 AND {$this->getTypeColumn()} = %2
45 $daoName = CRM_Core_DAO_AllCoreTables
::getClassForTable($this->getReferenceTable());
46 $result = CRM_Core_DAO
::executeQuery($sql, $params, TRUE, $daoName);
51 * @param CRM_Core_DAO $targetDao
55 public function getReferenceCount($targetDao) {
56 $targetColumn = $this->getTargetKey();
58 1 => [$targetDao->$targetColumn, 'String'],
59 // If anyone complains about $targetDao::getTableName(), then could use
60 // "{get_class($targetDao)}::getTableName();"
61 2 => [$targetDao::getTableName(), 'String'],
66 FROM {$this->getReferenceTable()}
67 WHERE {$this->getReferenceKey()} = %1
68 AND {$this->getTypeColumn()} = %2
72 'name' => implode(':', ['sql', $this->getReferenceTable(), $this->getReferenceKey()]),
73 'type' => get_class($this),
74 'table' => $this->getReferenceTable(),
75 'key' => $this->getReferenceKey(),
76 'count' => CRM_Core_DAO
::singleValueQuery($sql, $params),