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
19 * This class contains the functions that are called using AJAX (jQuery)
21 class CRM_Custom_Page_AJAX
{
24 * This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
27 public static function getOptionList() {
30 $sEcho = CRM_Utils_Type
::escape($_REQUEST['sEcho'], 'Integer');
31 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
32 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
34 $params['page'] = ($offset / $rowCount) +
1;
35 $params['rp'] = $rowCount;
37 $options = CRM_Core_BAO_CustomOption
::getOptionListSelector($params);
39 $iFilteredTotal = $iTotal = $params['total'];
50 CRM_Utils_System
::setHttpHeader('Content-Type', 'application/json');
51 echo CRM_Utils_JSON
::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
52 CRM_Utils_System
::civiExit();
56 * Fix Ordering of options
59 public static function fixOrdering() {
63 1 => [$params['start'], 'Integer'],
64 2 => [$params['end'], 'Integer'],
65 3 => [$params['gid'], 'Integer'],
67 $dao = "SELECT id FROM civicrm_option_value WHERE weight = %1 AND option_group_id = %3";
68 $startid = CRM_Core_DAO
::singleValueQuery($dao, $queryParams);
70 $dao2 = "SELECT id FROM civicrm_option_value WHERE weight = %2 AND option_group_id = %3";
71 $endid = CRM_Core_DAO
::singleValueQuery($dao2, $queryParams);
73 $query = "UPDATE civicrm_option_value SET weight = %2 WHERE id = $startid";
74 CRM_Core_DAO
::executeQuery($query, $queryParams);
76 // increment or decrement the rest by one
77 if ($params['start'] < $params['end']) {
78 $updateRows = "UPDATE civicrm_option_value
79 SET weight = weight - 1
80 WHERE weight > %1 AND weight < %2 AND option_group_id = %3
84 $updateRows = "UPDATE civicrm_option_value
85 SET weight = weight + 1
86 WHERE weight < %1 AND weight > %2 AND option_group_id = %3
89 CRM_Core_DAO
::executeQuery($updateRows, $queryParams);
90 CRM_Utils_JSON
::output(TRUE);
94 * Get list of Multi Record Fields.
96 public static function getMultiRecordFieldList() {
98 $params = CRM_Core_Page_AJAX
::defaultSortAndPagerParams(0, 10);
99 $params['cid'] = CRM_Utils_Type
::escape($_GET['cid'], 'Integer');
100 $params['cgid'] = CRM_Utils_Type
::escape($_GET['cgid'], 'Integer');
102 if (!CRM_Core_BAO_CustomGroup
::checkGroupAccess($params['cgid'], CRM_Core_Permission
::VIEW
) ||
103 !CRM_Contact_BAO_Contact_Permission
::allow($params['cid'], CRM_Core_Permission
::VIEW
)
105 CRM_Utils_System
::permissionDenied();
108 $contactType = CRM_Contact_BAO_Contact
::getContactType($params['cid']);
110 $obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
111 $obj->_pageViewType
= 'customDataView';
112 $obj->_contactId
= $params['cid'];
113 $obj->_customGroupId
= $params['cgid'];
114 $obj->_contactType
= $contactType;
115 $obj->_DTparams
['offset'] = ($params['page'] - 1) * $params['rp'];
116 $obj->_DTparams
['rowCount'] = $params['rp'];
117 if (!empty($params['sortBy'])) {
118 $obj->_DTparams
['sort'] = $params['sortBy'];
121 list($fields, $attributes) = $obj->browse();
123 // format params and add class attributes
125 foreach ($fields as $id => $value) {
126 foreach ($value as $fieldId => &$fieldName) {
127 if (!empty($attributes[$fieldId][$id]['class'])) {
128 $fieldName = ['data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']];
130 if (is_numeric($fieldId)) {
131 $fName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name');
132 CRM_Utils_Array
::crmReplaceKey($value, $fieldId, $fName);
135 array_push($fieldList, $value);
137 $totalRecords = !empty($obj->_total
) ?
$obj->_total
: 0;
139 $multiRecordFields = [];
140 $multiRecordFields['data'] = $fieldList;
141 $multiRecordFields['recordsTotal'] = $totalRecords;
142 $multiRecordFields['recordsFiltered'] = $totalRecords;
144 CRM_Utils_JSON
::output($multiRecordFields);