Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
6b83d5bd | 31 | * @copyright CiviCRM LLC (c) 2004-2019 |
6a488035 | 32 | */ |
4b4a10d3 | 33 | class CRM_Mailing_Form_Search extends CRM_Core_Form_Search { |
34 | ||
35 | /** | |
36 | * Get the default entity being queried. | |
37 | * | |
38 | * @return string | |
39 | */ | |
40 | public function getDefaultEntity() { | |
41 | return 'Mailing'; | |
42 | } | |
6a488035 TO |
43 | |
44 | public function preProcess() { | |
45 | parent::preProcess(); | |
46 | } | |
47 | ||
48 | public function buildQuickForm() { | |
49 | $parent = $this->controller->getParent(); | |
50 | $nameTextLabel = ($parent->_sms) ? ts('SMS Name') : ts('Mailing Name'); | |
51 | ||
52 | $this->add('text', 'mailing_name', $nameTextLabel, | |
53 | CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'title') | |
54 | ); | |
55 | ||
6de4fe34 SL |
56 | $dateFieldLabel = ($parent->_sms) ? ts('SMS Date') : ts('Mailing Date'); |
57 | $this->addDatePickerRange('mailing', $dateFieldLabel); | |
6a488035 TO |
58 | |
59 | $this->add('text', 'sort_name', ts('Created or Sent by'), | |
60 | CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name') | |
61 | ); | |
62 | ||
63 | CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this); | |
64 | ||
d4ad3b22 | 65 | // CRM-15434 - Fix mailing search by status in non-English languages |
7236e25f | 66 | $statusVals = CRM_Core_SelectValues::getMailingJobStatus(); |
d4ad3b22 | 67 | foreach ($statusVals as $statusId => $statusName) { |
68 | $this->addElement('checkbox', "mailing_status[$statusId]", NULL, $statusName); | |
6a488035 | 69 | } |
7ccbe556 | 70 | $this->addElement('checkbox', 'status_unscheduled', NULL, ts('Draft / Unscheduled')); |
8a4f27dc | 71 | $this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE); |
f6df2c32 | 72 | |
c00b95ef ML |
73 | // Search by language, if multi-lingual |
74 | $enabledLanguages = CRM_Core_I18n::languages(TRUE); | |
75 | ||
76 | if (count($enabledLanguages) > 1) { | |
be2fb01f | 77 | $this->addElement('select', 'language', ts('Language'), ['' => ts('- all languages -')] + $enabledLanguages, ['class' => 'crm-select2']); |
c00b95ef ML |
78 | } |
79 | ||
6a488035 TO |
80 | if ($parent->_sms) { |
81 | $this->addElement('hidden', 'sms', $parent->_sms); | |
82 | } | |
f5d7a1ab | 83 | $this->add('hidden', 'hidden_find_mailings', 1); |
6a488035 | 84 | |
be2fb01f CW |
85 | $this->addButtons([ |
86 | [ | |
353ffa53 TO |
87 | 'type' => 'refresh', |
88 | 'name' => ts('Search'), | |
89 | 'isDefault' => TRUE, | |
be2fb01f CW |
90 | ], |
91 | ]); | |
6a488035 TO |
92 | } |
93 | ||
e0ef6999 EM |
94 | /** |
95 | * @return array | |
96 | */ | |
00be9182 | 97 | public function setDefaultValues() { |
be2fb01f | 98 | $defaults = $statusVals = []; |
cbb4cb7b PJ |
99 | $parent = $this->controller->getParent(); |
100 | ||
f6df2c32 DS |
101 | if ($parent->get('unscheduled')) { |
102 | $defaults['status_unscheduled'] = 1; | |
103 | } | |
f6df2c32 | 104 | if ($parent->get('scheduled')) { |
67d4ed51 | 105 | $statusVals = array_keys(CRM_Core_SelectValues::getMailingJobStatus()); |
f6df2c32 DS |
106 | $defaults['is_archived'] = 0; |
107 | } | |
f6df2c32 DS |
108 | if ($parent->get('archived')) { |
109 | $defaults['is_archived'] = 1; | |
6a488035 | 110 | } |
6ff6d85a DS |
111 | foreach ($statusVals as $status) { |
112 | $defaults['mailing_status'][$status] = 1; | |
113 | } | |
6a488035 | 114 | |
6a488035 TO |
115 | if ($parent->_sms) { |
116 | $defaults['sms'] = 1; | |
117 | } | |
118 | return $defaults; | |
119 | } | |
120 | ||
00be9182 | 121 | public function postProcess() { |
6a488035 TO |
122 | $params = $this->controller->exportValues($this->_name); |
123 | ||
6de4fe34 SL |
124 | if (!empty($params['mailing_relative'])) { |
125 | list($params['mailing_low'], $params['mailing_high']) = CRM_Utils_Date::getFromTo($params['mailing_relative'], $params['mailing_low'], $params['mailing_high']); | |
126 | unset($params['mailing_relative']); | |
127 | } | |
128 | elseif (!empty($params['mailing_high'])) { | |
129 | $params['mailing_high'] .= ' ' . '23:59:59'; | |
130 | } | |
6a488035 TO |
131 | |
132 | $parent = $this->controller->getParent(); | |
133 | if (!empty($params)) { | |
be2fb01f | 134 | $fields = [ |
353ffa53 | 135 | 'mailing_name', |
6de4fe34 SL |
136 | 'mailing_low', |
137 | 'mailing_high', | |
353ffa53 TO |
138 | 'sort_name', |
139 | 'campaign_id', | |
140 | 'mailing_status', | |
141 | 'sms', | |
142 | 'status_unscheduled', | |
143 | 'is_archived', | |
c00b95ef | 144 | 'language', |
795492f3 | 145 | 'hidden_find_mailings', |
be2fb01f | 146 | ]; |
6a488035 TO |
147 | foreach ($fields as $field) { |
148 | if (isset($params[$field]) && | |
149 | !CRM_Utils_System::isNull($params[$field]) | |
150 | ) { | |
6de4fe34 | 151 | $parent->set($field, $params[$field]); |
6a488035 TO |
152 | } |
153 | else { | |
154 | $parent->set($field, NULL); | |
155 | } | |
156 | } | |
157 | } | |
158 | } | |
96025800 | 159 | |
6a488035 | 160 | } |