3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
36 * This class contains the functions that are called using AJAX (jQuery)
38 class CRM_Custom_Page_AJAX
{
41 * This function uses the deprecated v1 datatable api and needs updating. See CRM-16353.
44 public static function getOptionList() {
47 $sEcho = CRM_Utils_Type
::escape($_REQUEST['sEcho'], 'Integer');
48 $offset = isset($_REQUEST['iDisplayStart']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayStart'], 'Integer') : 0;
49 $rowCount = isset($_REQUEST['iDisplayLength']) ? CRM_Utils_Type
::escape($_REQUEST['iDisplayLength'], 'Integer') : 25;
51 $params['page'] = ($offset / $rowCount) +
1;
52 $params['rp'] = $rowCount;
54 $options = CRM_Core_BAO_CustomOption
::getOptionListSelector($params);
56 $iFilteredTotal = $iTotal = $params['total'];
67 CRM_Utils_System
::setHttpHeader('Content-Type', 'application/json');
68 echo CRM_Utils_JSON
::encodeDataTableSelector($options, $sEcho, $iTotal, $iFilteredTotal, $selectorElements);
69 CRM_Utils_System
::civiExit();
73 * Fix Ordering of options
76 public static function fixOrdering() {
80 1 => [$params['start'], 'Integer'],
81 2 => [$params['end'], 'Integer'],
82 3 => [$params['gid'], 'Integer'],
84 $dao = "SELECT id FROM civicrm_option_value WHERE weight = %1 AND option_group_id = %3";
85 $startid = CRM_Core_DAO
::singleValueQuery($dao, $queryParams);
87 $dao2 = "SELECT id FROM civicrm_option_value WHERE weight = %2 AND option_group_id = %3";
88 $endid = CRM_Core_DAO
::singleValueQuery($dao2, $queryParams);
90 $query = "UPDATE civicrm_option_value SET weight = %2 WHERE id = $startid";
91 CRM_Core_DAO
::executeQuery($query, $queryParams);
93 // increment or decrement the rest by one
94 if ($params['start'] < $params['end']) {
95 $updateRows = "UPDATE civicrm_option_value
96 SET weight = weight - 1
97 WHERE weight > %1 AND weight < %2 AND option_group_id = %3
101 $updateRows = "UPDATE civicrm_option_value
102 SET weight = weight + 1
103 WHERE weight < %1 AND weight > %2 AND option_group_id = %3
106 CRM_Core_DAO
::executeQuery($updateRows, $queryParams);
107 CRM_Utils_JSON
::output(TRUE);
111 * Get list of Multi Record Fields.
114 public static function getMultiRecordFieldList() {
116 $params = CRM_Core_Page_AJAX
::defaultSortAndPagerParams(0, 10);
117 $params['cid'] = CRM_Utils_Type
::escape($_GET['cid'], 'Integer');
118 $params['cgid'] = CRM_Utils_Type
::escape($_GET['cgid'], 'Integer');
120 $contactType = CRM_Contact_BAO_Contact
::getContactType($params['cid']);
122 $obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
123 $obj->_pageViewType
= 'customDataView';
124 $obj->_contactId
= $params['cid'];
125 $obj->_customGroupId
= $params['cgid'];
126 $obj->_contactType
= $contactType;
127 $obj->_DTparams
['offset'] = ($params['page'] - 1) * $params['rp'];
128 $obj->_DTparams
['rowCount'] = $params['rp'];
129 if (!empty($params['sortBy'])) {
130 $obj->_DTparams
['sort'] = $params['sortBy'];
133 list($fields, $attributes) = $obj->browse();
135 // format params and add class attributes
137 foreach ($fields as $id => $value) {
139 foreach ($value as $fieldId => &$fieldName) {
140 if (!empty($attributes[$fieldId][$id]['class'])) {
141 $fieldName = ['data' => $fieldName, 'cellClass' => $attributes[$fieldId][$id]['class']];
143 if (is_numeric($fieldId)) {
144 $fName = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_CustomField', $fieldId, 'column_name');
145 CRM_Utils_Array
::crmReplaceKey($value, $fieldId, $fName);
149 array_push($fieldList, $field);
151 $totalRecords = !empty($obj->_total
) ?
$obj->_total
: 0;
153 $multiRecordFields = [];
154 $multiRecordFields['data'] = $fieldList;
155 $multiRecordFields['recordsTotal'] = $totalRecords;
156 $multiRecordFields['recordsFiltered'] = $totalRecords;
158 if (!empty($_GET['is_unit_test'])) {
159 return $multiRecordFields;
162 CRM_Utils_JSON
::output($multiRecordFields);