| 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
- * @access public
- * @static
+ * @return CRM_Campaign_DAO_Campaign
*/
public static function create(&$params) {
if (empty($params)) {
- return;
+ return NULL;
}
if (!(CRM_Utils_Array::value('id', $params))) {
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();
}
}
/**
- * Delete the campaign
+ * Delete the campaign.
*
- * @param int $id id of the campaign
+ * @param int $id
+ * Id of the campaign.
*
* @return bool|mixed
*/
}
/**
- * 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
- * @access public
*/
public function retrieve(&$params, &$defaults) {
$campaign = new 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;
* 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,
) {
$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;
static $validCampaigns;
if (!isset($validCampaigns[$cacheKey])) {
$isValid = TRUE;
- $campaigns = array('campaigns' => array(),
+ $campaigns = array(
+ 'campaigns' => array(),
'hasAccessCampaign' => FALSE,
'isCampaignEnabled' => FALSE,
);
/**
* Retrieve campaigns for dashboard.
*
- * @static
*/
public static function getCampaignSummary($params = array(), $onlyCount = FALSE) {
$campaigns = array();
}
}
-
//need to lookup tables.
$orderOnCampaignTable = TRUE;
if ($sortParams['sort'] == 'status') {
$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'])) {
//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);
/**
* 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;
}
/**
- * 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);
return $allow;
}
- /*
+ /**
* Add select element for campaign
* and assign needful info to templates.
*
- */
- /**
* @param CRM_Core_Form $form
* @param int $connectedCampaignId
*/
$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;
'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;
}
'isCampaignEnabled',
'showCampaignInSearch',
);
- foreach ($infoFields as $fld) $campaignInfo[$fld] = $$fld;
+ foreach ($infoFields as $fld) {
+ $campaignInfo[$fld] = $$fld;
+ }
$form->assign('campaignInfo', $campaignInfo);
}
-}
+}