CRM-20219 Update activity fields in profiles to use date picker
authoreileen <emcnaughton@wikimedia.org>
Sun, 5 Mar 2017 21:02:14 +0000 (10:02 +1300)
committereileen <emcnaughton@wikimedia.org>
Sun, 5 Mar 2017 21:34:48 +0000 (10:34 +1300)
CRM/Activity/Form/Task/Batch.php
CRM/Core/BAO/UFGroup.php
templates/CRM/Activity/Form/Task/Batch.tpl
templates/CRM/Profile/Form/Dynamic.tpl
tests/phpunit/api/v3/ProfileTest.php

index 980ef2c808aa8529b52717941ffada57255c28c4..72a72febc180decfde0989cabbe1b581999d6759 100644 (file)
@@ -95,7 +95,7 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
     $ufGroupId = $this->get('ufGroupId');
 
     if (!$ufGroupId) {
-      CRM_Core_Error::fatal('ufGroupId is missing');
+      throw new CRM_Core_Exception('The profile id is missing');
     }
     $this->_title = ts('Update multiple activities') . ' - ' . CRM_Core_BAO_UFGroup::getTitle($ufGroupId);
     CRM_Utils_System::setTitle($this->_title);
@@ -108,7 +108,7 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
     $suppressFields = FALSE;
     $removehtmlTypes = array('File', 'Autocomplete-Select');
     foreach ($this->_fields as $name => $field) {
-      if ($cfID = CRM_Core_BAO_CustomField::getKeyID($name) &&
+      if (CRM_Core_BAO_CustomField::getKeyID($name) &&
         in_array($this->_fields[$name]['html_type'], $removehtmlTypes)
       ) {
         $suppressFields = TRUE;
@@ -150,6 +150,10 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
     }
 
     $customFields = CRM_Core_BAO_CustomField::getFields('Activity');
+    // It is possible to have fields that are required in CiviCRM not be required in the
+    // profile. Overriding that here. Perhaps a better approach would be to
+    // make them required in the schema & read that up through getFields functionality.
+    $requiredFields = array('activity_date_time');
 
     foreach ($this->_activityHolderIds as $activityId) {
       $typeId = CRM_Core_DAO::getFieldValue("CRM_Activity_DAO_Activity", $activityId, 'activity_type_id');
@@ -169,6 +173,9 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
         }
         else {
           // Handle non custom fields.
+          if (in_array($field['name'], $requiredFields)) {
+            $field['is_required'] = TRUE;
+          }
           CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, $activityId);
         }
       }
@@ -216,10 +223,6 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
         );
         $value['id'] = $key;
 
-        if (!empty($value['activity_date_time'])) {
-          $value['activity_date_time'] = CRM_Utils_Date::processDate($value['activity_date_time'], $value['activity_date_time_time']);
-        }
-
         if (!empty($value['activity_status_id'])) {
           $value['status_id'] = $value['activity_status_id'];
         }
@@ -228,10 +231,6 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
           $value['details'] = $value['activity_details'];
         }
 
-        if (!empty($value['activity_duration'])) {
-          $value['duration'] = $value['activity_duration'];
-        }
-
         if (!empty($value['activity_location'])) {
           $value['location'] = $value['activity_location'];
         }
@@ -240,30 +239,9 @@ class CRM_Activity_Form_Task_Batch extends CRM_Activity_Form_Task {
           $value['subject'] = $value['activity_subject'];
         }
 
-        $query = "
-SELECT a.activity_type_id, ac.contact_id
-FROM   civicrm_activity a
-JOIN   civicrm_activity_contact ac ON ( ac.activity_id = a.id
-AND    ac.record_type_id = %2 )
-WHERE  a.id = %1 ";
-        $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name');
-        $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts);
-        $params = array(1 => array($key, 'Integer'), 2 => array($sourceID, 'Integer'));
-        $dao = CRM_Core_DAO::executeQuery($query, $params);
-        $dao->fetch();
-
-        // Get Activity Type ID
-        $value['activity_type_id'] = $dao->activity_type_id;
-
-        // Get Conatct ID
-        $value['source_contact_id'] = $dao->contact_id;
-
-        // make call use API 3
-        $value['version'] = 3;
-
-        $activityId = civicrm_api('activity', 'update', $value);
+        $activityId = civicrm_api3('activity', 'create', $value);
 
-        // add custom field values
+        // @todo this would be done by the api call above if the parames were passed through.
         if (!empty($value['custom']) &&
           is_array($value['custom'])
         ) {
index 0f66ca72aa48d393f43dce09c329bca5e2b0e553..a1f53680799b07e029d929ca30700d62b9ce00fe 100644 (file)
@@ -2337,7 +2337,6 @@ AND    ( entity_id IS NULL OR entity_id <= 0 )
       'receipt_date' => 'activityDateTime',
       'thankyou_date' => 'activityDateTime',
       'cancel_date' => 'activityDateTime',
-      'activity_date_time' => 'activityDateTime',
     );
   }
 
index 5af6d8c6ea911af0b37ed3e209bd29e64adfa902..e57a71bcc3ccbfdf846e8bb2724e8af0d414737f 100644 (file)
            <td>{$contactDetails.$activityId.$fName}</td>
         {/foreach}
                 {foreach from=$fields item=field key=fieldName}
-                {assign var=n value=$field.name}
-                {if $fields.$n.name eq 'activity_date_time' }
-                <td class="compressed">{include file="CRM/common/jcalendar.tpl" elementName=$fieldName elementIndex=$activityId batchUpdate=1}</td>
-                {else}
+                  {assign var=n value=$field.name}
                    <td class="compressed">{$form.field.$activityId.$n.html}</td>
-                {/if}
               {/foreach}
              </tr>
               {/foreach}
index 210d97bab52b649a108da4343fea4f57d681510c..7b7725af99f677912f14511af81265042cd8cef6 100644 (file)
                 &nbsp;{$form.$phone_ext_field.html}
                 {/if}
               {else}
-                {if $n eq 'activity_date_time' and $field.is_view neq 1 }
-                {include file="CRM/common/jcalendar.tpl" elementName=$n}
-                {else}
-                  {$form.$n.html}
-                {/if}
+                {$form.$n.html}
                 {if $field.html_type eq 'Autocomplete-Select'}
                   {if $field.data_type eq 'ContactReference'}
                     {include file="CRM/Custom/Form/ContactReference.tpl" element_name = $n}
index 4c79b94dc13fc4dd277ff6969822636f144af9d7..4e8ede8883dc10e8682b76335af4cdc8bb8ce5e6 100644 (file)
@@ -606,7 +606,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
       'activity_subject' => 'Test Meeting',
       'activity_details' => 'a test activity details',
       'activity_duration' => '100',
-      'activity_date_time' => '03/08/2010',
+      'activity_date_time' => '2010-03-08 00:00:00',
       'activity_status_id' => '2',
     );
     $profileParams = array_merge($params, $updateParams);
@@ -799,7 +799,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
       'assignee_contact_id' => $contactId,
       'activity_type_id' => '1',
       'subject' => 'Make-it-Happen Meeting',
-      'activity_date_time' => '20110316',
+      'activity_date_time' => '2011-03-16 00:00:00',
       'duration' => '120',
       'location' => 'Pensulvania',
       'details' => 'a test activity',
@@ -825,8 +825,7 @@ class api_v3_ProfileTest extends CiviUnitTestCase {
       'activity_subject' => 'Make-it-Happen Meeting',
       'activity_details' => 'a test activity',
       'activity_duration' => '120',
-      'activity_date_time_time' => '12:00AM',
-      'activity_date_time' => '03/16/2011',
+      'activity_date_time' => '2011-03-16 00:00:00',
       'activity_status_id' => '1',
     );