CRM-10043 - merge in changes to Activity.tpl and splitting of ActivityJs.tpl with...
authorDave Greenberg <dave@civicrm.org>
Tue, 14 Jan 2014 02:26:20 +0000 (18:26 -0800)
committerDave Greenberg <dave@civicrm.org>
Tue, 14 Jan 2014 02:26:20 +0000 (18:26 -0800)
CRM/Activity/BAO/Activity.php
CRM/Activity/BAO/ActivityAssignment.php
CRM/Activity/Form/Activity.php
CRM/Case/Form/Activity.php
CRM/Case/XMLProcessor/Report.php
templates/CRM/Activity/Form/Activity.tpl
templates/CRM/Activity/Form/ActivityJs.tpl

index e1b85267cabb62176ccb74ad24af54aab0a74329..f8ff6340a61208cb5cb3cf4fa805f4ccb13d6462 100644 (file)
@@ -2023,6 +2023,7 @@ AND cl.modified_id  = c.id
     $followupParams['activity_type_id'] = $params['followup_activity_type_id'];
     // Get Subject of Follow-up Activiity, CRM-4491
     $followupParams['subject'] = CRM_Utils_Array::value('followup_activity_subject', $params);
+    $followupParams['assignee_contact_id'] = CRM_Utils_Array::value('followup_assignee_contact_id', $params);
 
     //create target contact for followup
     if (CRM_Utils_Array::value('target_contact_id', $params)) {
index 82516493353c28bdd22d692baed1911efa98cd06..ffd021e054fee220729998d32a98a4bb0986775c 100644 (file)
@@ -105,7 +105,7 @@ AND        civicrm_contact.is_deleted = 0
   /**
    * Retrieve assignee names by activity_id
    *
-   * @param int      $id             ID of the activity
+   * @param array    $activityIDs    IDs of the activities
    * @param boolean  $isDisplayName  if set returns display names of assignees
    * @param boolean  $skipDetails    if false returns all details of assignee contact.
    *
@@ -114,9 +114,9 @@ AND        civicrm_contact.is_deleted = 0
    * @access public
    *
    */
-  static function getAssigneeNames($activityID, $isDisplayName = FALSE, $skipDetails = TRUE) {
+  static function getAssigneeNames($activityIDs, $isDisplayName = FALSE, $skipDetails = TRUE) {
     $assigneeNames = array();
-    if (empty($activityID)) {
+    if (empty($activityIDs)) {
       return $assigneeNames;
     }
     $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
@@ -126,20 +126,21 @@ AND        civicrm_contact.is_deleted = 0
     if (!$skipDetails) {
       $whereClause = "  AND ce.is_primary= 1";
     }
+    $inClause = implode(",", $activityIDs);
 
     $query = "
-SELECT     contact_a.id, contact_a.sort_name, contact_a.display_name, ce.email
+SELECT     contact_a.id, contact_a.sort_name, contact_a.display_name, ce.email,
+           civicrm_activity_contact.activity_id
 FROM       civicrm_contact contact_a
 INNER JOIN civicrm_activity_contact ON civicrm_activity_contact.contact_id = contact_a.id
 LEFT JOIN  civicrm_email ce ON ce.contact_id = contact_a.id
-WHERE      civicrm_activity_contact.activity_id = %1
+WHERE      civicrm_activity_contact.activity_id IN ( $inClause )
 AND        contact_a.is_deleted = 0
 AND        civicrm_activity_contact.record_type_id = $assigneeID
            {$whereClause}
 ";
 
-    $queryParam = array(1 => array($activityID, 'Integer'));
-    $dao = CRM_Core_DAO::executeQuery($query, $queryParam);
+    $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
       if (!$isDisplayName) {
         $assigneeNames[$dao->id] = $dao->sort_name;
@@ -154,6 +155,7 @@ AND        civicrm_activity_contact.record_type_id = $assigneeID
           $assigneeNames[$dao->id]['sort_name'] = $dao->sort_name;
           $assigneeNames[$dao->id]['email'] = $dao->email;
           $assigneeNames[$dao->id]['role'] = ts('Activity Assignee');
+          $assigneeNames[$dao->id]['activity_id'] = $dao->activity_id;
         }
       }
     }
index a323b8bbfce236a7a78d5be008bd95a11cfe69c0..4950aea6a2bb19169d3530e5915d6be06e111c95 100644 (file)
@@ -304,7 +304,7 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
     // Set title
     if (isset($activityTName)) {
       $activityName = CRM_Utils_Array::value($this->_activityTypeId, $activityTName);
-      $this->assign('pageTitle', ts('%1 Activity', $activityName));
+      $this->assign('pageTitle', ts('%1 Activity', array( 1 => $activityName)));
 
       if ($this->_currentlyViewedContactId) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_currentlyViewedContactId);
@@ -810,10 +810,13 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
       $admin
     );
 
+    $followupAssigneeContactField =& $this->add( 'text', 'followup_assignee_contact_id', ts('assignee') );
+
     $this->add('hidden', 'source_contact_qid', '', array('id' => 'source_contact_qid'));
     CRM_Contact_Form_NewContact::buildQuickForm($this);
 
     $this->add('text', 'assignee_contact_id', ts('assignee'));
+    $this->add( 'text', 'followup_assignee_contact_id', ts('assignee'));
 
     if ($sourceContactField->getValue()) {
       $this->assign('source_contact', $sourceContactField->getValue());
@@ -1040,6 +1043,13 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
     else {
       $params['assignee_contact_id'] = array();
     }
+      // civicrm-10043 - 14/12/13
+      if ( CRM_Utils_Array::value( 'followup_assignee_contact_id', $params ) ) {
+          $params['followup_assignee_contact_id'] = explode( ',', $params['followup_assignee_contact_id'] );
+     }
+     else {
+        $params['followup_assignee_contact_id'] = array( );
+     }
 
     // get ids for associated contacts
     if (!$params['source_contact_id']) {
@@ -1141,42 +1151,69 @@ class CRM_Activity_Form_Activity extends CRM_Contact_Form_Task {
 
     // create follow up activity if needed
     $followupStatus = '';
+    $followupActivity = NULL;
     if (CRM_Utils_Array::value('followup_activity_type_id', $params)) {
-      CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
+      $followupActivity = CRM_Activity_BAO_Activity::createFollowupActivity($activity->id, $params);
       $followupStatus = ts('A followup activity has been scheduled.');
     }
 
     // send copy to assignee contacts.CRM-4509
     $mailStatus = '';
 
-    if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id']) &&
-      CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
-        'activity_assignee_notification'
-      )
-    ) {
-      $mailToContacts = array();
-      $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE);
+    if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
+        'activity_assignee_notification')) {
+      $activityIDs = array($activity->id);
+      if ($followupActivity) {
+        $activityIDs = array_merge($activityIDs, array($followupActivity->id));
+      }
+      $assigneeContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityIDs, TRUE, FALSE);
 
-      //build an associative array with unique email addresses.
-      foreach ($activityAssigned as $id => $dnc) {
-        if (isset($id) && array_key_exists($id, $assigneeContacts)) {
-          $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id];
+      if (!CRM_Utils_Array::crmIsEmptyArray($params['assignee_contact_id'])) {
+        $mailToContacts = array();
+
+        //build an associative array with unique email addresses.
+        foreach ($activityAssigned as $id => $dnc) {
+          if (isset($id) && array_key_exists($id, $assigneeContacts)) {
+            $mailToContacts[$assigneeContacts[$id]['email']] = $assigneeContacts[$id];
+          }
         }
-      }
 
-      if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
-        //include attachments while sending a copy of activity.
-        $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
+        if (!CRM_Utils_array::crmIsEmptyArray($mailToContacts)) {
+          //include attachments while sending a copy of activity.
+          $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $activity->id);
+
+          $ics = new CRM_Activity_BAO_ICalendar($activity);
+          $ics->addAttachment($attachments, $mailToContacts);
 
-        $ics = new CRM_Activity_BAO_ICalendar($activity);
-        $ics->addAttachment($attachments, $mailToContacts);
+          // CRM-8400 add param with _currentlyViewedContactId for URL link in mail
+          CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL);
 
-        // CRM-8400 add param with _currentlyViewedContactId for URL link in mail
-        CRM_Case_BAO_Case::sendActivityCopy(NULL, $activity->id, $mailToContacts, $attachments, NULL);
+          $ics->cleanup();
 
-        $ics->cleanup();
+          $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s).");
+        }
+      }
+      
+      // Also send email to follow-up activity assignees if set
+      if ($followupActivity) {
+        $mailToFollowupContacts = array();
+        foreach ($assigneeContacts as $values) {
+          if ($values['activity_id'] == $followupActivity->id) {
+            $mailToFollowupContacts[$values['email']] = $values;
+          }
+        }
+
+        if (!CRM_Utils_array::crmIsEmptyArray($mailToFollowupContacts)) {
+          $ics = new CRM_Activity_BAO_ICalendar($followupActivity);
+          $attachments = CRM_Core_BAO_File::getEntityFile('civicrm_activity', $followupActivity->id);
+          $ics->addAttachment($attachments, $mailToFollowupContacts);
 
-        $mailStatus .= ts("A copy of the activity has also been sent to assignee contacts(s).");
+          CRM_Case_BAO_Case::sendActivityCopy(NULL, $followupActivity->id, $mailToFollowupContacts, $attachments, NULL);
+
+          $ics->cleanup();
+
+          $mailStatus .= '<br />' . ts("A copy of the follow-up activity has also been sent to follow-up assignee contacts(s).");
+        }
       }
     }
 
index 9b4bf0cfe8d35895155f56226c6555a061b6c509..be60a2c26d5f8d05974580e339d1b8e2bd2ff09d 100644 (file)
@@ -619,7 +619,7 @@ class CRM_Case_Form_Activity extends CRM_Activity_Form_Activity {
           $mailStatus = ts("A copy of the activity has also been sent to selected contacts(s).");
         }
         else {
-          $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activity->id, TRUE, FALSE);
+          $this->_relatedContacts = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activity->id), TRUE, FALSE);
           $mailStatus .= ' ' . ts("A copy of the activity has also been sent to assignee contacts(s).");
         }
 
index a06b40f1b5c6af4972adf5addaf8919445dc6dc4..869db441c7f35f6f89aa92ecd48868c4ae9b7c47 100644 (file)
@@ -405,7 +405,7 @@ WHERE      a.id = %1
 
     if (!empty($activityDAO->assigneeID)) {
       //allow multiple assignee contacts.CRM-4503.
-      $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames($activityDAO->id, TRUE);
+      $assignee_contact_names = CRM_Activity_BAO_ActivityAssignment::getAssigneeNames(array($activityDAO->id), TRUE);
 
       foreach ($assignee_contact_names as & $assignee) {
         // add Assignee to the strings to be redacted across the case session
index 73a9f945ba7af84e3c21329b1da80b91cd2dbe76..a15547929674d0a869227cb4797e80073b1b84ef 100644 (file)
               <td class="label">{$form.followup_activity_subject.label}</td>
               <td>{$form.followup_activity_subject.html|crmAddClass:huge}</td>
             </tr>
+              <tr>
+                  <td class="label">{ts}Assign To{/ts}</td>
+                  <td>{$form.followup_assignee_contact_id.html}
+                      {edit}<span class="description">{ts}You can optionally assign this activity to someone. Assigned activities will appear in their Activities listing at CiviCRM Home.{/ts}
+                          </span>
+                      {/edit}
+                  </td>
+              </tr>
           </table>
         </div><!-- /.crm-accordion-body -->
       </div><!-- /.crm-accordion-wrapper -->
index 8ee7da8284fa36b078ab9399a0c02e6868e87d5a..e8753aa6e276c671bfd6e62e29cdfed1cc06821b 100644 (file)
 {* added onload javascript for source contact*}
 {literal}
 <script type="text/javascript">
-  var assignee_contact = '';
+       var assignee_contact = followup_assignee_contact = '';
 
   {/literal}
   {if $assignee_contact}
   var assignee_contact = {$assignee_contact};
   {/if}
+       {if $followup_assignee_contact}
+               var followup_assignee_contact = {$followup_assignee_contact};
+       {/if}
 
   {literal}
-  var assignee_contact_id = null;
+  var assignee_contact_id = followup_assignee_contact_id = null;
   //loop to set the value of cc and bcc if form rule.
   var toDataUrl = "{/literal}{crmURL p='civicrm/ajax/checkemail' q='id=1&noemail=1' h=0 }{literal}"; {/literal}
-  {foreach from=","|explode:"assignee" key=key item=element}
+       {foreach from=","|explode:"assignee,followup_assignee" key=key item=element}
   {assign var=currentElement value=`$element`_contact_id}
   {if $form.$currentElement.value}
     {literal} var {/literal}{$currentElement}{literal} = cj.ajax({ url: toDataUrl + "&cid={/literal}{$form.$currentElement.value}{literal}", async: false }).responseText;{/literal}
@@ -48,6 +51,9 @@
   if ( assignee_contact_id ) {
     eval( 'assignee_contact = ' + assignee_contact_id );
   }
+       if ( followup_assignee_contact_id ) {
+               eval( 'followup_assignee_contact = ' + followup_assignee_contact_id );
+       }
 
   cj(function( ) {
     {/literal}
@@ -61,6 +67,7 @@
 
     var hintText = "{/literal}{ts escape='js'}Start typing a name or email address.{/ts}{literal}";
     cj( "#assignee_contact_id").tokenInput( tokenDataUrl_assignee, { prePopulate: assignee_contact, theme: 'facebook', hintText: hintText });
+               cj( "#followup_assignee_contact_id").tokenInput( tokenDataUrl_assignee, { prePopulate: followup_assignee_contact, theme: 'facebook', hintText: hintText });
     cj( 'ul.token-input-list-facebook, div.token-input-dropdown-facebook' ).css( 'width', '450px' );
     cj('#source_contact_id').autocomplete( sourceDataUrl, { width : 180, selectFirst : false, hintText: hintText, matchContains: true, minChars: 1, max: {/literal}{crmSetting name="search_autocomplete_count" group="Search Preferences"}{literal}
     }).result( function(event, data, formatted) { cj( "#source_contact_qid" ).val( data[1] );