*/
class CRM_Activity_Page_AJAX {
public static function getCaseActivity() {
+ // Should those params be passed through the getSanitizedParams method?
$caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
$contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
$userID = CRM_Utils_Type::escape($_GET['userID'], 'Integer');
$context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String');
- $sortMapper = array();
- foreach ($_GET['columns'] as $key => $value) {
- $sortMapper[$key] = $value['data'];
- };
-
- $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
- $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
- $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
- $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
+ $optionalParameters = array(
+ 'source_contact_id' => 'Integer',
+ 'status_id' => 'Integer',
+ 'activity_deleted' => 'Boolean',
+ 'activity_type_id' => 'Integer',
+ 'activity_date_low' => 'String',
+ 'activity_date_high' => 'String',
+ );
- $params = $_GET;
- if ($sort && $sortOrder) {
- $params['sortBy'] = $sort . ' ' . $sortOrder;
- }
- $params['page'] = ($offset / $rowCount) + 1;
- $params['rp'] = $rowCount;
+ $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
+ $params += CRM_Core_Page_AJAX::getSanitizedParams(array(), $optionalParameters);
// get the activities related to given case
$activities = CRM_Case_BAO_Case::getCaseActivity($caseID, $params, $contactID, $context, $userID);
}
public static function getCaseGlobalRelationships() {
- $sortMapper = array();
- foreach ($_GET['columns'] as $key => $value) {
- $sortMapper[$key] = $value['data'];
- };
-
- $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
- $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
- $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
- $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
-
- $params = $_GET;
-
- // CRM-14466 initialize variable to avoid php notice.
- $sortSQL = "";
- if ($sort && $sortOrder) {
- $sortSQL = $sort . ' ' . $sortOrder;
- }
+ $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
// get the activities related to given case
$globalGroupInfo = array();
// get the total row count
- $relGlobalTotalCount = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, NULL, FALSE, TRUE, NULL, NULL);
+ CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, NULL, FALSE, TRUE, NULL, NULL);
// limit the rows
- $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, $sortSQL, $showLinks = TRUE, FALSE, $offset, $rowCount);
+ $relGlobal = CRM_Case_BAO_Case::getGlobalContacts($globalGroupInfo, $params['sortBy'], $showLinks = TRUE, FALSE, $params['offset'], $params['rp']);
$relationships = array();
// after sort we can update username fields to be a url
array_push($relationships, $relationship);
}
- $params['total'] = count($relationships);
-
$globalRelationshipsDT = array();
$globalRelationshipsDT['data'] = $relationships;
- $globalRelationshipsDT['recordsTotal'] = $params['total'];
- $globalRelationshipsDT['recordsFiltered'] = $params['total'];
+ $globalRelationshipsDT['recordsTotal'] = count($relationships);
+ $globalRelationshipsDT['recordsFiltered'] = count($relationships);
CRM_Utils_JSON::output($globalRelationshipsDT);
}
$caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
$contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
- $sortMapper = array();
- foreach ($_GET['columns'] as $key => $value) {
- $sortMapper[$key] = $value['data'];
- };
-
- $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
- $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
- $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
- $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
-
- $params = $_GET;
+ $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
// Retrieve ALL client relationships
$relClient = CRM_Contact_BAO_Relationship::getRelationship($contactID,
// sort clientRelationships array using jquery call params
foreach ($clientRelationships as $key => $row) {
- $sortArray[$key] = $row[$sort];
+ $sortArray[$key] = $row[$params['_raw_values']['sort'][0]];
}
- $sort_type = "SORT_" . strtoupper($sortOrder);
+ $sort_type = "SORT_" . strtoupper($params['_raw_values']['order'][0]);
array_multisort($sortArray, constant($sort_type), $clientRelationships);
$relationships = array();
array_push($relationships, $relationship);
}
- $params['total'] = count($relationships);
-
$clientRelationshipsDT = array();
$clientRelationshipsDT['data'] = $relationships;
- $clientRelationshipsDT['recordsTotal'] = $params['total'];
- $clientRelationshipsDT['recordsFiltered'] = $params['total'];
+ $clientRelationshipsDT['recordsTotal'] = count($relationships);
+ $clientRelationshipsDT['recordsFiltered'] = count($relationships);
CRM_Utils_JSON::output($clientRelationshipsDT);
}
$caseID = CRM_Utils_Type::escape($_GET['caseID'], 'Integer');
$contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
- $sortMapper = array();
- foreach ($_GET['columns'] as $key => $value) {
- $sortMapper[$key] = $value['data'];
- };
-
- $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
- $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
- $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
- $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
-
- $params = $_GET;
+ $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
$caseRelationships = CRM_Case_BAO_Case::getCaseRoles($contactID, $caseID);
$caseTypeName = CRM_Case_BAO_Case::getCaseType($caseID, 'name');
// sort clientRelationships array using jquery call params
foreach ($caseRelationships as $key => $row) {
- $sortArray[$key] = $row[$sort];
+ $sortArray[$key] = $row[$params['_raw_values']['sort'][0]];
}
- $sort_type = "SORT_" . strtoupper($sortOrder);
+ $sort_type = "SORT_" . strtoupper($params['_raw_values']['order'][0]);
array_multisort($sortArray, constant($sort_type), $caseRelationships);
$relationships = array();
}
public static function getContactActivity() {
- $contactID = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
- $context = CRM_Utils_Type::escape(CRM_Utils_Array::value('context', $_GET), 'String');
-
- $sortMapper = array();
- foreach ($_GET['columns'] as $key => $value) {
- $sortMapper[$key] = $value['data'];
- };
-
- $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
- $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 25;
- $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
- $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
-
- $params = $_GET;
- if ($sort && $sortOrder) {
- $params['sortBy'] = $sort . ' ' . $sortOrder;
- }
+ $requiredParameters = array(
+ 'cid' => 'Integer',
+ );
- $params['page'] = ($offset / $rowCount) + 1;
- $params['rp'] = $rowCount;
+ $optionalParameters = array(
+ 'context' => 'String',
+ );
- $params['contact_id'] = $contactID;
- $params['context'] = $context;
+ $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams();
+ $params += CRM_Core_Page_AJAX::getSanitizedParams($requiredParameters, $optionalParameters);
// get the contact activities
$activities = CRM_Activity_BAO_Activity::getContactActivitySelector($params);
*
*/
public static function getMultiRecordFieldList() {
- $params = $_GET;
- $offset = isset($_GET['start']) ? CRM_Utils_Type::escape($_GET['start'], 'Integer') : 0;
- $rowCount = isset($_GET['length']) ? CRM_Utils_Type::escape($_GET['length'], 'Integer') : 10;
- $sortMapper = array();
- foreach ($_GET['columns'] as $key => $value) {
- $sortMapper[$key] = $value['data'];
- };
- $sort = isset($_GET['order'][0]['column']) ? CRM_Utils_Array::value(CRM_Utils_Type::escape($_GET['order'][0]['column'], 'Integer'), $sortMapper) : NULL;
- $sortOrder = isset($_GET['order'][0]['dir']) ? CRM_Utils_Type::escape($_GET['order'][0]['dir'], 'String') : 'asc';
+ $params = CRM_Core_Page_AJAX::defaultSortAndPagerParams(0, 10);
+ $params['cid'] = CRM_Utils_Type::escape($_GET['cid'], 'Integer');
+ $params['cgid'] = CRM_Utils_Type::escape($_GET['cgid'], 'Integer');
- $params['page'] = ($offset / $rowCount) + 1;
- $params['rp'] = $rowCount;
$contactType = CRM_Contact_BAO_Contact::getContactType($params['cid']);
$obj = new CRM_Profile_Page_MultipleRecordFieldsListing();
$obj->_contactType = $contactType;
$obj->_DTparams['offset'] = ($params['page'] - 1) * $params['rp'];
$obj->_DTparams['rowCount'] = $params['rp'];
- if ($sort && $sortOrder) {
- $sort = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $sort, 'column_name', 'label');
- $obj->_DTparams['sort'] = $sort . ' ' . $sortOrder;
+ if (isset($params['_raw_values']['sort'][0])) {
+ // Will this work when CiviCRM is translated, as searching happens on the label column?
+ // I can't find a place where the sort is added, but it should use the name, not the label.
+ $sort = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['_raw_values']['sort'][0], 'column_name', 'label');
+ $obj->_DTparams['sort'] = $sort . ' ' . $params['_raw_values']['order'][0];
}
list($fields, $attributes) = $obj->browse();