INFRA-132 comments to end with full stops
[civicrm-core.git] / CRM / Campaign / BAO / Campaign.php
index 5485b4887433e0e46a7157b12852ae4091a19c52..2261f3a15b1f1e00238e754a95b65e1dd140d241 100644 (file)
@@ -23,7 +23,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * $Id$
  *
  */
-Class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
+class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
 
   /**
-   * Takes an associative array and creates a campaign object
+   * Takes an associative array and creates a campaign object.
    *
    * the function extract all the params it needs to initialize the create a
    * contact object. the params array could contain additional unused name/value
    * pairs
    *
-   * @param array  $params (reference ) an assoc array of name/value pairs
+   * @param array $params
+   *   (reference ) an assoc array of name/value pairs.
    *
-   * @return CRM_Campaign_DAO_Campaign object
-   * @static
+   * @return CRM_Campaign_DAO_Campaign
    */
   public static function create(&$params) {
     if (empty($params)) {
-      return;
+      return NULL;
     }
 
     if (!(CRM_Utils_Array::value('id', $params))) {
@@ -77,11 +77,11 @@ Class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
 
     if (isset($params['groups']) && !empty($params['groups']['include']) && is_array($params['groups']['include'])) {
       foreach ($params['groups']['include'] as $entityId) {
-        $dao               = new CRM_Campaign_DAO_CampaignGroup();
-        $dao->campaign_id  = $campaign->id;
+        $dao = new CRM_Campaign_DAO_CampaignGroup();
+        $dao->campaign_id = $campaign->id;
         $dao->entity_table = $groupTableName;
-        $dao->entity_id    = $entityId;
-        $dao->group_type   = 'Include';
+        $dao->entity_id = $entityId;
+        $dao->group_type = 'Include';
         $dao->save();
         $dao->free();
       }
@@ -98,9 +98,10 @@ Class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
   }
 
   /**
-   * Delete the campaign
+   * Delete the campaign.
    *
-   * @param  int $id id of the campaign
+   * @param int $id
+   *   Id of the campaign.
    *
    * @return bool|mixed
    */
@@ -114,12 +115,14 @@ Class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
   }
 
   /**
-   * Takes a bunch of params that are needed to match certain criteria and
-   * retrieves the relevant objects. Typically the valid params are only
-   * campaign_id.
+   * Retrieve DB object based on input parameters.
+   *
+   * It also stores all the retrieved values in the default array.
    *
-   * @param array $params (reference ) an assoc array of name/value pairs
-   * @param array $defaults (reference ) an assoc array to hold the flattened values
+   * @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_Campaign_DAO_Campaign|null
    */
@@ -138,29 +141,37 @@ Class CRM_Campaign_BAO_Campaign extends CRM_Campaign_DAO_Campaign {
   /**
    * Return the all eligible campaigns w/ cache.
    *
-   * @param int $includeId lets inlcude this campaign by force.
-   * @param int $excludeId do not include this campaign.
-   * @param boolean $onlyActive consider only active campaigns.
+   * @param int $includeId
+   *   Lets inlcude this campaign by force.
+   * @param int $excludeId
+   *   Do not include this campaign.
+   * @param bool $onlyActive
+   *   Consider only active campaigns.
    *
    * @param bool $onlyCurrent
    * @param bool $appendDatesToTitle
    * @param bool $forceAll
    *
-   * @return mixed $campaigns a set of campaigns.@access public
+   * @return mixed
+   *   $campaigns a set of campaigns.
    */
   public static function getCampaigns(
     $includeId = NULL,
-    $excludeId          = NULL,
-    $onlyActive         = TRUE,
-    $onlyCurrent        = TRUE,
+    $excludeId = NULL,
+    $onlyActive = TRUE,
+    $onlyCurrent = TRUE,
     $appendDatesToTitle = FALSE,
-    $forceAll           = FALSE
+    $forceAll = FALSE
   ) {
     static $campaigns;
     $cacheKey = 0;
     $cacheKeyParams = array(
-      'includeId', 'excludeId', 'onlyActive',
-      'onlyCurrent', 'appendDatesToTitle', 'forceAll',
+      'includeId',
+      'excludeId',
+      'onlyActive',
+      'onlyCurrent',
+      'appendDatesToTitle',
+      'forceAll',
     );
     foreach ($cacheKeyParams as $param) {
       $cacheParam = $$param;
@@ -228,8 +239,19 @@ Order By  camp.title";
    * Wrapper to self::getCampaigns( )
    * w/ permissions and component check.
    *
+   * @param int $includeId
+   * @param int $excludeId
+   * @param bool $onlyActive
+   * @param bool $onlyCurrent
+   * @param bool $appendDatesToTitle
+   * @param bool $forceAll
+   * @param bool $doCheckForComponent
+   * @param bool $doCheckForPermissions
+   *
+   * @return mixed
    */
-  public static function getPermissionedCampaigns($includeId = NULL,
+  public static function getPermissionedCampaigns(
+    $includeId = NULL,
     $excludeId = NULL,
     $onlyActive = TRUE,
     $onlyCurrent = TRUE,
@@ -240,8 +262,14 @@ Order By  camp.title";
   ) {
     $cacheKey = 0;
     $cachekeyParams = array(
-      'includeId', 'excludeId', 'onlyActive', 'onlyCurrent',
-      'appendDatesToTitle', 'doCheckForComponent', 'doCheckForPermissions', 'forceAll',
+      'includeId',
+      'excludeId',
+      'onlyActive',
+      'onlyCurrent',
+      'appendDatesToTitle',
+      'doCheckForComponent',
+      'doCheckForPermissions',
+      'forceAll',
     );
     foreach ($cachekeyParams as $param) {
       $cacheKeyParam = $$param;
@@ -254,7 +282,8 @@ Order By  camp.title";
     static $validCampaigns;
     if (!isset($validCampaigns[$cacheKey])) {
       $isValid = TRUE;
-      $campaigns = array('campaigns' => array(),
+      $campaigns = array(
+        'campaigns' => array(),
         'hasAccessCampaign' => FALSE,
         'isCampaignEnabled' => FALSE,
       );
@@ -308,7 +337,6 @@ Order By  camp.title";
   /**
    * Retrieve campaigns for dashboard.
    *
-   * @static
    */
   public static function getCampaignSummary($params = array(), $onlyCount = FALSE) {
     $campaigns = array();
@@ -328,7 +356,6 @@ Order By  camp.title";
         }
       }
 
-
       //need to lookup tables.
       $orderOnCampaignTable = TRUE;
       if ($sortParams['sort'] == 'status') {
@@ -370,13 +397,13 @@ INNER JOIN civicrm_option_group grp ON ( campaign_type.option_group_id = grp.id
       $queryParams[3] = array('%' . trim($params['title']) . '%', 'String');
     }
     if (!empty($params['start_date'])) {
-      $startDate      = CRM_Utils_Date::processDate($params['start_date']);
-      $where[]        = "( campaign.start_date >= %4 OR campaign.start_date IS NULL )";
+      $startDate = CRM_Utils_Date::processDate($params['start_date']);
+      $where[] = "( campaign.start_date >= %4 OR campaign.start_date IS NULL )";
       $queryParams[4] = array($startDate, 'String');
     }
     if (!empty($params['end_date'])) {
-      $endDate        = CRM_Utils_Date::processDate($params['end_date'], '235959');
-      $where[]        = "( campaign.end_date <= %5 OR campaign.end_date IS NULL )";
+      $endDate = CRM_Utils_Date::processDate($params['end_date'], '235959');
+      $where[] = "( campaign.end_date <= %5 OR campaign.end_date IS NULL )";
       $queryParams[5] = array($endDate, 'String');
     }
     if (!empty($params['description'])) {
@@ -440,7 +467,7 @@ SELECT  campaign.id               as id,
 
     //in case of only count.
     if ($onlyCount) {
-      return (int)CRM_Core_DAO::singleValueQuery($query, $queryParams);
+      return (int) CRM_Core_DAO::singleValueQuery($query, $queryParams);
     }
 
     $campaign = CRM_Core_DAO::executeQuery($query, $queryParams);
@@ -456,19 +483,18 @@ SELECT  campaign.id               as id,
   /**
    * Get the campaign count.
    *
-   * @static
    */
   public static function getCampaignCount() {
-    return (int)CRM_Core_DAO::singleValueQuery('SELECT COUNT(*) FROM civicrm_campaign');
+    return (int) CRM_Core_DAO::singleValueQuery('SELECT COUNT(*) FROM civicrm_campaign');
   }
 
   /**
-   * Get Campaigns groups
+   * Get Campaigns groups.
    *
-   * @param int $campaignId campaign id
+   * @param int $campaignId
+   *   Campaign id.
    *
    * @return array
-   * @static
    */
   public static function getCampaignGroups($campaignId) {
     static $campaignGroups;
@@ -497,13 +523,15 @@ INNER JOIN  civicrm_group grp ON ( grp.id = campgrp.entity_id )
   }
 
   /**
-   * 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 boolean  $is_active value we want to set the is_active field
+   * @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 CRM_Campaign_DAO_Campaign|null
+   *   DAO object on sucess, null otherwise
    */
   public static function setIsActive($id, $is_active) {
     return CRM_Core_DAO::setFieldValue('CRM_Campaign_DAO_Campaign', $id, 'is_active', $is_active);
@@ -527,12 +555,10 @@ INNER JOIN  civicrm_group grp ON ( grp.id = campgrp.entity_id )
     return $allow;
   }
 
-  /*
+  /**
    * Add select element for campaign
    * and assign needful info to templates.
    *
-   */
-  /**
    * @param CRM_Core_Form $form
    * @param int $connectedCampaignId
    */
@@ -545,7 +571,9 @@ INNER JOIN  civicrm_group grp ON ( grp.id = campgrp.entity_id )
 
     $campaignDetails = self::getPermissionedCampaigns($connectedCampaignId, NULL, TRUE, TRUE, $appendDates);
     $fields = array('campaigns', 'hasAccessCampaign', 'isCampaignEnabled');
-    foreach ($fields as $fld)$$fld = CRM_Utils_Array::value($fld, $campaignDetails);
+    foreach ($fields as $fld) {
+      $$fld = CRM_Utils_Array::value($fld, $campaignDetails);
+    }
 
     //lets see do we have past campaigns.
     $hasPastCampaigns = FALSE;
@@ -608,28 +636,32 @@ INNER JOIN  civicrm_group grp ON ( grp.id = campgrp.entity_id )
       'includePastCampaignURL',
       'alreadyIncludedPastCampaigns',
     );
-    foreach ($infoFields as $fld) $campaignInfo[$fld] = $$fld;
+    foreach ($infoFields as $fld) {
+      $campaignInfo[$fld] = $$fld;
+    }
     $form->assign('campaignInfo', $campaignInfo);
   }
 
   /**
-   * Add campaign in compoent search.
+   * Add campaign in component search.
    * and assign needful info to templates.
    *
    * @param CRM_Core_Form $form
    * @param string $elementName
    */
   public static function addCampaignInComponentSearch(&$form, $elementName = 'campaign_id') {
-    $campaignInfo    = array();
+    $campaignInfo = array();
     $campaignDetails = self::getPermissionedCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
-    $fields          = array('campaigns', 'hasAccessCampaign', 'isCampaignEnabled');
-    foreach ($fields as $fld)$$fld = CRM_Utils_Array::value($fld, $campaignDetails);
+    $fields = array('campaigns', 'hasAccessCampaign', 'isCampaignEnabled');
+    foreach ($fields as $fld) {
+      $$fld = CRM_Utils_Array::value($fld, $campaignDetails);
+    }
     $showCampaignInSearch = FALSE;
     if ($isCampaignEnabled && $hasAccessCampaign && !empty($campaigns)) {
       //get the current campaign only.
       $currentCampaigns = self::getCampaigns(NULL, NULL, FALSE);
-      $pastCampaigns    = array_diff($campaigns, $currentCampaigns);
-      $allCampaigns     = array();
+      $pastCampaigns = array_diff($campaigns, $currentCampaigns);
+      $allCampaigns = array();
       if (!empty($currentCampaigns)) {
         $allCampaigns = array('crm_optgroup_current_campaign' => ts('Current Campaigns')) + $currentCampaigns;
       }
@@ -648,7 +680,10 @@ INNER JOIN  civicrm_group grp ON ( grp.id = campgrp.entity_id )
       'isCampaignEnabled',
       'showCampaignInSearch',
     );
-    foreach ($infoFields as $fld) $campaignInfo[$fld] = $$fld;
+    foreach ($infoFields as $fld) {
+      $campaignInfo[$fld] = $$fld;
+    }
     $form->assign('campaignInfo', $campaignInfo);
   }
+
 }