4 * Description of a one-way link between an option-value and an entity
6 class CRM_Core_Reference_OptionValue
extends CRM_Core_Reference_Basic
{
12 protected $targetOptionGroupName;
15 * Target Option Group ID.
19 protected $targetOptionGroupId;
24 * @param null $targetTable
25 * @param string $targetKey
26 * @param null $optionGroupName
28 public function __construct($refTable, $refKey, $targetTable, $targetKey, $optionGroupName) {
29 parent
::__construct($refTable, $refKey, $targetTable, $targetKey, NULL);
30 $this->targetOptionGroupName
= $optionGroupName;
34 * @param CRM_Core_DAO $targetDao
37 * @throws CRM_Core_Exception
39 public function findReferences($targetDao) {
40 if (!($targetDao instanceof CRM_Core_DAO_OptionValue
)) {
41 throw new CRM_Core_Exception("Mismatched reference: expected OptionValue but received " . get_class($targetDao));
43 if ($targetDao->option_group_id
== $this->getTargetOptionGroupId()) {
44 return parent
::findReferences($targetDao);
52 * Get Reference Count.
54 * @param CRM_Core_DAO $targetDao
57 * @throws CRM_Core_Exception
59 public function getReferenceCount($targetDao) {
60 if (!($targetDao instanceof CRM_Core_DAO_OptionValue
)) {
61 throw new CRM_Core_Exception("Mismatched reference: expected OptionValue but received " . get_class($targetDao));
63 if ($targetDao->option_group_id
== $this->getTargetOptionGroupId()) {
64 return parent
::getReferenceCount($targetDao);
72 * Get target option group ID.
76 public function getTargetOptionGroupId() {
77 if ($this->targetOptionGroupId
=== NULL) {
78 $this->targetOptionGroupId
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->targetOptionGroupName
, 'id', 'name');
80 return $this->targetOptionGroupId
;