3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2019
33 class CRM_Mailing_Form_Search
extends CRM_Core_Form
{
35 public function preProcess() {
39 public function buildQuickForm() {
40 $parent = $this->controller
->getParent();
41 $nameTextLabel = ($parent->_sms
) ?
ts('SMS Name') : ts('Mailing Name');
43 $this->add('text', 'mailing_name', $nameTextLabel,
44 CRM_Core_DAO
::getAttribute('CRM_Mailing_DAO_Mailing', 'title')
47 $dateFieldLabel = ($parent->_sms
) ?
ts('SMS Date') : ts('Mailing Date');
48 $this->addDatePickerRange('mailing', $dateFieldLabel);
50 $this->add('text', 'sort_name', ts('Created or Sent by'),
51 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
54 CRM_Campaign_BAO_Campaign
::addCampaignInComponentSearch($this);
56 // CRM-15434 - Fix mailing search by status in non-English languages
57 $statusVals = CRM_Core_SelectValues
::getMailingJobStatus();
58 foreach ($statusVals as $statusId => $statusName) {
59 $this->addElement('checkbox', "mailing_status[$statusId]", NULL, $statusName);
61 $this->addElement('checkbox', 'status_unscheduled', NULL, ts('Draft / Unscheduled'));
62 $this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE);
64 // Search by language, if multi-lingual
65 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
67 if (count($enabledLanguages) > 1) {
68 $this->addElement('select', 'language', ts('Language'), ['' => ts('- all languages -')] +
$enabledLanguages, ['class' => 'crm-select2']);
72 $this->addElement('hidden', 'sms', $parent->_sms
);
74 $this->add('hidden', 'hidden_find_mailings', 1);
79 'name' => ts('Search'),
88 public function setDefaultValues() {
89 $defaults = $statusVals = [];
90 $parent = $this->controller
->getParent();
92 if ($parent->get('unscheduled')) {
93 $defaults['status_unscheduled'] = 1;
95 if ($parent->get('scheduled')) {
96 $statusVals = array_keys(CRM_Core_SelectValues
::getMailingJobStatus());
97 $defaults['is_archived'] = 0;
99 if ($parent->get('archived')) {
100 $defaults['is_archived'] = 1;
102 foreach ($statusVals as $status) {
103 $defaults['mailing_status'][$status] = 1;
107 $defaults['sms'] = 1;
112 public function postProcess() {
113 $params = $this->controller
->exportValues($this->_name
);
115 if (!empty($params['mailing_relative'])) {
116 list($params['mailing_low'], $params['mailing_high']) = CRM_Utils_Date
::getFromTo($params['mailing_relative'], $params['mailing_low'], $params['mailing_high']);
117 unset($params['mailing_relative']);
119 elseif (!empty($params['mailing_high'])) {
120 $params['mailing_high'] .= ' ' . '23:59:59';
123 $parent = $this->controller
->getParent();
124 if (!empty($params)) {
133 'status_unscheduled',
136 'hidden_find_mailings',
138 foreach ($fields as $field) {
139 if (isset($params[$field]) &&
140 !CRM_Utils_System
::isNull($params[$field])
142 $parent->set($field, $params[$field]);
145 $parent->set($field, NULL);