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
{
8 * @var string option-group-name
10 protected $targetOptionGroupName;
13 * @var int|NULL null if not yet loaded
15 protected $targetOptionGroupId;
20 * @param null $targetTable
21 * @param string $targetKey
22 * @param null $optionGroupName
24 public function __construct($refTable, $refKey, $targetTable = NULL, $targetKey = 'id', $optionGroupName) {
25 parent
::__construct($refTable, $refKey, $targetTable, $targetKey, NULL);
26 $this->targetOptionGroupName
= $optionGroupName;
30 * @param CRM_Core_DAO $targetDao
33 * @throws CRM_Core_Exception
35 public function findReferences($targetDao) {
36 if (! ($targetDao instanceof CRM_Core_DAO_OptionValue
)) {
37 throw new CRM_Core_Exception("Mismatched reference: expected OptionValue but received " . get_class($targetDao));
39 if ($targetDao->option_group_id
== $this->getTargetOptionGroupId()) {
40 return parent
::findReferences($targetDao);
48 * @param CRM_Core_DAO $targetDao
51 * @throws CRM_Core_Exception
53 public function getReferenceCount($targetDao) {
54 if (! ($targetDao instanceof CRM_Core_DAO_OptionValue
)) {
55 throw new CRM_Core_Exception("Mismatched reference: expected OptionValue but received " . get_class($targetDao));
57 if ($targetDao->option_group_id
== $this->getTargetOptionGroupId()) {
58 return parent
::getReferenceCount($targetDao);
68 public function getTargetOptionGroupId() {
69 if ($this->targetOptionGroupId
=== NULL) {
70 $this->targetOptionGroupId
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->targetOptionGroupName
, 'id', 'name');
72 return $this->targetOptionGroupId
;