From 8b21f46560ab80c94bf73d4333439828c27ebf52 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Wed, 26 Feb 2014 00:34:01 +1300 Subject: [PATCH] CRM-14269 correctly set default role id when event id is passed, note that this also adds support for roles to be passed in the url - taking precedence" --- CRM/Event/Form/Participant.php | 39 ++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 802ff8a3df..84952ad38a 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -532,10 +532,7 @@ SELECT civicrm_custom_group.name as name, CRM_Event_BAO_Participant::getValues($params, $defaults, $ids); $sep = CRM_Core_DAO::VALUE_SEPARATOR; if ($defaults[$this->_id]['role_id']) { - foreach (explode($sep, $defaults[$this->_id]['role_id']) as $k => $v) { - $defaults[$this->_id]["role_id[{$v}]"] = 1; - } - unset($defaults[$this->_id]['role_id']); + $roleIDs = explode($sep, $defaults[$this->_id]['role_id']); } $this->_contactId = $defaults[$this->_id]['contact_id']; $this->_statusId = $defaults[$this->_id]['participant_status_id']; @@ -638,14 +635,38 @@ SELECT civicrm_custom_group.name as name, if (CRM_Utils_Array::value('participant_role_id', $defaults[$this->_id])) { $roleIDs = explode($sep, $defaults[$this->_id]['participant_role_id']); } - if (isset($roleIDs)) { - $this->assign('roleID', $roleIDs); - } + if (isset($_POST['event_id'])) { $eventID = $_POST['event_id']; - if ($eventID) { - $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id'); + } + + if($this->_eID) { + $eventID = $this->_eID; + //@todo - rationalise the $this->_eID with $POST['event_id'], $this->_eid is set when eid=x is in the url + $roleID = CRM_Core_DAO::getFieldValue( + 'CRM_Event_DAO_Event', + $this->_eID, + 'default_role_id' + ); + if(empty($roleIDs)) { + $roleIDs = (array) $defaults[$this->_id]['participant_role_id'] = $roleID; + } + $defaults[$this->_id]['event_id'] = $eventID; + } + if ($eventID) { + $this->_eventTypeId = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $eventID, 'event_type_id', 'id'); + } + //these should take precedence so we state them last + $urlRoleIDS = CRM_Utils_Request::retrieve('roles', 'String'); + if($urlRoleIDS) { + $roleIDs = explode(',', $urlRoleIDS); + } + if (isset($roleIDs)) { + foreach ($roleIDs as $roleID) { + $defaults[$this->_id]["role_id[{$roleID}]"] = 1; } + unset($defaults[$this->_id]['role_id']); + $this->assign('roleID', $roleIDs); } if (isset($eventID)) { -- 2.25.1