CRM-16569 - avoid backtrace when adding contacts to group
[civicrm-core.git] / CRM / Report / Form / Activity.php
index bd7ca05529afacaebdcfc7b243557460359b89ae..d3bbdfb13fb5f95d2de60e577dc209b9b803419b 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.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
@@ -42,8 +42,7 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
   protected $_nonDisplayFields = array();
 
   /**
-   */
-  /**
+   * Class constructor.
    */
   public function __construct() {
     // There could be multiple contacts. We not clear on which contact id to display.
@@ -346,8 +345,11 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
 
   /**
    * Adding address fields with dbAlias for order clause.
+   *
+   * @param bool $orderBy
+   *
    * @return array
-   *   address fields
+   *   Address fields
    */
   public function addressFields($orderBy = FALSE) {
     $address = parent::addAddressFields(FALSE, TRUE);
@@ -650,9 +652,13 @@ class CRM_Report_Form_Activity extends CRM_Report_Form {
       CRM_Core_Error::fatal(ts('Current filter criteria didn\'t have any target contact to add to group'));
     }
 
-    $query = "{$this->_select}
+    $new_select = 'AS addtogroup_contact_id';
+    $select = str_ireplace('AS civicrm_contact_contact_target_id', $new_select, $this->_select);
+    $new_having = ' addtogroup_contact_id';
+    $having = str_ireplace(' civicrm_contact_contact_target_id', $new_having, $this->_having);
+    $query = "$select
 FROM civireport_activity_temp_target tar
-GROUP BY civicrm_activity_id {$this->_having} {$this->_orderBy}";
+GROUP BY civicrm_activity_id $having {$this->_orderBy}";
     $select = 'AS addtogroup_contact_id';
     $query = str_ireplace('AS civicrm_contact_contact_target_id', $select, $query);
     $dao = CRM_Core_DAO::executeQuery($query);
@@ -767,16 +773,19 @@ GROUP BY civicrm_activity_id {$this->_having} {$this->_orderBy} {$this->_limit}"
   }
 
   /**
-   * @param $rows
+   * Alter display of rows.
+   *
+   * Iterate through the rows retrieved via SQL and make changes for display purposes,
+   * such as rendering contacts as links.
+   *
+   * @param array $rows
+   *   Rows generated by SQL, with an array for each row.
    */
   public function alterDisplay(&$rows) {
-    // custom code to alter rows
-
     $entryFound = FALSE;
     $activityType = CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE);
     $activityStatus = CRM_Core_PseudoConstant::activityStatus();
     $viewLinks = FALSE;
-    $seperator = CRM_Core_DAO::VALUE_SEPARATOR;
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'report');
     $actUrl = '';
 
@@ -893,7 +902,7 @@ GROUP BY civicrm_activity_id {$this->_having} {$this->_orderBy} {$this->_limit}"
         }
       }
 
-      if (array_key_exists('civicrm_activity_details', $row)) {
+      if (array_key_exists('civicrm_activity_details', $row) && $this->_outputMode == 'html') {
         if ($value = $row['civicrm_activity_details']) {
           $fullDetails = $rows[$rowNum]['civicrm_activity_details'];
           $rows[$rowNum]['civicrm_activity_details'] = substr($fullDetails, 0, strrpos(substr($fullDetails, 0, 80), ' '));