Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
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 | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 | 16 | */ |
4b4a10d3 | 17 | class CRM_Mailing_Form_Search extends CRM_Core_Form_Search { |
18 | ||
19 | /** | |
20 | * Get the default entity being queried. | |
21 | * | |
22 | * @return string | |
23 | */ | |
24 | public function getDefaultEntity() { | |
25 | return 'Mailing'; | |
26 | } | |
6a488035 TO |
27 | |
28 | public function preProcess() { | |
29 | parent::preProcess(); | |
30 | } | |
31 | ||
32 | public function buildQuickForm() { | |
33 | $parent = $this->controller->getParent(); | |
34 | $nameTextLabel = ($parent->_sms) ? ts('SMS Name') : ts('Mailing Name'); | |
35 | ||
36 | $this->add('text', 'mailing_name', $nameTextLabel, | |
37 | CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'title') | |
38 | ); | |
39 | ||
6de4fe34 SL |
40 | $dateFieldLabel = ($parent->_sms) ? ts('SMS Date') : ts('Mailing Date'); |
41 | $this->addDatePickerRange('mailing', $dateFieldLabel); | |
6a488035 TO |
42 | |
43 | $this->add('text', 'sort_name', ts('Created or Sent by'), | |
44 | CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name') | |
45 | ); | |
46 | ||
47 | CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this); | |
48 | ||
d4ad3b22 | 49 | // CRM-15434 - Fix mailing search by status in non-English languages |
7236e25f | 50 | $statusVals = CRM_Core_SelectValues::getMailingJobStatus(); |
d4ad3b22 | 51 | foreach ($statusVals as $statusId => $statusName) { |
52 | $this->addElement('checkbox', "mailing_status[$statusId]", NULL, $statusName); | |
6a488035 | 53 | } |
7ccbe556 | 54 | $this->addElement('checkbox', 'status_unscheduled', NULL, ts('Draft / Unscheduled')); |
8a4f27dc | 55 | $this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE); |
f6df2c32 | 56 | |
c00b95ef ML |
57 | // Search by language, if multi-lingual |
58 | $enabledLanguages = CRM_Core_I18n::languages(TRUE); | |
59 | ||
60 | if (count($enabledLanguages) > 1) { | |
be2fb01f | 61 | $this->addElement('select', 'language', ts('Language'), ['' => ts('- all languages -')] + $enabledLanguages, ['class' => 'crm-select2']); |
c00b95ef ML |
62 | } |
63 | ||
6a488035 TO |
64 | if ($parent->_sms) { |
65 | $this->addElement('hidden', 'sms', $parent->_sms); | |
66 | } | |
f5d7a1ab | 67 | $this->add('hidden', 'hidden_find_mailings', 1); |
6a488035 | 68 | |
be2fb01f CW |
69 | $this->addButtons([ |
70 | [ | |
353ffa53 TO |
71 | 'type' => 'refresh', |
72 | 'name' => ts('Search'), | |
73 | 'isDefault' => TRUE, | |
be2fb01f CW |
74 | ], |
75 | ]); | |
6a488035 TO |
76 | } |
77 | ||
e0ef6999 EM |
78 | /** |
79 | * @return array | |
80 | */ | |
00be9182 | 81 | public function setDefaultValues() { |
be2fb01f | 82 | $defaults = $statusVals = []; |
cbb4cb7b PJ |
83 | $parent = $this->controller->getParent(); |
84 | ||
f6df2c32 DS |
85 | if ($parent->get('unscheduled')) { |
86 | $defaults['status_unscheduled'] = 1; | |
87 | } | |
f6df2c32 | 88 | if ($parent->get('scheduled')) { |
67d4ed51 | 89 | $statusVals = array_keys(CRM_Core_SelectValues::getMailingJobStatus()); |
f6df2c32 DS |
90 | $defaults['is_archived'] = 0; |
91 | } | |
f6df2c32 DS |
92 | if ($parent->get('archived')) { |
93 | $defaults['is_archived'] = 1; | |
6a488035 | 94 | } |
6ff6d85a DS |
95 | foreach ($statusVals as $status) { |
96 | $defaults['mailing_status'][$status] = 1; | |
97 | } | |
6a488035 | 98 | |
6a488035 TO |
99 | if ($parent->_sms) { |
100 | $defaults['sms'] = 1; | |
101 | } | |
102 | return $defaults; | |
103 | } | |
104 | ||
00be9182 | 105 | public function postProcess() { |
6a488035 TO |
106 | $params = $this->controller->exportValues($this->_name); |
107 | ||
6de4fe34 SL |
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']); | |
111 | } | |
112 | elseif (!empty($params['mailing_high'])) { | |
113 | $params['mailing_high'] .= ' ' . '23:59:59'; | |
114 | } | |
6a488035 TO |
115 | |
116 | $parent = $this->controller->getParent(); | |
117 | if (!empty($params)) { | |
be2fb01f | 118 | $fields = [ |
353ffa53 | 119 | 'mailing_name', |
6de4fe34 SL |
120 | 'mailing_low', |
121 | 'mailing_high', | |
353ffa53 TO |
122 | 'sort_name', |
123 | 'campaign_id', | |
124 | 'mailing_status', | |
125 | 'sms', | |
126 | 'status_unscheduled', | |
127 | 'is_archived', | |
c00b95ef | 128 | 'language', |
795492f3 | 129 | 'hidden_find_mailings', |
be2fb01f | 130 | ]; |
6a488035 TO |
131 | foreach ($fields as $field) { |
132 | if (isset($params[$field]) && | |
133 | !CRM_Utils_System::isNull($params[$field]) | |
134 | ) { | |
6de4fe34 | 135 | $parent->set($field, $params[$field]); |
6a488035 TO |
136 | } |
137 | else { | |
138 | $parent->set($field, NULL); | |
139 | } | |
140 | } | |
141 | } | |
142 | } | |
96025800 | 143 | |
6a488035 | 144 | } |