Merge pull request #6159 from yashodha/CRM-16735.fix
[civicrm-core.git] / CRM / Event / BAO / Event.php
index dbf9101a79814be0dc80836e484c6f3fbdffce9c..9a4f3d2aaf9b9c4e9fc296463ebffdb23d0e8f96 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.                                    |
  |                                                                    |
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
  *
  */
 class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
 
   /**
-   * Class constructor
+   * Class constructor.
    */
   public function __construct() {
     parent::__construct();
   }
 
   /**
-   * Fetch object based on array of properties
+   * Fetch object based on array of properties.
    *
    * @param array $params
    *   (reference ) an assoc array of name/value pairs.
@@ -62,7 +62,7 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
   }
 
   /**
-   * Update the is_active flag in the db
+   * Update the is_active flag in the db.
    *
    * @param int $id
    *   Id of the database record.
@@ -77,7 +77,7 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
   }
 
   /**
-   * Add the event
+   * Add the event.
    *
    * @param array $params
    *   Reference array contains the values submitted by the form.
@@ -116,7 +116,7 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
   }
 
   /**
-   * Create the event
+   * Create the event.
    *
    * @param array $params
    *   Reference array contains the values submitted by the form.
@@ -173,7 +173,7 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
   }
 
   /**
-   * Delete the event
+   * Delete the event.
    *
    * @param int $id
    *   Event id.
@@ -252,27 +252,35 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
    *   0 returns current and future events.
    *                                  1 if events all are required
    *                                  2 returns events since 3 months ago
-   * @param bool|int $id int id of a specific event to return
+   * @param int|array $id single int event id or array of multiple event ids to return
    * @param bool $isActive
    *   true if you need only active events.
    * @param bool $checkPermission
    *   true if you need to check permission else false.
+   * @param bool $titleOnly
+   *   true if you need only title not appended with start date
    *
    * @return array
    */
   public static function getEvents(
     $all = 0,
-    $id = FALSE,
+    $id = NULL,
     $isActive = TRUE,
-    $checkPermission = TRUE
+    $checkPermission = TRUE,
+    $titleOnly = FALSE
   ) {
     $query = "
 SELECT `id`, `title`, `start_date`
 FROM   `civicrm_event`
 WHERE  ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
 
-    if ($id) {
-      $query .= " AND `id` = {$id}";
+    if (!empty($id)) {
+      if (is_array($id)) {
+        $query .= " AND `id` IN (" . implode(',', $id) . ")";
+      }
+      else {
+        $query .= " AND `id` = {$id}";
+      }
     }
     elseif ($all == 0) {
       // find only events ending in the future
@@ -303,7 +311,10 @@ WHERE  ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
         ) &&
         $dao->title
       ) {
-        $events[$dao->id] = $dao->title . ' - ' . CRM_Utils_Date::customFormat($dao->start_date);
+        $events[$dao->id] = $dao->title;
+        if (!$titleOnly) {
+          $events[$dao->id] .= ' - ' . CRM_Utils_Date::customFormat($dao->start_date);
+        }
       }
     }
 
@@ -311,7 +322,7 @@ WHERE  ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
   }
 
   /**
-   * Get events Summary
+   * Get events Summary.
    *
    *
    * @return array
@@ -576,7 +587,7 @@ $event_summary_limit
   }
 
   /**
-   * Get participant count
+   * Get participant count.
    *
    * @param int $eventId
    * @param bool $considerStatus consider status for participant count.
@@ -642,7 +653,7 @@ $event_summary_limit
   }
 
   /**
-   * Get the information to map a event
+   * Get the information to map a event.
    *
    * @param int $id
    *   For which we want map info.
@@ -709,7 +720,7 @@ WHERE civicrm_address.geo_code_1 IS NOT NULL
   }
 
   /**
-   * Get the complete information for one or more events
+   * Get the complete information for one or more events.
    *
    * @param date $start
    *   Get events with start date >= this date.
@@ -1169,7 +1180,7 @@ WHERE civicrm_event.is_active = 1
           $tplParams['participant_status'] = CRM_Event_PseudoConstant::participantStatus($statusId, NULL, 'label');
         }
         //CRM-15754 - if participant_status contains status ID
-        elseif (CRM_Utils_Rule::integer($tplParams['participant_status'])) {
+        elseif (!empty($tplParams['participant_status']) && CRM_Utils_Rule::integer($tplParams['participant_status'])) {
           $tplParams['participant_status'] = CRM_Event_PseudoConstant::participantStatus($tplParams['participant_status'], NULL, 'label');
         }
 
@@ -1235,7 +1246,7 @@ WHERE civicrm_event.is_active = 1
           $taxAmt = $template->get_template_vars('totalTaxAmount');
           $prefixValue = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
           $invoicing = CRM_Utils_Array::value('invoicing', $prefixValue);
-          if ($taxAmt && (isset($invoicing) && isset($prefixValue['is_email_pdf']))) {
+          if (isset($invoicing) && isset($prefixValue['is_email_pdf'])) {
             $sendTemplateParams['isEmailPdf'] = TRUE;
             $sendTemplateParams['contributionId'] = $values['contributionId'];
           }
@@ -1282,6 +1293,7 @@ WHERE civicrm_event.is_active = 1
       $profileIds = $id;
     }
 
+    $val = $groupTitles = NULL;
     foreach ($profileIds as $gid) {
       if (CRM_Core_BAO_UFGroup::filterUFGroups($gid, $cid)) {
         $values = array();
@@ -1431,7 +1443,7 @@ WHERE civicrm_event.is_active = 1
   }
 
   /**
-   * Build the array for display the profile fields
+   * Build the array for display the profile fields.
    *
    * @param array $params
    *   Key value.
@@ -1696,7 +1708,7 @@ WHERE  id = $cfID
               $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name]));
             }
             else {
-              $values[$index] = $params[$name];
+              $values[$index] = CRM_Utils_Array::value($name, $params);
             }
           }
         }
@@ -1881,7 +1893,7 @@ WHERE  ce.loc_block_id = $locBlockId";
   }
 
   /**
-   * Check if event registration is valid according to permissions AND Dates
+   * Check if event registration is valid according to permissions AND Dates.
    *
    * @param array $values
    * @param int $eventID
@@ -1992,7 +2004,7 @@ WHERE  ce.loc_block_id = $locBlockId";
   }
 
   /**
-   * Make sure that the user has permission to access this event
+   * Make sure that the user has permission to access this event.
    *
    * @param int $eventId
    * @param int $type
@@ -2018,7 +2030,7 @@ WHERE  ce.loc_block_id = $locBlockId";
         $permissions[CRM_Core_Permission::EDIT] = array_keys($allEvents);
       }
       else {
-        $permissions[CRM_Core_Permission::EDIT] = &CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_event', $allEvents, $createdEvents);
+        $permissions[CRM_Core_Permission::EDIT] = CRM_ACL_API::group(CRM_Core_Permission::EDIT, NULL, 'civicrm_event', $allEvents, $createdEvents);
       }
 
       if (CRM_Core_Permission::check('edit all events')) {
@@ -2033,7 +2045,7 @@ WHERE  ce.loc_block_id = $locBlockId";
           // at the same time also allow any hook to override if needed.
           $createdEvents = array_keys($allEvents);
         }
-        $permissions[CRM_Core_Permission::VIEW] = &CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_event', $allEvents, $createdEvents);
+        $permissions[CRM_Core_Permission::VIEW] = CRM_ACL_API::group(CRM_Core_Permission::VIEW, NULL, 'civicrm_event', $allEvents, $createdEvents);
       }
 
       $permissions[CRM_Core_Permission::DELETE] = array();
@@ -2137,7 +2149,7 @@ LEFT  JOIN  civicrm_price_field_value value ON ( value.id = lineItem.price_field
   }
 
   /**
-   * Retrieve event template default values to be set
+   * Retrieve event template default values to be set.
    *  as default values for current new event.
    *
    * @param int $templateId
@@ -2179,7 +2191,7 @@ LEFT  JOIN  civicrm_price_field_value value ON ( value.id = lineItem.price_field
   }
 
   /**
-   * Update the Campaign Id of all the participants of the given event
+   * Update the Campaign Id of all the participants of the given event.
    *
    * @param int $eventID
    *   Event id.