test case using recursion objects
[civicrm-core.git] / CRM / Core / Page / AJAX / RecurringEntity.php
CommitLineData
62933949 1<?php
2
3/*
4 * To change this license header, choose License Headers in Project Properties.
5 * To change this template file, choose Tools | Templates
6 * and open the template in the editor.
7 */
8
9/**
10 * Description of EntityApplyChangesTo
11 *
12 * @author Priyanka
13 */
14
079617dc 15class CRM_Core_Page_AJAX_RecurringEntity {
62933949 16
60b36f60 17 public static function updateMode() {
18 if(CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST)){
62933949 19 $finalResult = array();
60b36f60 20 $mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer');
62933949 21 $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer');
60b36f60 22
62933949 23 $sql = "UPDATE
60b36f60 24 civicrm_recurring_entity
25 SET mode = %1
26 WHERE entity_id = %2 AND entity_table = 'civicrm_event'";
62933949 27 $params = array(
60b36f60 28 1 => array($mode, 'Integer'),
29 2 => array($entityId, 'Integer')
30 );
62933949 31 CRM_Core_DAO::executeQuery($sql, $params);
32 $finalResult['status'] = 'Done';
33 }
34 echo json_encode($finalResult);
35 CRM_Utils_System::civiExit();
36 }
37
38 public static function generatePreview(){
f51acb7a 39 $params = $formValues = $genericResult = array();
62933949 40 $formValues = $_REQUEST;
41 if(!empty($formValues)){
62933949 42 $dbParams = CRM_Core_BAO_RecurringEntity::mapFormValuesToDB($formValues);
43 if(!empty($dbParams)){
44 $recursionObject = CRM_Core_BAO_RecurringEntity::getRecursionFromReminderByDBParams($dbParams);
fd1abec4 45 // Check if there were any errors
46 if($recursionObject->errors){
f51acb7a 47 $genericResult['errors'] = $recursionObject->errors;
fd1abec4 48 }else{
49 if(CRM_Utils_Array::value('event_id', $formValues)){
50 $parent_event_id = CRM_Core_BAO_RecurringEntity::getParentFor($formValues['event_id'], 'civicrm_event');
51 if(!$parent_event_id){
52 $parent_event_id = $formValues['event_id'];
53 }
f51acb7a 54 //Show the list of participants registered for the events if any
55 $getConnectedEntities = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($parent_event_id, 'civicrm_event', FALSE);
56 if($getConnectedEntities){
57 $participantDetails = CRM_Core_BAO_RecurringEntity::getParticipantCountforEvent($getConnectedEntities);
58 if(!empty($participantDetails['countByName'])){
59 $genericResult['participantData'] = $participantDetails['countByName'];
60 }
61 }
d10273dc 62 $startDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $parent_event_id, 'start_date');
63 $endDate = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $parent_event_id, 'end_date');
64
f51acb7a 65 if($endDate) {
d10273dc 66 $params['interval'] = CRM_Core_BAO_RecurringEntity::getInterval($startDate, $endDate);
67 }
ad82cae1 68 $params['start_action_offset'] = $formValues['start_action_offset'];
62933949 69 }
ad82cae1 70 $recurResult = CRM_Core_BAO_RecurringEntity::generateRecursions($recursionObject, $params, $formValues['exclude_date_list']);
fd1abec4 71 $count = 1;
72 foreach ($recurResult as $key => $value) {
f51acb7a 73 $genericResult[$count]['start_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['start_date']));
fd1abec4 74 if($value['end_date']){
f51acb7a 75 $genericResult[$count]['end_date'] = date('M d, Y h:i:s A \o\n l', strtotime($value['end_date']));
fd1abec4 76 }
77 $count++;
62933949 78 }
62933949 79 }
80 }
81 }
f51acb7a 82 echo json_encode($genericResult);
62933949 83 CRM_Utils_System::civiExit();
84 }
85
86}
87