];
}
- $activityParams['assignee_contact_id'] = $this->getDefaultAssigneeForActivity($activityParams, $activityTypeXML);
+ $activityParams['assignee_contact_id'] = $this->getDefaultAssigneeForActivity($activityParams, $activityTypeXML, $params['caseID']);
//parsing date to default preference format
$params['activity_date_time'] = CRM_Utils_Date::processDate($params['activity_date_time']);
*
* @param array $activityParams
* @param object $activityTypeXML
+ * @param int $caseId
*
* @return int|null the ID of the default assignee contact or null if none.
*/
- protected function getDefaultAssigneeForActivity($activityParams, $activityTypeXML) {
+ protected function getDefaultAssigneeForActivity($activityParams, $activityTypeXML, $caseId) {
if (!isset($activityTypeXML->default_assignee_type)) {
return NULL;
}
switch ($activityTypeXML->default_assignee_type) {
case $defaultAssigneeOptionsValues['BY_RELATIONSHIP']:
- return $this->getDefaultAssigneeByRelationship($activityParams, $activityTypeXML);
+ return $this->getDefaultAssigneeByRelationship($activityParams, $activityTypeXML, $caseId);
break;
case $defaultAssigneeOptionsValues['SPECIFIC_CONTACT']:
*
* @param array $activityParams
* @param object $activityTypeXML
+ * @param int $caseId
*
* @return int|null the ID of the default assignee contact or null if none.
*/
- protected function getDefaultAssigneeByRelationship($activityParams, $activityTypeXML) {
+ protected function getDefaultAssigneeByRelationship($activityParams, $activityTypeXML, $caseId) {
$isDefaultRelationshipDefined = isset($activityTypeXML->default_assignee_relationship)
&& preg_match('/\d+_[ab]_[ab]/', $activityTypeXML->default_assignee_relationship);
'relationship_type_id' => $relTypeId,
"contact_id_$b" => $targetContactId,
'is_active' => 1,
+ 'case_id' => $caseId,
+ 'options' => ['limit' => 1],
];
if ($this->isBidirectionalRelationshipType($relTypeId)) {
}
$relationships = civicrm_api3('Relationship', 'get', $params);
+ if (empty($relationships['count'])) {
+ $params['case_id'] = ['IS NULL' => 1];
+ $relationships = civicrm_api3('Relationship', 'get', $params);
+ }
if ($relationships['count']) {
$relationship = CRM_Utils_Array::first($relationships['values']);