Merge remote-tracking branch 'upstream/4.4' into 4.4-master-2014-06-25-23-42-42
[civicrm-core.git] / CRM / Utils / Weight.php
index a5b240216694300b6d394af0ee6a5315644d299d..df1f36efd3f227005739575a9947f5df5921aaf0 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
   +--------------------------------------------------------------------+
-  | CiviCRM version 4.4                                                |
+  | CiviCRM version 4.5                                                |
   +--------------------------------------------------------------------+
-  | Copyright CiviCRM LLC (c) 2004-2013                                |
+  | Copyright CiviCRM LLC (c) 2004-2014                                |
   +--------------------------------------------------------------------+
   | This file is a part of CiviCRM.                                    |
   |                                                                    |
   | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
   +--------------------------------------------------------------------+
 */
+
+/**
+ * Class CRM_Utils_Weight
+ */
 class CRM_Utils_Weight {
   /**
    * @var array, list of GET fields which must be validated
@@ -81,6 +85,7 @@ class CRM_Utils_Weight {
    *
    * @param string $daoName full name of the DAO
    * $param integer $weight the weight to be removed
+   * @param $fieldID
    * @param array $fieldValues field => value to be used in the WHERE
    * @param string $weightField field which contains the weight value,
    * defaults to 'weight'
@@ -255,8 +260,11 @@ class CRM_Utils_Weight {
    * @param string $daoName full name of the DAO
    * @param array $fieldValues field => value to be used in the WHERE
    * @param string $queryData data to be used, dependent on the query type
+   * @param null $additionalWhere
    * @param string $orderBy optional ORDER BY field
    *
+   * @param null $groupBy
+   *
    * @return Object CRM_Core_DAO objet that holds the results of the query
    */
   static function &query($queryType,
@@ -328,6 +336,13 @@ class CRM_Utils_Weight {
     return $resultDAO;
   }
 
+  /**
+   * @param $rows
+   * @param $daoName
+   * @param $idName
+   * @param $returnURL
+   * @param null $filter
+   */
   static function addOrder(&$rows, $daoName, $idName, $returnURL, $filter = NULL) {
     if (empty($rows)) {
       return;
@@ -368,10 +383,10 @@ class CRM_Utils_Weight {
 
       if ($prevID != 0) {
         $alt = ts('Move to top');
-        $links[] = "<a href=\"{$url}&dst={$firstID}&dir=first\"><img src=\"{$imageURL}/first.gif\" title=\"$alt\" alt=\"$alt\" class=\"order-icon\"></a>";
+        $links[] = "<a class=\"crm-weight-arrow\" href=\"{$url}&dst={$firstID}&dir=first\"><img src=\"{$imageURL}/first.gif\" title=\"$alt\" alt=\"$alt\" class=\"order-icon\"></a>";
 
         $alt = ts('Move up one row');
-        $links[] = "<a href=\"{$url}&dst={$prevID}&dir=swap\"><img src=\"{$imageURL}/up.gif\" title=\"$alt\" alt=\"$alt\" class=\"order-icon\"></a>";
+        $links[] = "<a class=\"crm-weight-arrow\" href=\"{$url}&dst={$prevID}&dir=swap\"><img src=\"{$imageURL}/up.gif\" title=\"$alt\" alt=\"$alt\" class=\"order-icon\"></a>";
       }
       else {
         $links[] = "<img src=\"{$imageURL}/spacer.gif\" class=\"order-icon\">";
@@ -380,10 +395,10 @@ class CRM_Utils_Weight {
 
       if ($nextID != 0) {
         $alt = ts('Move down one row');
-        $links[] = "<a href=\"{$url}&dst={$nextID}&dir=swap\"><img src=\"{$imageURL}/down.gif\" title=\"$alt\" alt=\"$alt\" class=\"order-icon\"></a>";
+        $links[] = "<a class=\"crm-weight-arrow\" href=\"{$url}&dst={$nextID}&dir=swap\"><img src=\"{$imageURL}/down.gif\" title=\"$alt\" alt=\"$alt\" class=\"order-icon\"></a>";
 
         $alt = ts('Move to bottom');
-        $links[] = "<a href=\"{$url}&dst={$lastID}&dir=last\"><img src=\"{$imageURL}/last.gif\" title=\"$alt\" alt=\"$alt\" class=\"order-icon\"></a>";
+        $links[] = "<a class=\"crm-weight-arrow\" href=\"{$url}&dst={$lastID}&dir=last\"><img src=\"{$imageURL}/last.gif\" title=\"$alt\" alt=\"$alt\" class=\"order-icon\"></a>";
       }
       else {
         $links[] = "<img src=\"{$imageURL}/spacer.gif\" class=\"order-icon\">";
@@ -415,7 +430,7 @@ class CRM_Utils_Weight {
     $srcWeight = CRM_Core_DAO::getFieldValue($daoName, $src, 'weight', $idName);
     $dstWeight = CRM_Core_DAO::getFieldValue($daoName, $dst, 'weight', $idName);
     if ($srcWeight == $dstWeight) {
-      CRM_Utils_System::redirect($url);
+      self::fixOrderOutput($url);
     }
 
     $tableName = $object->tableName();
@@ -455,7 +470,20 @@ class CRM_Utils_Weight {
       CRM_Core_DAO::executeQuery($query, $params);
     }
 
-    CRM_Utils_System::redirect($url);
+    self::fixOrderOutput($url);
+  }
+
+  /**
+   * @param $url
+   */
+  static function fixOrderOutput($url) {
+    if (empty($_GET['snippet']) || $_GET['snippet'] !== 'json') {
+      CRM_Utils_System::redirect($url);
+    }
+
+    CRM_Core_Page_AJAX::returnJsonResponse(array(
+      'userContext' => $url,
+    ));
   }
 }