Merge pull request #4687 from eileenmcnaughton/CRM-15699-master
[civicrm-core.git] / CRM / Event / BAO / Query.php
index 771631b7179fba95028ed71e052db8be37a8ca37..376d3062e0cd8217903ffe1315093911beabe916 100644 (file)
@@ -56,7 +56,7 @@ class CRM_Event_BAO_Query {
   }
 
   /**
-   * build select for CiviEvent
+   * Build select for CiviEvent
    *
    * @param $query
    *
@@ -207,6 +207,7 @@ class CRM_Event_BAO_Query {
     }
   }
 
+
   /**
    * @param $query
    */
@@ -256,6 +257,42 @@ class CRM_Event_BAO_Query {
         $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1;
         return;
 
+      case 'event_include_repeating_events':
+        /**
+         * Include Repeating Events
+         */
+        //Get parent of this event
+        $exEventId = '';
+        if ($query->_where[$grouping]) {
+          foreach($query->_where[$grouping] as $key => $val) {
+            if (strstr($val, 'civicrm_event.id =')) {
+              $exEventId = $val;
+              $extractEventId = explode(" ", $val);
+              $value = $extractEventId[2];
+              unset($query->_where[$grouping][$key]);
+            }
+          }
+          $extractEventId = explode(" ", $exEventId);
+          $value = $extractEventId[2];
+          unset($query->_where[$grouping][$key]);
+        }
+        $thisEventHasParent = CRM_Core_BAO_RecurringEntity::getParentFor($value, 'civicrm_event');
+        if ($thisEventHasParent) {
+          $getAllConnections = CRM_Core_BAO_RecurringEntity::getEntitiesForParent($thisEventHasParent, 'civicrm_event');
+          $allEventIds = array();
+          foreach($getAllConnections as $key => $val) {
+            $allEventIds[] = $val['id'];
+          }
+          if (!empty($allEventIds)) {
+            $op = "IN";
+            $value = "(".implode(",", $allEventIds).")";
+          }
+        }
+        $query->_where[$grouping][] = "civicrm_event.id $op {$value}";
+        $query->_qill[$grouping][] = ts('Include Repeating Events (If Any) ') . " = TRUE";
+        $query->_tables['civicrm_event'] = $query->_whereTables['civicrm_event'] = 1;
+        return;
+
       case 'event_type_id':
 
         $eventTypes = CRM_Core_OptionGroup::values("event_type");
@@ -417,11 +454,7 @@ class CRM_Event_BAO_Query {
         return;
 
       case 'participant_id':
-        $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.id",
-          $op,
-          $value,
-          "Integer"
-        );
+        $query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_participant.id", $op, $value, "Integer");
         $query->_tables['civicrm_participant'] = $query->_whereTables['civicrm_participant'] = 1;
         return;
 
@@ -467,7 +500,7 @@ class CRM_Event_BAO_Query {
   }
 
   /**
-   * @param $name
+   * @param string $name
    * @param $mode
    * @param $side
    *
@@ -513,7 +546,7 @@ class CRM_Event_BAO_Query {
   }
 
   /**
-   * getter for the qill object
+   * Getter for the qill object
    *
    * @return string
    * @access public
@@ -602,6 +635,7 @@ 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 (If Any) ? '));
 
     $status = CRM_Event_PseudoConstant::participantStatus(NULL, NULL, 'label');
     foreach ($status as $id => $Name) {
@@ -645,7 +679,7 @@ class CRM_Event_BAO_Query {
 
   /**
    * @param $row
-   * @param $id
+   * @param int $id
    */
   static function searchAction(&$row, $id) {}