Merge pull request #15933 from civicrm/5.20
[civicrm-core.git] / CRM / Batch / Page / AJAX.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
bc77d7c0 4 | Copyright CiviCRM LLC. All rights reserved. |
6a488035 5 | |
bc77d7c0
TO
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
6a488035
TO
9 +--------------------------------------------------------------------+
10 */
11
12/**
13 *
14 * @package CRM
ca5cec67 15 * @copyright CiviCRM LLC https://civicrm.org/licensing
6a488035
TO
16 */
17
18/**
3819f101 19 * This class contains functions that are called using AJAX.
6a488035
TO
20 */
21class CRM_Batch_Page_AJAX {
22
23 /**
eceb18cc 24 * Save record.
6a488035 25 */
00be9182 26 public function batchSave() {
6c97864e 27 // save the entered information in 'data' column
6a488035
TO
28 $batchId = CRM_Utils_Type::escape($_POST['batch_id'], 'Positive');
29
6a488035 30 unset($_POST['qfKey']);
be2fb01f 31 CRM_Core_DAO::setFieldValue('CRM_Batch_DAO_Batch', $batchId, 'data', json_encode(['values' => $_POST]));
6a488035 32
6a488035
TO
33 CRM_Utils_System::civiExit();
34 }
35
36 /**
9d311c8f
CW
37 * This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
38 * @deprecated
6a488035 39 */
00be9182 40 public static function getBatchList() {
edc80cda 41 $context = CRM_Utils_Request::retrieve('context', 'Alphanumeric');
6209e779 42 if ($context != 'financialBatch') {
be2fb01f 43 $sortMapper = [
6209e779
PN
44 0 => 'title',
45 1 => 'type_id.label',
46 2 => 'item_count',
47 3 => 'total',
48 4 => 'status_id.label',
49 5 => 'created_id.sort_name',
be2fb01f 50 ];
6209e779
PN
51 }
52 else {
be2fb01f 53 $sortMapper = [
6209e779
PN
54 1 => 'title',
55 2 => 'payment_instrument_id.label',
56 3 => 'item_count',
57 4 => 'total',
58 5 => 'status_id.label',
59 6 => 'created_id.sort_name',
be2fb01f 60 ];
6209e779 61 }
353ffa53 62 $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer');
408b79bf 63 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
64 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
65 $sort = isset($_REQUEST['iSortCol_0']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_REQUEST['iSortCol_0'], 'Integer'), $sortMapper) : NULL;
66 $sortOrder = isset($_REQUEST['sSortDir_0']) ? CRM_Utils_Type::escape($_REQUEST['sSortDir_0'], 'String') : 'asc';
6a488035
TO
67
68 $params = $_REQUEST;
69 if ($sort && $sortOrder) {
70 $params['sortBy'] = $sort . ' ' . $sortOrder;
71 }
72
73 $params['page'] = ($offset / $rowCount) + 1;
74 $params['rp'] = $rowCount;
75
76 if ($context != 'financialBatch') {
77 // data entry status batches
c4514e7e 78 $params['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Batch_BAO_Batch', 'status_id', 'Data Entry');
6a488035 79 }
0b0941e2 80
6a488035
TO
81 $params['context'] = $context;
82
83 // get batch list
84 $batches = CRM_Batch_BAO_Batch::getBatchListSelector($params);
85
86 $iFilteredTotal = $iTotal = $params['total'];
6a488035
TO
87
88 if ($context == 'financialBatch') {
be2fb01f 89 $selectorElements = [
957bbb1d
CW
90 'check',
91 'batch_name',
92 'payment_instrument',
93 'item_count',
94 'total',
95 'status',
96 'created_by',
97 'links',
be2fb01f 98 ];
957bbb1d
CW
99 }
100 else {
be2fb01f 101 $selectorElements = [
957bbb1d
CW
102 'batch_name',
103 'type',
104 'item_count',
105 'total',
106 'status',
107 'created_by',
108 'links',
be2fb01f 109 ];
6a488035 110 }
d42a224c 111 CRM_Utils_System::setHttpHeader('Content-Type', 'application/json');
6a488035
TO
112 echo CRM_Utils_JSON::encodeDataTableSelector($batches, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
113 CRM_Utils_System::civiExit();
114 }
96025800 115
6a488035 116}