CRM-15357 fix Event 'delete participant' batch operation can show incorrect count
authorjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Wed, 22 Apr 2015 07:15:56 +0000 (12:45 +0530)
committerjitendrapurohit <jitendra.purohit@webaccessglobal.com>
Wed, 22 Apr 2015 07:15:56 +0000 (12:45 +0530)
CRM/Event/Form/Task/Delete.php

index 467bd75801bbcce93ab75011eac0902c5d59a50e..c69c8a9dabaf768863845602015d1bbfb689e568 100644 (file)
@@ -94,6 +94,7 @@ class CRM_Event_Form_Task_Delete extends CRM_Event_Form_Task {
   public function postProcess() {
     $params = $this->controller->exportValues($this->_name);
 
+    $participantLinks = NULL;
     if (CRM_Utils_Array::value('delete_participant', $params) == 2) {
       $links = array();
       foreach ($this->_participantIds as $participantId) {
@@ -104,15 +105,22 @@ class CRM_Event_Form_Task_Delete extends CRM_Event_Form_Task {
     $deletedParticipants = $additionalCount = 0;
     foreach ($this->_participantIds as $participantId) {
       if (CRM_Utils_Array::value('delete_participant', $params) == 1) {
+        $primaryParticipantId = CRM_Core_DAO::getFieldValue("CRM_Event_DAO_Participant", $participantId, 'registered_by_id', 'id');
         if (CRM_Event_BAO_Participant::isPrimaryParticipant($participantId)) {
           $additionalIds = (CRM_Event_BAO_Participant::getAdditionalParticipantIds($participantId));
-          $additionalCount = count($additionalIds);
+          $additionalCount += count($additionalIds);
           foreach ($additionalIds as $value) {
             CRM_Event_BAO_Participant::deleteParticipant($value);
           }
           CRM_Event_BAO_Participant::deleteParticipant($participantId);
+          $deletedParticipants++;
+        }
+        // delete participant only if it is not an additional participant
+        // or if it is additional and its primary participant is not selected in $this->_participantIds.
+        elseif ($primaryParticipantId == NULL || ($primaryParticipantId != NULL && !CRM_Utils_Array::crmInArray($primaryParticipantId, $this->_participantIds))) {
+          CRM_Event_BAO_Participant::deleteParticipant($participantId);
+          $deletedParticipants++;
         }
-        $deletedParticipants++;
       }
       else {
         CRM_Event_BAO_Participant::deleteParticipant($participantId);