dev/financial#131 Remove last places where Core Processors return error object
[civicrm-core.git] / CRM / Core / Reference / OptionValue.php
CommitLineData
ffcef054
TO
1<?php
2
3/**
4 * Description of a one-way link between an option-value and an entity
5 */
6class CRM_Core_Reference_OptionValue extends CRM_Core_Reference_Basic {
7 /**
9d451db8 8 * Option group name.
9 *
10 * @var string
ffcef054
TO
11 */
12 protected $targetOptionGroupName;
13
14 /**
e97c66ff 15 * Target Option Group ID.
16 *
17 * @var int|null
ffcef054
TO
18 */
19 protected $targetOptionGroupId;
20
a0ee3941
EM
21 /**
22 * @param $refTable
23 * @param $refKey
24 * @param null $targetTable
25 * @param string $targetKey
26 * @param null $optionGroupName
27 */
00be9182 28 public function __construct($refTable, $refKey, $targetTable = NULL, $targetKey = 'id', $optionGroupName) {
ffcef054
TO
29 parent::__construct($refTable, $refKey, $targetTable, $targetKey, NULL);
30 $this->targetOptionGroupName = $optionGroupName;
31 }
32
a0ee3941
EM
33 /**
34 * @param CRM_Core_DAO $targetDao
35 *
36 * @return null|Object
37 * @throws CRM_Core_Exception
38 */
ffcef054 39 public function findReferences($targetDao) {
353ffa53 40 if (!($targetDao instanceof CRM_Core_DAO_OptionValue)) {
ffcef054
TO
41 throw new CRM_Core_Exception("Mismatched reference: expected OptionValue but received " . get_class($targetDao));
42 }
43 if ($targetDao->option_group_id == $this->getTargetOptionGroupId()) {
44 return parent::findReferences($targetDao);
0db6c3e1
TO
45 }
46 else {
ffcef054
TO
47 return NULL;
48 }
49 }
50
a0ee3941 51 /**
e97c66ff 52 * Get Reference Count.
53 *
a0ee3941
EM
54 * @param CRM_Core_DAO $targetDao
55 *
56 * @return array|null
57 * @throws CRM_Core_Exception
58 */
1256c139 59 public function getReferenceCount($targetDao) {
353ffa53 60 if (!($targetDao instanceof CRM_Core_DAO_OptionValue)) {
1256c139
TO
61 throw new CRM_Core_Exception("Mismatched reference: expected OptionValue but received " . get_class($targetDao));
62 }
63 if ($targetDao->option_group_id == $this->getTargetOptionGroupId()) {
64 return parent::getReferenceCount($targetDao);
0db6c3e1
TO
65 }
66 else {
1256c139
TO
67 return NULL;
68 }
69 }
70
a0ee3941 71 /**
e97c66ff 72 * Get target option group ID.
73 *
74 * @return int
a0ee3941 75 */
ffcef054
TO
76 public function getTargetOptionGroupId() {
77 if ($this->targetOptionGroupId === NULL) {
78 $this->targetOptionGroupId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $this->targetOptionGroupName, 'id', 'name');
79 }
80 return $this->targetOptionGroupId;
81 }
96025800 82
a0ee3941 83}