Check participant before deleting events
authorunknown <priyanka.karan26@gmail.com>
Mon, 8 Sep 2014 00:03:18 +0000 (01:03 +0100)
committerdeepak-srivastava <deepak.srivastava.0303@gmail.com>
Fri, 3 Oct 2014 08:55:17 +0000 (09:55 +0100)
CRM/Core/Form/RecurringEntity.php

index d57e35497b1ea7befdf51fbd866d75ca26addb9b..04096d2a4198f7d227ceba73390db6b43fe3b0e9 100644 (file)
@@ -263,6 +263,27 @@ class CRM_Core_Form_RecurringEntity {
     
     //Delete relations if any from recurring entity tables before inserting new relations for this entity id
     if($params['parent_event_id']){
+      $getRelatedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($params['parent_event_id'], 'civicrm_event', FALSE);
+      $implodeRelatedEntities = implode(',', array_map(function($entity){
+                                  return $entity['id'];
+                                }, $getRelatedEntities));
+      //Check if participants exists for events
+      if($implodeRelatedEntities){
+        $query = "SELECT event_id, COUNT(*) as count
+                  FROM civicrm_participant 
+                  WHERE event_id IN ({$implodeRelatedEntities})
+                  GROUP BY event_id";
+        $dao = CRM_Core_DAO::executeQuery($query);
+        $participantDetails = array();
+        while($dao->fetch()) {
+          $participantDetails[$dao->event_id] = $dao->count;
+        }
+      }
+      foreach ($getRelatedEntities as $key => $value) {
+        if(!CRM_Utils_Array::value($value['id'], $participantDetails)){
+          CRM_Event_BAO_Event::del($value['id']);
+        }
+      }
       CRM_Core_BAO_RecurringEntity::delEntityRelations($params['parent_event_id'], 'civicrm_event');
     }