Merge pull request #11150 from civicrm/4.7.27-rc
[civicrm-core.git] / CRM / Core / Page / AJAX / RecurringEntity.php
CommitLineData
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
13class CRM_Core_Page_AJAX_RecurringEntity {
14
15 public static function updateMode() {
3c7bb1b1 16 $finalResult = array();
2aa397bc
TO
17 if (CRM_Utils_Array::value('mode', $_REQUEST) && CRM_Utils_Array::value('entityId', $_REQUEST) && CRM_Utils_Array::value('entityTable', $_REQUEST)) {
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');
22
b53cbfbc 23 if (!empty($_REQUEST['linkedEntityTable'])) {
2aa397bc
TO
24 $result = CRM_Core_BAO_RecurringEntity::updateModeLinkedEntity($entityId, $_REQUEST['linkedEntityTable'], $entityTable);
25 }
26
27 $dao = new CRM_Core_DAO_RecurringEntity();
28 if (!empty($result)) {
29 $dao->entity_id = $result['entityId'];
30 $dao->entity_table = $result['entityTable'];
31 }
32 else {
33 $dao->entity_id = $entityId;
34 $dao->entity_table = $entityTable;
35 }
36
37 if ($dao->find(TRUE)) {
38 $dao->mode = $mode;
39 $dao->save();
40 $finalResult['status'] = 'Done';
41 }
42 else {
43 $finalResult['status'] = 'Error';
44 }
45 }
3c7bb1b1 46 CRM_Utils_JSON::output($finalResult);
2aa397bc 47 }
96025800 48
2aa397bc 49}