$dao->entity_id = $entityId;
$dao->group_type = 'Include';
$dao->save();
- $dao->free();
}
}
$$fld = CRM_Utils_Array::value($fld, $campaignDetails);
}
- //lets see do we have past campaigns.
- $hasPastCampaigns = FALSE;
- $allActiveCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, TRUE, FALSE);
- if (count($allActiveCampaigns) > count($campaigns)) {
- $hasPastCampaigns = TRUE;
- }
- $hasCampaigns = FALSE;
- if (!empty($campaigns)) {
- $hasCampaigns = TRUE;
- }
- if ($hasPastCampaigns) {
- $hasCampaigns = TRUE;
- $form->add('hidden', 'included_past_campaigns');
- }
-
$showAddCampaign = FALSE;
- $alreadyIncludedPastCampaigns = FALSE;
if ($connectedCampaignId || ($isCampaignEnabled && $hasAccessCampaign)) {
$showAddCampaign = TRUE;
- //lets add past campaigns as options to quick-form element.
- if ($hasPastCampaigns && $form->getElementValue('included_past_campaigns')) {
- $campaigns = $allActiveCampaigns;
- $alreadyIncludedPastCampaigns = TRUE;
- }
- $campaign = &$form->add('select',
- 'campaign_id',
- ts('Campaign'),
- array('' => ts('- select -')) + $campaigns,
- FALSE,
- array('class' => 'crm-select2')
- );
+ $campaign = $form->addEntityRef('campaign_id', ts('Campaign'), [
+ 'entity' => 'Campaign',
+ 'create' => TRUE,
+ 'select' => ['minimumInputLength' => 0],
+ ]);
//lets freeze when user does not has access or campaign is disabled.
if (!$isCampaignEnabled || !$hasAccessCampaign) {
$campaign->freeze();
}
}
- $addCampaignURL = NULL;
- if (empty($campaigns) && $hasAccessCampaign && $isCampaignEnabled) {
- $addCampaignURL = CRM_Utils_System::url('civicrm/campaign/add', 'reset=1');
- }
-
- $includePastCampaignURL = NULL;
- if ($hasPastCampaigns && $isCampaignEnabled && $hasAccessCampaign) {
- $includePastCampaignURL = CRM_Utils_System::url('civicrm/ajax/rest',
- 'className=CRM_Campaign_Page_AJAX&fnName=allActiveCampaigns',
- FALSE, NULL, FALSE
- );
- }
-
//carry this info to templates.
$infoFields = array(
- 'hasCampaigns',
- 'addCampaignURL',
'showAddCampaign',
- 'hasPastCampaigns',
'hasAccessCampaign',
'isCampaignEnabled',
- 'includePastCampaignURL',
- 'alreadyIncludedPastCampaigns',
);
foreach ($infoFields as $fld) {
$campaignInfo[$fld] = $$fld;
$form->assign('campaignInfo', $campaignInfo);
}
+ /**
+ * @return array
+ */
+ public static function getEntityRefFilters() {
+ return [
+ ['key' => 'campaign_type_id', 'value' => ts('Campaign Type')],
+ ['key' => 'status_id', 'value' => ts('Status')],
+ [
+ 'key' => 'start_date',
+ 'value' => ts('Start Date'),
+ 'options' => [
+ ['key' => '{">":"now"}', 'value' => ts('Upcoming')],
+ [
+ 'key' => '{"BETWEEN":["now - 3 month","now"]}',
+ 'value' => ts('Past 3 Months'),
+ ],
+ [
+ 'key' => '{"BETWEEN":["now - 6 month","now"]}',
+ 'value' => ts('Past 6 Months'),
+ ],
+ [
+ 'key' => '{"BETWEEN":["now - 1 year","now"]}',
+ 'value' => ts('Past Year'),
+ ],
+ ],
+ ],
+ [
+ 'key' => 'end_date',
+ 'value' => ts('End Date'),
+ 'options' => [
+ ['key' => '{">":"now"}', 'value' => ts('In the future')],
+ ['key' => '{"<":"now"}', 'value' => ts('In the past')],
+ ['key' => '{"IS NULL":"1"}', 'value' => ts('Not set')],
+ ],
+ ],
+ ];
+ }
+
/**
* Links to create new campaigns from entityRef widget
*
* @return array|bool
*/
- public static function entityRefCreateLinks() {
+ public static function getEntityRefCreateLinks() {
if (CRM_Core_Permission::check([['administer CiviCampaign', 'manage campaign']])) {
return [
[