Commit f30954e1e842283a8e49435c39bb6f16731717ab
1 parent
38cd7e24
Add getByLookupAndParentBehaviour, which finds the value instance with
specified lookup value reached by the specified behaviour. git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@3793 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
19 additions
and
1 deletions
lib/metadata/valueinstance.inc.php
| ... | ... | @@ -84,11 +84,29 @@ class KTValueInstance extends KTEntity { |
| 84 | 84 | return KTEntityUtil::getBy('KTValueInstance', 'field_value_id', $iLookupId, $aOptions); |
| 85 | 85 | } |
| 86 | 86 | |
| 87 | - function &getByLookup($oLookup, $aOptions) { | |
| 87 | + function &getByLookup($oLookup) { | |
| 88 | 88 | $aOptions = array('multi' => true); |
| 89 | 89 | $iLookupId = KTUtil::getId($oLookup); |
| 90 | 90 | return KTEntityUtil::getBy('KTValueInstance', 'field_value_id', $iLookupId, $aOptions); |
| 91 | 91 | } |
| 92 | + | |
| 93 | + function &getByLookupAndParentBehaviour($oLookup, $oBehaviour, $aOptions = null) { | |
| 94 | + $iLookupId = KTUtil::getId($oLookup); | |
| 95 | + $iBehaviourId = KTUtil::getId($oBehaviour); | |
| 96 | + $sInstanceTable = KTUtil::getTableName('field_value_instances'); | |
| 97 | + $sBehaviourOptionsTable = KTUtil::getTableName('field_behaviour_options'); | |
| 98 | + $aQuery = array( | |
| 99 | + "SELECT instance_id FROM $sBehaviourOptionsTable AS BO INNER JOIN | |
| 100 | + $sInstanceTable AS I ON BO.instance_id = I.id WHERE | |
| 101 | + BO.behaviour_id = ? AND I.field_value_id = ?", | |
| 102 | + array($iBehaviourId, $iLookupId), | |
| 103 | + ); | |
| 104 | + $iId = DBUtil::getOneResultKey($aQuery, 'instance_id'); | |
| 105 | + if (KTUtil::arrayGet($aOptions, 'ids')) { | |
| 106 | + return $iId; | |
| 107 | + } | |
| 108 | + return KTValueInstance::get($iId); | |
| 109 | + } | |
| 92 | 110 | } |
| 93 | 111 | |
| 94 | 112 | ?> | ... | ... |