Commit | Line | Data |
---|---|---|
2aa397bc | 1 | <?php |
2aa397bc TO |
2 | /* |
3 | * To change this license header, choose License Headers in Project Properties. | |
4 | * To change this template file, choose Tools | Templates | |
5 | * and open the template in the editor. | |
6 | */ | |
7 | ||
8 | /** | |
9 | * Description of EntityApplyChangesTo | |
10 | * | |
11 | * @author Priyanka | |
12 | */ | |
2aa397bc TO |
13 | class CRM_Core_Page_AJAX_RecurringEntity { |
14 | ||
15 | public static function updateMode() { | |
3c7bb1b1 | 16 | $finalResult = array(); |
a1bfea17 | 17 | if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST) && CRM_Utils_Array::value('priceSet', $_REQUEST)) { |
2aa397bc | 18 | |
2aa397bc TO |
19 | $mode = CRM_Utils_Type::escape($_REQUEST['mode'], 'Integer'); |
20 | $entityId = CRM_Utils_Type::escape($_REQUEST['entityId'], 'Integer'); | |
21 | $entityTable = CRM_Utils_Type::escape($_REQUEST['entityTable'], 'String'); | |
a1bfea17 | 22 | $priceSet = CRM_Utils_Type::escape($_REQUEST['priceSet'], 'String'); |
2aa397bc | 23 | |
b53cbfbc | 24 | if (!empty($_REQUEST['linkedEntityTable'])) { |
2aa397bc TO |
25 | $result = CRM_Core_BAO_RecurringEntity::updateModeLinkedEntity($entityId, $_REQUEST['linkedEntityTable'], $entityTable); |
26 | } | |
27 | ||
28 | $dao = new CRM_Core_DAO_RecurringEntity(); | |
29 | if (!empty($result)) { | |
30 | $dao->entity_id = $result['entityId']; | |
31 | $dao->entity_table = $result['entityTable']; | |
32 | } | |
33 | else { | |
34 | $dao->entity_id = $entityId; | |
35 | $dao->entity_table = $entityTable; | |
36 | } | |
37 | ||
38 | if ($dao->find(TRUE)) { | |
39 | $dao->mode = $mode; | |
40 | $dao->save(); | |
b0f2e06f RJ |
41 | |
42 | //CRM-20787 Fix | |
43 | //I am not sure about other fields, if mode = 3 apply for an event then other fields | |
44 | //should be save for all other series events or not so applying for price set only for now here. | |
45 | if (CRM_Core_BAO_RecurringEntity::MODE_ALL_ENTITY_IN_SERIES === $mode) { | |
b0f2e06f | 46 | |
a1bfea17 AP |
47 | //Step-1: Get all events of series |
48 | $seriesEventRecords = CRM_Core_BAO_RecurringEntity::getEntitiesFor($entityId, $entityTable); | |
49 | foreach ($seriesEventRecords as $event) { | |
50 | //Step-3: Save price set in other series events | |
51 | if (CRM_Price_BAO_PriceSet::removeFrom($event['table'], $event['id'])) {//Remove existing priceset | |
52 | CRM_Core_BAO_Discount::del($event['id'], $event['table']); | |
53 | CRM_Price_BAO_PriceSet::addTo($event['table'], $event['id'], $priceSet); //Add new price set | |
b0f2e06f | 54 | } |
a1bfea17 | 55 | } |
b0f2e06f RJ |
56 | } |
57 | //CRM-20787 - Fix end | |
2aa397bc TO |
58 | $finalResult['status'] = 'Done'; |
59 | } | |
60 | else { | |
61 | $finalResult['status'] = 'Error'; | |
62 | } | |
63 | } | |
3c7bb1b1 | 64 | CRM_Utils_JSON::output($finalResult); |
2aa397bc | 65 | } |
96025800 | 66 | |
2aa397bc | 67 | } |