3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
20 * This class contains the functions that are called using AJAX (jQuery)
22 class CRM_Custom_Page_AJAX
{
25 * This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
28 public static function getOptionList() {
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;
35 $params['page'] = ($offset / $rowCount) +
1;
36 $params['rp'] = $rowCount;
38 $options = CRM_Core_BAO_CustomOption
::getOptionListSelector($params);
40 $iFilteredTotal = $iTotal = $params['total'];
51 CRM_Utils_System
::setHttpHeader('Content-Type', 'application/json');
52 echo CRM_Utils_JSON
::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
53 CRM_Utils_System
::civiExit();
57 * Fix Ordering of options
60 public static function fixOrdering() {
64 1 => [$params['start'], 'Integer'],
65 2 => [$params['end'], 'Integer'],
66 3 => [$params['gid'], 'Integer'],
68 $dao = "SELECT id FROM civicrm_option_value WHERE weight = %1 AND option_group_id = %3";
69 $startid = CRM_Core_DAO
::singleValueQuery($dao, $queryParams);
71 $dao2 = "SELECT id FROM civicrm_option_value WHERE weight = %2 AND option_group_id = %3";
72 $endid = CRM_Core_DAO
::singleValueQuery($dao2, $queryParams);
74 $query = "UPDATE civicrm_option_value SET weight = %2 WHERE id = $startid";
75 CRM_Core_DAO
::executeQuery($query, $queryParams);
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
85 $updateRows = "UPDATE civicrm_option_value
86 SET weight = weight + 1
87 WHERE weight < %1 AND weight > %2 AND option_group_id = %3
90 CRM_Core_DAO
::executeQuery($updateRows, $queryParams);
91 CRM_Utils_JSON
::output(TRUE);
95 * Get list of Multi Record Fields.
98 public static function getMultiRecordFieldList() {
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');
104 $contactType = CRM_Contact_BAO_Contact
::getContactType($params['cid']);
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;
111 $obj->_DTparams
['offset'] = ($params['page'] - 1) * $params['rp'];
112 $obj->_DTparams
['rowCount'] = $params['rp'];
113 if (!empty($params['sortBy'])) {
114 $obj->_DTparams
['sort'] = $params['sortBy'];
117 list($fields, $attributes) = $obj->browse();
119 // format params and add class attributes
121 foreach ($fields as $id => $value) {
123 foreach ($value as $fieldId => &$fieldName) {
124 if (!empty($attributes[$fieldId][$id]['class'])) {
125 $fieldName = ['data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']];
127 if (is_numeric($fieldId)) {
128 $fName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name');
129 CRM_Utils_Array
::crmReplaceKey($value, $fieldId, $fName);
133 array_push($fieldList, $field);
135 $totalRecords = !empty($obj->_total
) ?
$obj->_total
: 0;
137 $multiRecordFields = [];
138 $multiRecordFields['data'] = $fieldList;
139 $multiRecordFields['recordsTotal'] = $totalRecords;
140 $multiRecordFields['recordsFiltered'] = $totalRecords;
142 if (!empty($_GET['is_unit_test'])) {
143 return $multiRecordFields;
146 CRM_Utils_JSON
::output($multiRecordFields);