3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Mailing_Form_Search
extends CRM_Core_Form_Search
{
20 * Get the default entity being queried.
24 public function getDefaultEntity() {
28 public function preProcess() {
32 public function buildQuickForm() {
33 $parent = $this->controller
->getParent();
34 $nameTextLabel = ($parent->_sms
) ?
ts('SMS Name') : ts('Mailing Name');
36 $this->add('text', 'mailing_name', $nameTextLabel,
37 CRM_Core_DAO
::getAttribute('CRM_Mailing_DAO_Mailing', 'title')
40 $dateFieldLabel = ($parent->_sms
) ?
ts('SMS Date') : ts('Mailing Date');
41 $this->addDatePickerRange('mailing', $dateFieldLabel);
43 $this->add('text', 'sort_name', ts('Created or Sent by'),
44 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
47 CRM_Campaign_BAO_Campaign
::addCampaignInComponentSearch($this);
49 // CRM-15434 - Fix mailing search by status in non-English languages
50 $statusVals = CRM_Core_SelectValues
::getMailingJobStatus();
51 foreach ($statusVals as $statusId => $statusName) {
52 $this->addElement('checkbox', "mailing_status[$statusId]", NULL, $statusName);
54 $this->addElement('checkbox', 'status_unscheduled', NULL, ts('Draft / Unscheduled'));
55 $this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE);
57 // Search by language, if multi-lingual
58 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
60 if (count($enabledLanguages) > 1) {
61 $this->addElement('select', 'language', ts('Language'), ['' => ts('- all languages -')] +
$enabledLanguages, ['class' => 'crm-select2']);
65 $this->addElement('hidden', 'sms', $parent->_sms
);
67 $this->add('hidden', 'hidden_find_mailings', 1);
72 'name' => ts('Search'),
81 public function setDefaultValues() {
82 $defaults = $statusVals = [];
83 $parent = $this->controller
->getParent();
85 if ($parent->get('unscheduled')) {
86 $defaults['status_unscheduled'] = 1;
88 if ($parent->get('scheduled')) {
89 $statusVals = array_keys(CRM_Core_SelectValues
::getMailingJobStatus());
90 $defaults['is_archived'] = 0;
92 if ($parent->get('archived')) {
93 $defaults['is_archived'] = 1;
95 foreach ($statusVals as $status) {
96 $defaults['mailing_status'][$status] = 1;
100 $defaults['sms'] = 1;
105 public function postProcess() {
106 $params = $this->controller
->exportValues($this->_name
);
108 if (!empty($params['mailing_relative'])) {
109 list($params['mailing_low'], $params['mailing_high']) = CRM_Utils_Date
::getFromTo($params['mailing_relative'], $params['mailing_low'], $params['mailing_high']);
110 unset($params['mailing_relative']);
112 elseif (!empty($params['mailing_high'])) {
113 $params['mailing_high'] .= ' ' . '23:59:59';
116 $parent = $this->controller
->getParent();
117 if (!empty($params)) {
126 'status_unscheduled',
129 'hidden_find_mailings',
131 foreach ($fields as $field) {
132 if (isset($params[$field]) &&
133 !CRM_Utils_System
::isNull($params[$field])
135 $parent->set($field, $params[$field]);
138 $parent->set($field, NULL);