CRM-16208 - Clarify repeating event search and fix fatal error
authorColeman Watts <coleman@civicrm.org>
Wed, 1 Apr 2015 02:10:13 +0000 (22:10 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 1 Apr 2015 02:10:13 +0000 (22:10 -0400)
CRM/Event/BAO/Query.php
api/v3/Activity.php
api/v3/Contact.php
api/v3/Event.php
api/v3/Generic/Getlist.php
api/v3/RecurringEntity.php [new file with mode: 0644]
templates/CRM/Event/Form/Search/Common.tpl

index 6652c08b5e31ab42ef2d0cfcad2c78391a00bf27..c27adb13589e4b29619027cc234d48141f650fce 100644 (file)
@@ -542,13 +542,18 @@ class CRM_Event_BAO_Query {
 
     $form->assign('dataURLEventFee', $dataURLEventFee);
 
-    $eventId = $form->addEntityRef('event_id', ts('Event Name'), array(
+    $form->addEntityRef('event_id', ts('Event Name'), array(
         'entity' => 'event',
         'placeholder' => ts('- any -'),
         'select' => array('minimumInputLength' => 0),
+        'api' => array(
+          'params' => array(
+            'api.RecurringEntity.getcount' => array('entity_id' => "\$value.id", 'entity_table' => "civicrm_event"),
+          ),
+        ),
       )
     );
-    $eventType = $form->addEntityRef('event_type_id', ts('Event Type'), array(
+    $form->addEntityRef('event_type_id', ts('Event Type'), array(
         'entity' => 'option_value',
         'placeholder' => ts('- any -'),
         'select' => array('minimumInputLength' => 0),
@@ -560,7 +565,8 @@ class CRM_Event_BAO_Query {
     $form->add('text', 'participant_fee_id', ts('Fee Level'), array('class' => 'big crm-ajax-select'));
 
     CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE);
-    $eventIncludeRepeatingEvents = &$form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include Repeating Events?'));
+
+    $form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', array(1 => '<em>%1</em>')));
 
     $form->addSelect('participant_status_id',
       array('entity' => 'participant', 'label' => ts('Participant Status'), 'multiple' => 'multiple', 'option_url' => NULL, 'placeholder' => ts('- any -'))
index 946c631100604a850742ab83469a5baa07a92d51..efa238d10a5f67e32b556a3516a3cb90dcb7ad87 100644 (file)
@@ -483,9 +483,6 @@ function _civicrm_api3_activity_getlist_output($result, $request) {
           1 => CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $row['source_contact_id'], 'display_name'),
         ));
       }
-      foreach ($request['extra'] as $field) {
-        $data['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL;
-      }
       $output[] = $data;
     }
   }
index aa4a693ed46c08c47467a1e57b83003f4bf8d43d..de305dd33181f7ceaf0af069f65b80efe279c342 100644 (file)
@@ -1133,9 +1133,6 @@ function _civicrm_api3_contact_getlist_output($result, $request) {
       else {
         $data['icon_class'] = $row['contact_type'];
       }
-      foreach ($request['extra'] as $field) {
-        $data['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL;
-      }
       $output[] = $data;
     }
   }
index abff8e836bbc9c958e5673b42410fd02e4553798..79993cda4bbe711155aeb41d1d55e36c291d4cb1 100644 (file)
@@ -259,9 +259,6 @@ function _civicrm_api3_event_getlist_output($result, $request) {
       if (!empty($row['summary'])) {
         $data['description'][] = $row['summary'];
       }
-      foreach ($request['extra'] as $field) {
-        $data['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL;
-      }
       $output[] = $data;
     }
   }
index 1774036773473f9f5279e94c1bfd1376a3447745..8582f1515ee8a054a540f7710aae5ac4a184cacf 100644 (file)
@@ -58,6 +58,8 @@ function civicrm_api3_generic_getList($apiRequest) {
   $fnName = function_exists($fnName) ? $fnName : '_civicrm_api3_generic_getlist_output';
   $values = $fnName($result, $request);
 
+  _civicrm_api3_generic_getlist_postprocess($result, $request, $values);
+
   $output = array('page_num' => $request['page_num']);
 
   // Limit is set for searching but not fetching by id
@@ -176,15 +178,38 @@ function _civicrm_api3_generic_getlist_output($result, $request) {
       if (!empty($request['image_field'])) {
         $data['image'] = isset($row[$request['image_field']]) ? $row[$request['image_field']] : '';
       }
-      foreach ($request['extra'] as $field) {
-        $data['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL;
-      }
       $output[] = $data;
     }
   }
   return $output;
 }
 
+/**
+ * Common postprocess for getlist output
+ *
+ * @param $result
+ * @param $request
+ * @param $values
+ */
+function _civicrm_api3_generic_getlist_postprocess($result, $request, &$values) {
+  $chains = array();
+  foreach ($request['params'] as $field => $param) {
+    if (substr($field, 0, 4) === 'api.') {
+      $chains[] = $field;
+    }
+  }
+  if (!empty($result['values'])) {
+    foreach (array_values($result['values']) as $num => $row) {
+      foreach ($request['extra'] as $field) {
+        $values[$num]['extra'][$field] = isset($row[$field]) ? $row[$field] : NULL;
+      }
+      foreach ($chains as $chain) {
+        $values[$num][$chain] = isset($row[$chain]) ? $row[$chain] : NULL;
+      }
+    }
+  }
+}
+
 /**
  * Provide metadata for this api
  *
diff --git a/api/v3/RecurringEntity.php b/api/v3/RecurringEntity.php
new file mode 100644 (file)
index 0000000..9ee0b57
--- /dev/null
@@ -0,0 +1,96 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.6                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | This file is a part of CiviCRM.                                    |
+ |                                                                    |
+ | CiviCRM is free software; you can copy, modify, and distribute it  |
+ | under the terms of the GNU Affero General Public License           |
+ | Version 3, 19 November 2007 and the CiviCRM Licensing Exception.   |
+ |                                                                    |
+ | CiviCRM is distributed in the hope that it will be useful, but     |
+ | WITHOUT ANY WARRANTY; without even the implied warranty of         |
+ | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
+ | See the GNU Affero General Public License for more details.        |
+ |                                                                    |
+ | You should have received a copy of the GNU Affero General Public   |
+ | License and the CiviCRM Licensing Exception along                  |
+ | with this program; if not, contact CiviCRM LLC                     |
+ | at info[AT]civicrm[DOT]org. If you have questions about the        |
+ | GNU Affero General Public License or the licensing of CiviCRM,     |
+ | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ * This api exposes CiviCRM recurring entity records.
+ *
+ * @package CiviCRM_APIv3
+ */
+
+/**
+ * Retrieve a recurring entity.
+ *
+ * @param array $params
+ *   Input parameters.
+ *
+ * @return array
+ */
+function civicrm_api3_recurring_entity_get($params) {
+  return _civicrm_api3_basic_get(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Adjust Metadata for Get action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $params
+ *   Array of parameters determined by getfields.
+ */
+function _civicrm_api3_recurring_entity_get_spec(&$params) {
+  $params['entity_table']['options'] = array(
+    'civicrm_event' => 'civicrm_event',
+    'civicrm_activity' => 'civicrm_activity',
+  );
+}
+
+/**
+ * Add or update a recurring entity.
+ *
+ * @param array $params
+ *
+ * @return array
+ */
+function civicrm_api3_recurring_entity_create($params) {
+  return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
+
+/**
+ * Adjust Metadata for Create action.
+ *
+ * The metadata is used for setting defaults, documentation & validation.
+ *
+ * @param array $params
+ *   Array of parameters determined by getfields.
+ */
+function _civicrm_api3_recurring_entity_create_spec(&$params) {
+  $params['entity_table']['options'] = array(
+    'civicrm_event' => 'civicrm_event',
+    'civicrm_activity' => 'civicrm_activity',
+  );
+}
+
+/**
+ * Deletes an existing ReportInstance.
+ *
+ * @param array $params
+ *
+ * @return array
+ */
+function civicrm_api3_recurring_entity_delete($params) {
+  return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
+}
index 7d8e3607786c1ac9621daea6fe12e70cdaaa4da6..47beaf83e016ace57949711c320621b1e40d241b 100644 (file)
 *}
 <tr>
   <td class="crm-event-form-block-event_id">
-      {$form.event_id.label}  <br />{$form.event_id.html|crmAddClass:huge} <br/>
-      {$form.event_include_repeating_events.label}&nbsp;&nbsp;{$form.event_include_repeating_events.html}
+      {$form.event_id.label}  <br />{$form.event_id.html|crmAddClass:huge}
+      <div class="crm-event-form-block-event_include_repeating_events">
+        {$form.event_include_repeating_events.label}&nbsp;&nbsp;{$form.event_include_repeating_events.html}
+      </div>
   </td>
   <td class="crm-event-form-block-event_type_id"> {$form.event_type_id.label}<br />{$form.event_type_id.html} </td>
 </tr>
@@ -81,6 +83,18 @@ campaignTrClass='' campaignTdClass='crm-event-form-block-participant_campaign_id
 {literal}
 <script type="text/javascript">
 CRM.$(function($) {
+  var recurringLabel = $('label[for=event_include_repeating_events]').html();
+  // Conditional rule for recurring checkbox
+  function toggleRecurrigCheckbox() {
+    if ($(this).val() && $(this).select2('data')['api.RecurringEntity.getcount']) {
+      $('.crm-event-form-block-event_include_repeating_events').show();
+      $('label[for=event_include_repeating_events]').html(recurringLabel.replace('%1', $(this).select2('data').label));
+    } else {
+      $('.crm-event-form-block-event_include_repeating_events').hide().find('input').prop('checked', false);
+    }
+  }
+  $('#event_id').each(toggleRecurrigCheckbox).change(toggleRecurrigCheckbox);
+
   // FIXME: This could be much simpler as an entityRef field but the priceFieldValue api doesn't currently support the filters we need
   $('#participant_fee_id').crmSelect2({
     placeholder: {/literal}'{ts escape="js"}- any -{/ts}'{literal},