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;
17 function __construct($refTable, $refKey, $targetTable = NULL, $targetKey = 'id', $optionGroupName) {
18 parent
::__construct($refTable, $refKey, $targetTable, $targetKey, NULL);
19 $this->targetOptionGroupName
= $optionGroupName;
22 public function findReferences($targetDao) {
23 if (! ($targetDao instanceof CRM_Core_DAO_OptionValue
)) {
24 throw new CRM_Core_Exception("Mismatched reference: expected OptionValue but received " . get_class($targetDao));
26 if ($targetDao->option_group_id
== $this->getTargetOptionGroupId()) {
27 return parent
::findReferences($targetDao);
33 public function getReferenceCount($targetDao) {
34 if (! ($targetDao instanceof CRM_Core_DAO_OptionValue
)) {
35 throw new CRM_Core_Exception("Mismatched reference: expected OptionValue but received " . get_class($targetDao));
37 if ($targetDao->option_group_id
== $this->getTargetOptionGroupId()) {
38 return parent
::getReferenceCount($targetDao);
44 public function getTargetOptionGroupId() {
45 if ($this->targetOptionGroupId
=== NULL) {
46 $this->targetOptionGroupId
= CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_OptionGroup', $this->targetOptionGroupName
, 'id', 'name');
48 return $this->targetOptionGroupId
;