Merge pull request #5597 from pratikshad/CRM-16008
[civicrm-core.git] / CRM / Event / BAO / Event.php
index a41c375459e70f5031d13662a5f2f80c4ced067e..e87dd2d235cced9f64bd44cc351c101290496cd3 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.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @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.
    * @param array $defaults
    *   (reference ) an assoc array to hold the flattened values.
    *
-   * @return CRM_Event_BAO_ManageEvent object
-   * @static
+   * @return CRM_Event_BAO_ManageEvent
    */
   public static function retrieve(&$params, &$defaults) {
     $event = new CRM_Event_DAO_Event();
@@ -63,27 +62,26 @@ 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.
    * @param bool $is_active
    *   Value we want to set the is_active field.
    *
-   * @return Object             DAO object on sucess, null otherwise
-   * @static
+   * @return Object
+   *   DAO object on sucess, null otherwise
    */
   public static function setIsActive($id, $is_active) {
     return CRM_Core_DAO::setFieldValue('CRM_Event_DAO_Event', $id, 'is_active', $is_active);
   }
 
   /**
-   * Add the event
+   * Add the event.
    *
    * @param array $params
    *   Reference array contains the values submitted by the form.
    *
-   * @static
    *
    * @return object
    */
@@ -118,14 +116,12 @@ 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.
    *
    * @return object
-   * @static
-   *
    */
   public static function create(&$params) {
     $transaction = new CRM_Core_Transaction();
@@ -177,14 +173,12 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
   }
 
   /**
-   * Delete the event
+   * Delete the event.
    *
    * @param int $id
    *   Event id.
    *
    * @return mixed|null
-   * @static
-   *
    */
   public static function del($id) {
     if (!$id) {
@@ -236,7 +230,6 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
    * @param int $eventId
    *   Event with which loc block is associated.
    *
-   * @static
    */
   public static function deleteEventLocBlock($locBlockId, $eventId = NULL) {
     $query = "SELECT count(ce.id) FROM civicrm_event ce WHERE ce.loc_block_id = $locBlockId";
@@ -255,24 +248,23 @@ class CRM_Event_BAO_Event extends CRM_Event_DAO_Event {
   /**
    * Get current/future Events
    *
-   * @param $all
-   *   Int 0 returns current and future events.
+   * @param int $all
+   *   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 $isActive
-   *   Boolean true if you need only active events.
-   * @param $checkPermission
-   *   Boolean true if you need to check permission else false.
+   * @param bool $isActive
+   *   true if you need only active events.
+   * @param bool $checkPermission
+   *   true if you need to check permission else false.
    *
    * @return array
-   * @static
    */
-  static function getEvents(
+  public static function getEvents(
     $all = 0,
-                            $id = FALSE,
-                            $isActive = TRUE,
-                            $checkPermission = TRUE
+    $id = FALSE,
+    $isActive = TRUE,
+    $checkPermission = TRUE
   ) {
     $query = "
 SELECT `id`, `title`, `start_date`
@@ -319,11 +311,11 @@ WHERE  ( civicrm_event.is_template IS NULL OR civicrm_event.is_template = 0 )";
   }
 
   /**
-   * Get events Summary
+   * Get events Summary.
    *
-   * @static
    *
-   * @return array Array of event summary values
+   * @return array
+   *   Array of event summary values
    */
   public static function getEventSummary() {
     $eventSummary = $eventIds = array();
@@ -584,27 +576,28 @@ $event_summary_limit
   }
 
   /**
-   * Get participant count
+   * Get participant count.
    *
    * @param int $eventId
-   * @param bool $considerStatusConsider status for participant count.
+   * @param bool $considerStatus consider status for participant count.
    *   Consider status for participant count.
-   * @param bool $statusConsider counted participant.
+   * @param bool $status counted participant.
    *   Consider counted participant.
-   * @param bool $considerRoleConsider role for participant count.
+   * @param bool $considerRole consider role for participant count.
    *   Consider role for participant count.
-   * @param bool $roleConsider counted( is filter role) participant.
+   * @param bool $role consider counted( is filter role) participant.
    *   Consider counted( is filter role) participant.
    *
    *
-   * @return array array with count of participants for each event based on status/role
+   * @return array
+   *   array with count of participants for each event based on status/role
    */
   public static function getParticipantCount(
     $eventId,
-                                             $considerStatus = TRUE,
-                                             $status = TRUE,
-                                             $considerRole = TRUE,
-                                             $role = TRUE
+    $considerStatus = TRUE,
+    $status = TRUE,
+    $considerRole = TRUE,
+    $role = TRUE
   ) {
 
     // consider both role and status for counted participants, CRM-4924.
@@ -649,13 +642,13 @@ $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.
    *
-   * @return null|string     title of the event
-   * @static
+   * @return null|string
+   *   title of the event
    */
   public static function &getMapInfo(&$id) {
 
@@ -701,9 +694,9 @@ WHERE civicrm_address.geo_code_1 IS NOT NULL
       $params = array('entity_id' => $id, 'entity_table' => 'civicrm_event');
       $addressValues = CRM_Core_BAO_Location::getValues($params, TRUE);
       $location['address'] = str_replace(array(
-          "\r",
-          "\n"
-        ), '', addslashes(nl2br($addressValues['address'][1]['display_text'])));
+        "\r",
+        "\n",
+      ), '', addslashes(nl2br($addressValues['address'][1]['display_text'])));
 
       $location['url'] = CRM_Utils_System::url('civicrm/event/register', 'reset=1&id=' . $dao->event_id);
       $location['location_type'] = $dao->location_type;
@@ -716,23 +709,23 @@ 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.
-   * @param int $typeGet events on the a specific event type (by event_type_id).
+   * @param int $type Get events on the a specific event type (by event_type_id).
    *   Get events on the a specific event type (by event_type_id).
-   * @param int $eventIdReturn a single event - by event id.
+   * @param int $eventId Return a single event - by event id.
    *   Return a single event - by event id.
    * @param date $end
    *   Also get events with end date >= this date.
-   * @param bool $onlyPublicInclude public events only, default TRUE.
+   * @param bool $onlyPublic Include public events only, default TRUE.
    *   Include public events only, default TRUE.
    *
-   * @return  array  $all      array of all the events that are searched
-   * @static
+   * @return array
+   *   array of all the events that are searched
    */
-  static function &getCompleteInfo(
+  public static function &getCompleteInfo(
     $start = NULL,
     $type = NULL,
     $eventId = NULL,
@@ -907,21 +900,20 @@ WHERE civicrm_event.is_active = 1
   }
 
   /**
-   * This function is to make a copy of a Event, including
+   * make a copy of a Event, including
    * all the fields in the event Wizard
    *
    * @param int $id
    *   The event id to copy.
-   *        obj     $newEvent    object of CRM_Event_DAO_Event
    *        boolean $afterCreate call to copy after the create function
    * @param null $newEvent
    * @param bool $afterCreate
    *
-   * @return void
+   * @return CRM_Event_DAO_Event
    */
   public static function copy($id, $newEvent = NULL, $afterCreate = FALSE) {
 
-    $defaults = $eventValues = array();
+    $eventValues = array();
 
     //get the require event values.
     $eventParams = array('id' => $id);
@@ -930,7 +922,7 @@ WHERE civicrm_event.is_active = 1
       'is_show_location',
       'default_fee_id',
       'default_discount_fee_id',
-      'is_template'
+      'is_template',
     );
 
     CRM_Core_DAO::commonRetrieve('CRM_Event_DAO_Event', $eventParams, $eventValues, $returnProperties);
@@ -952,7 +944,7 @@ WHERE civicrm_event.is_active = 1
         array('id' => $id),
         array(
           'loc_block_id' =>
-            ($locBlockId) ? $locBlockId : NULL,
+          ($locBlockId) ? $locBlockId : NULL,
         ),
         $fieldsFix
       );
@@ -1177,7 +1169,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');
         }
 
@@ -1268,7 +1260,7 @@ WHERE civicrm_event.is_active = 1
    *
    * @return void
    */
-  static function buildCustomDisplay(
+  public static function buildCustomDisplay(
     $id,
     $name,
     $cid,
@@ -1439,7 +1431,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.
@@ -1453,7 +1445,6 @@ WHERE civicrm_event.is_active = 1
    * @param array $profileFields
    *
    * @return void
-   * @static
    */
   public static function displayProfile(&$params, $gid, &$groupTitle, &$values, &$profileFields = array()) {
     if ($gid) {
@@ -1524,7 +1515,7 @@ WHERE civicrm_event.is_active = 1
         elseif (in_array($name, array(
           'addressee',
           'email_greeting',
-          'postal_greeting'
+          'postal_greeting',
         ))) {
           $filterCondition = array('greeting_type' => $name);
           $greeting = CRM_Core_PseudoConstant::greeting($filterCondition);
@@ -1589,7 +1580,7 @@ WHERE civicrm_event.is_active = 1
           if (in_array($fieldName, array(
             'state_province',
             'country',
-            'county'
+            'county',
           ))) {
             $values[$index] = $params[$detailName];
             $idx = $detailName . '_id';
@@ -1700,7 +1691,7 @@ WHERE  id = $cfID
             elseif (in_array($name, array(
               'birth_date',
               'deceased_date',
-              'participant_register_date'
+              'participant_register_date',
             ))) {
               $values[$index] = CRM_Utils_Date::customFormat(CRM_Utils_Date::format($params[$name]));
             }
@@ -1730,9 +1721,10 @@ WHERE  id = $cfID
    *
    * @param bool $skipCancel
    *
-   * @return array $customProfile array of Additional participant's info OR array of Ids.
+   * @return array
+   *   array of Additional participant's info OR array of Ids.
    */
-  static function buildCustomProfile(
+  public static function buildCustomProfile(
     $participantId,
     $values,
     $contactId = NULL,
@@ -1843,7 +1835,8 @@ WHERE  id = $cfID
 
   /* Function to retrieve all events those having location block set.
    *
-   * @return array $events array of all events.
+   * @return array
+   *   array of all events.
    */
   /**
    * @return array
@@ -1888,11 +1881,11 @@ 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
-   * @return boolean
+   * @return bool
    */
   public static function validRegistrationRequest($values, $eventID) {
     // check that the user has permission to register for this event
@@ -1932,7 +1925,8 @@ WHERE  ce.loc_block_id = $locBlockId";
    *
    * @param array $values
    *   Key/value event info.
-   * @return boolean true if allow registration otherwise false
+   * @return boolean
+   *   true if allow registration otherwise false
    */
   /**
    * @param $values
@@ -1969,7 +1963,7 @@ WHERE  ce.loc_block_id = $locBlockId";
    *
    * @param array $params
    *   Key/value participant info.
-   * @return boolean $alreadyRegistered true/false
+   * @return boolean
    */
   /**
    * @param array $params
@@ -1998,13 +1992,13 @@ 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
    *
-   * @return string   the permission that the user has (or null)
-   * @static
+   * @return string
+   *   the permission that the user has (or null)
    */
   public static function checkPermission($eventId = NULL, $type = CRM_Core_Permission::VIEW) {
     static $permissions = NULL;
@@ -2067,8 +2061,8 @@ WHERE  ce.loc_block_id = $locBlockId";
    * @param int $eventId
    *   The id of the event.
    *
-   * @return array         an array of email ids
-   * @static
+   * @return array
+   *   an array of email ids
    */
   public static function getFromEmailIds($eventId = NULL) {
     $fromEmailValues['from_email_id'] = CRM_Core_BAO_Email::getFromEmail();
@@ -2103,8 +2097,8 @@ WHERE  ce.loc_block_id = $locBlockId";
    * @param sting $extraWhereClause
    *   Extra filter on participants.
    *
-   * @return int   event total seats w/ given criteria.
-   * @static
+   * @return int
+   *   event total seats w/ given criteria.
    */
   public static function eventTotalSeats($eventId, $extraWhereClause = NULL) {
     if (empty($eventId)) {
@@ -2143,13 +2137,14 @@ 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
    *   Event template id.
    *
-   * @return array of custom data defaults.
+   * @return array
+   *   Array of custom data defaults.
    */
   public static function getTemplateDefaultValues($templateId) {
     $defaults = array();
@@ -2184,7 +2179,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.