Commit | Line | Data |
---|---|---|
57c9c217 | 1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
57c9c217 | 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 | | |
57c9c217 | 9 | +--------------------------------------------------------------------+ |
10 | */ | |
11 | ||
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
57c9c217 | 16 | * |
17 | */ | |
18 | ||
19 | /** | |
20 | * This class contains the functions that are called using AJAX (jQuery) | |
21 | */ | |
22 | class CRM_Custom_Page_AJAX { | |
9d311c8f | 23 | |
57c9c217 | 24 | /** |
9d311c8f CW |
25 | * This function uses the deprecated v1 datatable api and needs updating. See CRM-16353. |
26 | * @deprecated | |
57c9c217 | 27 | */ |
28 | public static function getOptionList() { | |
29 | $params = $_REQUEST; | |
30 | ||
57c9c217 | 31 | $sEcho = CRM_Utils_Type::escape($_REQUEST['sEcho'], 'Integer'); |
32 | $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayStart'], 'Integer') : 0; | |
33 | $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type::escape($_REQUEST['iDisplayLength'], 'Integer') : 25; | |
57c9c217 | 34 | |
35 | $params['page'] = ($offset / $rowCount) + 1; | |
36 | $params['rp'] = $rowCount; | |
37 | ||
38 | $options = CRM_Core_BAO_CustomOption::getOptionListSelector($params); | |
39 | ||
40 | $iFilteredTotal = $iTotal = $params['total']; | |
be2fb01f | 41 | $selectorElements = [ |
57c9c217 | 42 | 'label', |
43 | 'value', | |
4247b886 | 44 | 'description', |
57c9c217 | 45 | 'is_default', |
57c9c217 | 46 | 'is_active', |
47 | 'links', | |
48 | 'class', | |
be2fb01f | 49 | ]; |
57c9c217 | 50 | |
d42a224c | 51 | CRM_Utils_System::setHttpHeader('Content-Type', 'application/json'); |
57c9c217 | 52 | echo CRM_Utils_JSON::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements); |
53 | CRM_Utils_System::civiExit(); | |
54 | } | |
55 | ||
46227b8d | 56 | /** |
57 | * Fix Ordering of options | |
58 | * | |
59 | */ | |
46227b8d | 60 | public static function fixOrdering() { |
61 | $params = $_REQUEST; | |
62 | ||
be2fb01f CW |
63 | $queryParams = [ |
64 | 1 => [$params['start'], 'Integer'], | |
65 | 2 => [$params['end'], 'Integer'], | |
66 | 3 => [$params['gid'], 'Integer'], | |
67 | ]; | |
46227b8d | 68 | $dao = "SELECT id FROM civicrm_option_value WHERE weight = %1 AND option_group_id = %3"; |
69 | $startid = CRM_Core_DAO::singleValueQuery($dao, $queryParams); | |
70 | ||
71 | $dao2 = "SELECT id FROM civicrm_option_value WHERE weight = %2 AND option_group_id = %3"; | |
72 | $endid = CRM_Core_DAO::singleValueQuery($dao2, $queryParams); | |
73 | ||
74 | $query = "UPDATE civicrm_option_value SET weight = %2 WHERE id = $startid"; | |
75 | CRM_Core_DAO::executeQuery($query, $queryParams); | |
76 | ||
77 | // increment or decrement the rest by one | |
78 | if ($params['start'] < $params['end']) { | |
79 | $updateRows = "UPDATE civicrm_option_value | |
80 | SET weight = weight - 1 | |
81 | WHERE weight > %1 AND weight < %2 AND option_group_id = %3 | |
82 | OR id = $endid"; | |
83 | } | |
84 | else { | |
85 | $updateRows = "UPDATE civicrm_option_value | |
86 | SET weight = weight + 1 | |
87 | WHERE weight < %1 AND weight > %2 AND option_group_id = %3 | |
88 | OR id = $endid"; | |
89 | } | |
90 | CRM_Core_DAO::executeQuery($updateRows, $queryParams); | |
c1cd77e2 | 91 | CRM_Utils_JSON::output(TRUE); |
46227b8d | 92 | } |
93 | ||
5a2c7bb9 | 94 | /** |
95 | * Get list of Multi Record Fields. | |
96 | * | |
97 | */ | |
98 | public static function getMultiRecordFieldList() { | |
5a2c7bb9 | 99 | |
9c3f979f MM |
100 | $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(0, 10); |
101 | $params['cid'] = CRM_Utils_Type::escape($_GET['cid'], 'Integer'); | |
102 | $params['cgid'] = CRM_Utils_Type::escape($_GET['cgid'], 'Integer'); | |
5a2c7bb9 | 103 | |
5a2c7bb9 | 104 | $contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']); |
105 | ||
106 | $obj = new CRM_Profile_Page_MultipleRecordFieldsListing(); | |
107 | $obj->_pageViewType = 'customDataView'; | |
108 | $obj->_contactId = $params['cid']; | |
109 | $obj->_customGroupId = $params['cgid']; | |
110 | $obj->_contactType = $contactType; | |
c693f065 | 111 | $obj->_DTparams['offset'] = ($params['page'] - 1) * $params['rp']; |
112 | $obj->_DTparams['rowCount'] = $params['rp']; | |
e525d6af | 113 | if (!empty($params['sortBy'])) { |
f11b68e0 | 114 | $obj->_DTparams['sort'] = $params['sortBy']; |
c693f065 | 115 | } |
5a2c7bb9 | 116 | |
c693f065 | 117 | list($fields, $attributes) = $obj->browse(); |
5a2c7bb9 | 118 | |
f5eda27f | 119 | // format params and add class attributes |
be2fb01f | 120 | $fieldList = []; |
c693f065 | 121 | foreach ($fields as $id => $value) { |
be2fb01f | 122 | $field = []; |
d51e02d3 | 123 | foreach ($value as $fieldId => &$fieldName) { |
124 | if (!empty($attributes[$fieldId][$id]['class'])) { | |
be2fb01f | 125 | $fieldName = ['data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']]; |
d51e02d3 | 126 | } |
c693f065 | 127 | if (is_numeric($fieldId)) { |
f11b68e0 | 128 | $fName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name'); |
d51e02d3 | 129 | CRM_Utils_Array::crmReplaceKey($value, $fieldId, $fName); |
5a2c7bb9 | 130 | } |
131 | } | |
c693f065 | 132 | $field = $value; |
133 | array_push($fieldList, $field); | |
5a2c7bb9 | 134 | } |
f5eda27f | 135 | $totalRecords = !empty($obj->_total) ? $obj->_total : 0; |
5a2c7bb9 | 136 | |
be2fb01f | 137 | $multiRecordFields = []; |
c693f065 | 138 | $multiRecordFields['data'] = $fieldList; |
f5eda27f | 139 | $multiRecordFields['recordsTotal'] = $totalRecords; |
140 | $multiRecordFields['recordsFiltered'] = $totalRecords; | |
5a2c7bb9 | 141 | |
e525d6af | 142 | if (!empty($_GET['is_unit_test'])) { |
143 | return $multiRecordFields; | |
144 | } | |
145 | ||
c693f065 | 146 | CRM_Utils_JSON::output($multiRecordFields); |
5a2c7bb9 | 147 | } |
148 | ||
57c9c217 | 149 | } |