From f51acb7a9c8f5b482f6a9d73466e06712c7a3959 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 8 Sep 2014 21:28:00 +0100 Subject: [PATCH] Participant check before recreating repeat configuration --- CRM/Core/BAO/RecurringEntity.php | 23 ++++++++++++++++++++ CRM/Core/Page/AJAX/RecurringEntity.php | 20 +++++++++++------ templates/CRM/Core/Form/RecurringEntity.tpl | 24 +++++++++++++++++++-- 3 files changed, 59 insertions(+), 8 deletions(-) diff --git a/CRM/Core/BAO/RecurringEntity.php b/CRM/Core/BAO/RecurringEntity.php index a0c1111a62..a93f88e7bb 100644 --- a/CRM/Core/BAO/RecurringEntity.php +++ b/CRM/Core/BAO/RecurringEntity.php @@ -484,5 +484,28 @@ class CRM_Core_BAO_RecurringEntity extends CRM_Core_DAO_RecurringEntity { return $dao->delete(); } } + + static public function getParticipantCountforEvent($listOfRelatedEntities = array()){ + if(!empty($listOfRelatedEntities)){ + $implodeRelatedEntities = implode(',', array_map(function($entity){ + return $entity['id']; + }, $listOfRelatedEntities)); + if($implodeRelatedEntities){ + $query = "SELECT p.event_id as event_id, + concat_ws(' ', e.title, concat_ws(' - ', DATE_FORMAT(e.start_date, '%b %d %Y %h:%i %p'), DATE_FORMAT(e.end_date, '%b %d %Y %h:%i %p'))) as event_data, + count(p.id) as participant_count + FROM civicrm_participant p, civicrm_event e + WHERE p.event_id = e.id AND p.event_id IN ({$implodeRelatedEntities}) + GROUP BY p.event_id"; + $dao = CRM_Core_DAO::executeQuery($query); + $participantDetails = array(); + while($dao->fetch()) { + $participantDetails['countByID'][$dao->event_id] = $dao->participant_count; + $participantDetails['countByName'][$dao->event_id][$dao->event_data] = $dao->participant_count; + } + } + } + return $participantDetails; + } } diff --git a/CRM/Core/Page/AJAX/RecurringEntity.php b/CRM/Core/Page/AJAX/RecurringEntity.php index 8b416e4f38..b440475774 100644 --- a/CRM/Core/Page/AJAX/RecurringEntity.php +++ b/CRM/Core/Page/AJAX/RecurringEntity.php @@ -36,7 +36,7 @@ class CRM_Core_Page_AJAX_RecurringEntity { } public static function generatePreview(){ - $params = $formValues = $recurDates = array(); + $params = $formValues = $genericResult = array(); $formValues = $_REQUEST; if(!empty($formValues)){ $dbParams = CRM_Core_BAO_RecurringEntity::mapFormValuesToDB($formValues); @@ -44,17 +44,25 @@ class CRM_Core_Page_AJAX_RecurringEntity { $recursionObject = CRM_Core_BAO_RecurringEntity::getRecursionFromReminderByDBParams($dbParams); // Check if there were any errors if($recursionObject->errors){ - $recurDates['errors'] = $recursionObject->errors; + $genericResult['errors'] = $recursionObject->errors; }else{ if(CRM_Utils_Array::value('event_id', $formValues)){ $parent_event_id = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['event_id'], 'civicrm_event'); if(!$parent_event_id){ $parent_event_id = $formValues['event_id']; } + //Show the list of participants registered for the events if any + $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parent_event_id, 'civicrm_event', FALSE); + if($getConnectedEntities){ + $participantDetails = CRM_Core_BAO_RecurringEntity::getParticipantCountforEvent($getConnectedEntities); + if(!empty($participantDetails['countByName'])){ + $genericResult['participantData'] = $participantDetails['countByName']; + } + } $startDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $parent_event_id, 'start_date'); $endDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $parent_event_id, 'end_date'); - if ($endDate) { + if($endDate) { $params['interval'] = CRM_Core_BAO_RecurringEntity::getInterval($startDate, $endDate); } $params['start_action_offset'] = $formValues['start_action_offset']; @@ -62,16 +70,16 @@ class CRM_Core_Page_AJAX_RecurringEntity { $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params, $formValues['exclude_date_list']); $count = 1; foreach ($recurResult as $key => $value) { - $recurDates[$count]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['start_date'])); + $genericResult[$count]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['start_date'])); if($value['end_date']){ - $recurDates[$count]['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['end_date'])); + $genericResult[$count]['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['end_date'])); } $count++; } } } } - echo json_encode($recurDates); + echo json_encode($genericResult); CRM_Utils_System::civiExit(); } diff --git a/templates/CRM/Core/Form/RecurringEntity.tpl b/templates/CRM/Core/Form/RecurringEntity.tpl index 0dd002b716..97703c1fdc 100644 --- a/templates/CRM/Core/Form/RecurringEntity.tpl +++ b/templates/CRM/Core/Form/RecurringEntity.tpl @@ -254,7 +254,7 @@ cj('#preview-dialog').dialog('open'); cj('#preview-dialog').dialog({ title: 'Confirm event dates', - width: '600', + width: '650', position: 'center', //draggable: false, buttons: { @@ -280,10 +280,15 @@ url: ajaxurl, success: function (result) { var errors = []; + var participantData = []; var html = 'Based on your repeat configuration here is the list of event dates, Do you wish to proceed creating events for these dates?
'; var count = 1; for(var i in result) { if(i != 'errors'){ + if(i == 'participantData'){ + participantData = result.participantData; + break; + } var start_date = result[i].start_date; var end_date = result[i].end_date; @@ -298,13 +303,28 @@ } } html += '
Sr NoStart dateEnd date
'; + var warningHtml = ''; + if(Object.keys(participantData).length > 0){ + warningHtml += '
 There are registrations for the repeating events already present in the set, continuing with the process would unlink them and repeating events without registration would be trashed.
'; + for (var id in participantData) { + for(var data in participantData[id]){ + warningHtml += ''; + } + } + warningHtml += '
Event IDEventParticipant Count
'+id+' '+data+''+participantData[id][data]+'

'; + } if(errors.length > 0){ html = ''; for (var j = 0; j < errors.length; j++) { html += '* ' + errors[j] + '
'; } } - cj('#generated_dates').html(html); + if(warningHtml != ""){ + cj('button span.ui-button-text:contains("Ok")').hide(); + cj('#generated_dates').append(warningHtml).append(html); + }else{ + cj('#generated_dates').html(html); + } if(end_date_text == ""){ cj('#th-end-date').hide(); } -- 2.25.1