Code styling fixes
[civicrm-core.git] / CRM / Contact / Page / DedupeFind.php
index 434384527ced61af68646ea1b848c92b7a9ad0ef..0129be19d57f0ebbf402f033db28ab20e5c030fc 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -39,30 +39,32 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
   protected $_gid;
 
   /**
-   * Get BAO Name
+   * Get BAO Name.
    *
-   * @return string Classname of BAO.
+   * @return string
+   *   Classname of BAO.
    */
-  function getBAOName() {
+  public function getBAOName() {
     return 'CRM_Dedupe_BAO_RuleGroup';
   }
 
   /**
-   * Get action Links
+   * Get action Links.
    *
-   * @return array (reference) of action links
+   * @return void
+   *   (reference) of action links
    */
-  function &links() {}
+  public function &links() {
+  }
 
   /**
-   * Browse all rule groups
+   * Browse all rule groups.
    *
    * @return void
-   * @access public
    */
-  function run() {
-    $gid     = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0);
-    $action  = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 0);
+  public function run() {
+    $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0);
+    $action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 0);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
 
     $session = CRM_Core_Session::singleton();
@@ -92,12 +94,12 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
     elseif ($action & CRM_Core_Action::MAP) {
       // do a batch merge if requested
       $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0);
-      $result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, 'safe', TRUE, TRUE);
+      $result = CRM_Dedupe_Merger::batchMerge($rgid, $gid, 'safe', TRUE, 75);
 
       $skippedCount = CRM_Utils_Request::retrieve('skipped', 'Positive', $this, FALSE, 0);
       $skippedCount = $skippedCount + count($result['skipped']);
-      $mergedCount  = CRM_Utils_Request::retrieve('merged', 'Positive', $this, FALSE, 0);
-      $mergedCount  = $mergedCount + count($result['merged']);
+      $mergedCount = CRM_Utils_Request::retrieve('merged', 'Positive', $this, FALSE, 0);
+      $mergedCount = $mergedCount + count($result['merged']);
 
       if (empty($result['merged']) && empty($result['skipped'])) {
         $message = '';
@@ -136,8 +138,8 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
     if ($action & CRM_Core_Action::UPDATE ||
       $action & CRM_Core_Action::BROWSE
     ) {
-      $cid          = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0);
-      $rgid         = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0);
+      $cid = CRM_Utils_Request::retrieve('cid', 'Positive', $this, FALSE, 0);
+      $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0);
       $this->action = CRM_Core_Action::UPDATE;
 
       //calculate the $contactType
@@ -155,6 +157,9 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
       if ($rgid) {
         $sourceParams .= "&rgid={$rgid}";
       }
+      if ($context == 'conflicts') {
+        $sourceParams .= "&selected=1";
+      }
 
       $this->assign('sourceUrl', CRM_Utils_System::url('civicrm/ajax/dedupefind', $sourceParams, FALSE, NULL, FALSE));
 
@@ -163,11 +168,31 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
       $cacheKeyString .= $rgid ? "_{$rgid}" : '_0';
       $cacheKeyString .= $gid ? "_{$gid}" : '_0';
 
+      $stats = CRM_Dedupe_Merger::getMergeStatsMsg($cacheKeyString);
+      if ($stats) {
+        CRM_Core_Session::setStatus($stats);
+        // reset so we not displaying same message again
+        CRM_Dedupe_Merger::resetMergeStats($cacheKeyString);
+      }
       $join = "LEFT JOIN civicrm_dedupe_exception de ON ( pn.entity_id1 = de.contact_id1 AND
                                                                  pn.entity_id2 = de.contact_id2 )";
       $where = "de.id IS NULL";
+      if ($context == 'conflicts') {
+        $where .= " AND pn.is_selected = 1";
+      }
       $this->_mainContacts = CRM_Core_BAO_PrevNextCache::retrieve($cacheKeyString, $join, $where);
       if (empty($this->_mainContacts)) {
+        if ($context == 'conflicts') {
+          // if the current screen was intended to list only selected contacts, move back to full dupe list
+          $sourceParams = 'reset=1&action=update';
+          if ($gid) {
+            $sourceParams .= "&gid={$gid}";
+          }
+          if ($rgid) {
+            $sourceParams .= "&rgid={$rgid}";
+          }
+          CRM_Utils_System::redirect(CRM_Utils_System::url(CRM_Utils_System::currentPath(), $sourceParams));
+        }
         if ($gid) {
           $foundDupes = $this->get("dedupe_dupes_$gid");
           if (!$foundDupes) {
@@ -209,8 +234,8 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
             $cids[$dupe[1]] = 1;
           }
           $cidString = implode(', ', array_keys($cids));
-          $sql       = "SELECT id, display_name FROM civicrm_contact WHERE id IN ($cidString) ORDER BY sort_name";
-          $dao       = new CRM_Core_DAO();
+          $sql = "SELECT id, display_name FROM civicrm_contact WHERE id IN ($cidString) ORDER BY sort_name";
+          $dao = new CRM_Core_DAO();
           $dao->query($sql);
           $displayNames = array();
           while ($dao->fetch()) {
@@ -222,8 +247,8 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
           // (also, consider sorting by dupe count first)
           // lobo - change the sort to by threshold value
           // so the more likely dupes are sorted first
-          $session      = CRM_Core_Session::singleton();
-          $userId       = $session->get('userID');
+          $session = CRM_Core_Session::singleton();
+          $userId = $session->get('userID');
           $mainContacts = $permission = array();
 
           foreach ($foundDupes as $dupes) {
@@ -238,14 +263,14 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
              * Eliminate this since it introduces 3 queries PER merge row
              * and hence is very expensive
              * CRM-8822
-             if ( !array_key_exists( $srcID, $permission ) ) {
-             $permission[$srcID] = CRM_Contact_BAO_Contact_Permission::allow( $srcID, CRM_Core_Permission::EDIT );
-             }
-             if ( !array_key_exists( $dstID, $permission ) ) {
-             $permission[$dstID] = CRM_Contact_BAO_Contact_Permission::allow( $dstID, CRM_Core_Permission::EDIT );
-             }
-
-             $canMerge = ( $permission[$dstID] && $permission[$srcID] );
+             if ( !array_key_exists( $srcID, $permission ) ) {
+             $permission[$srcID] = CRM_Contact_BAO_Contact_Permission::allow( $srcID, CRM_Core_Permission::EDIT );
+             }
+             if ( !array_key_exists( $dstID, $permission ) ) {
+             $permission[$dstID] = CRM_Contact_BAO_Contact_Permission::allow( $dstID, CRM_Core_Permission::EDIT );
+             }
+             *
+             $canMerge = ( $permission[$dstID] && $permission[$srcID] );
              *
              */
 
@@ -277,13 +302,13 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
           $session = CRM_Core_Session::singleton();
           if ($this->_cid) {
             $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/deduperules',
-                "action=update&rgid={$this->_rgid}&gid={$this->_gid}&cid={$this->_cid}"
-              ));
+              "action=update&rgid={$this->_rgid}&gid={$this->_gid}&cid={$this->_cid}"
+            ));
           }
           else {
             $session->pushUserContext(CRM_Utils_System::url('civicrm/contact/dedupefind',
-                "reset=1&action=update&rgid={$this->_rgid}"
-              ));
+              "reset=1&action=update&rgid={$this->_rgid}"
+            ));
           }
         }
       }
@@ -312,12 +337,11 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
   }
 
   /**
-   * Browse all rule groups
+   * Browse all rule groups.
    *
    * @return void
-   * @access public
    */
-  function browse() {
+  public function browse() {
     $this->assign('main_contacts', $this->_mainContacts);
 
     if ($this->_cid) {
@@ -330,32 +354,35 @@ class CRM_Contact_Page_DedupeFind extends CRM_Core_Page_Basic {
   }
 
   /**
-   * Get name of edit form
+   * Get name of edit form.
    *
-   * @return string  classname of edit form
+   * @return string
+   *   classname of edit form
    */
-  function editForm() {
+  public function editForm() {
     return 'CRM_Contact_Form_DedupeFind';
   }
 
   /**
-   * Get edit form name
+   * Get edit form name.
    *
-   * @return string  name of this page
+   * @return string
+   *   name of this page
    */
-  function editName() {
+  public function editName() {
     return 'DedupeFind';
   }
 
   /**
-   * Get user context
+   * Get user context.
    *
    * @param null $mode
    *
-   * @return string  user context
+   * @return string
+   *   user context
    */
-  function userContext($mode = NULL) {
+  public function userContext($mode = NULL) {
     return 'civicrm/contact/dedupefind';
   }
-}
 
+}