Merge pull request #2712 from pratik-joshi/CRM-14363
[civicrm-core.git] / CRM / Case / Page / AJAX.php
index b05803690f0d6a2d841b1b35eabb692e8829c95f..7e7256cc744c4502e1fa5c8d11d7bb5c9d870f82 100644 (file)
@@ -41,30 +41,25 @@ class CRM_Case_Page_AJAX {
    * Retrieve unclosed cases.
    */
   static function unclosedCases() {
-    $criteria = explode('-', CRM_Utils_Type::escape(CRM_Utils_Array::value('s', $_GET), 'String'));
-
-    $limit = NULL;
-    if ($limit = CRM_Utils_Array::value('limit', $_GET)) {
-      $limit = CRM_Utils_Type::escape($limit, 'Integer');
-    }
-
     $params = array(
-      'limit' => $limit,
-      'case_type' => trim(CRM_Utils_Array::value(1, $criteria)),
-      'sort_name' => trim(CRM_Utils_Array::value(0, $criteria)),
+      'limit' => CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'search_autocomplete_count', NULL, 10),
+      'sort_name' => CRM_Utils_Type::escape(CRM_Utils_Array::value('term', $_GET, ''), 'String'),
     );
 
     $excludeCaseIds = array();
-    if ($caseIdStr = CRM_Utils_Array::value('excludeCaseIds', $_GET)) {
-      $excludeIdStr = CRM_Utils_Type::escape($caseIdStr, 'String');
-      $excludeCaseIds = explode(',', $excludeIdStr);
+    if (!empty($_GET['excludeCaseIds'])) {
+      $excludeCaseIds = explode(',', CRM_Utils_Type::escape($_GET['excludeCaseIds'], 'String'));
     }
     $unclosedCases = CRM_Case_BAO_Case::getUnclosedCases($params, $excludeCaseIds);
-
+    $results = array();
     foreach ($unclosedCases as $caseId => $details) {
-      echo $details['sort_name'] . ' (' . $details['case_type'] . ': ' . $details['case_subject'] . ') ' . "|$caseId|" . $details['contact_id'] . '|' . $details['case_type'] . '|' . $details['sort_name'] . "\n";
+      $results[] = array(
+        'id' => $caseId,
+        'text' => $details['sort_name'] . ' (' . $details['case_type'] . ': ' . $details['case_subject'] . ')',
+        'extra' => $details,
+      );
     }
-
+    print json_encode($results);
     CRM_Utils_System::civiExit();
   }
 
@@ -84,9 +79,7 @@ class CRM_Case_Page_AJAX {
       $tagIds = explode(',', $tags);
     }
 
-    $skipEntityDelete = FALSE;
     if (!empty($tagIds)) {
-      $skipEntityDelete = TRUE;
       $params = array(
         'entity_id' => $caseId,
         'entity_table' => 'civicrm_case',
@@ -103,7 +96,7 @@ class CRM_Case_Page_AJAX {
     }
 
     if (!empty($tagList)) {
-      CRM_Core_Form_Tag::postProcess($tagList, $caseId, 'civicrm_case', CRM_Core_DAO::$_nullObject, $skipEntityDelete);
+      CRM_Core_Form_Tag::postProcess($tagList, $caseId, 'civicrm_case', CRM_Core_DAO::$_nullObject);
     }
 
     $session = CRM_Core_Session::singleton();