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_Search
{
36 * Get the default entity being queried.
40 public function getDefaultEntity() {
44 public function preProcess() {
48 public function buildQuickForm() {
49 $parent = $this->controller
->getParent();
50 $nameTextLabel = ($parent->_sms
) ?
ts('SMS Name') : ts('Mailing Name');
52 $this->add('text', 'mailing_name', $nameTextLabel,
53 CRM_Core_DAO
::getAttribute('CRM_Mailing_DAO_Mailing', 'title')
56 $dateFieldLabel = ($parent->_sms
) ?
ts('SMS Date') : ts('Mailing Date');
57 $this->addDatePickerRange('mailing', $dateFieldLabel);
59 $this->add('text', 'sort_name', ts('Created or Sent by'),
60 CRM_Core_DAO
::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
63 CRM_Campaign_BAO_Campaign
::addCampaignInComponentSearch($this);
65 // CRM-15434 - Fix mailing search by status in non-English languages
66 $statusVals = CRM_Core_SelectValues
::getMailingJobStatus();
67 foreach ($statusVals as $statusId => $statusName) {
68 $this->addElement('checkbox', "mailing_status[$statusId]", NULL, $statusName);
70 $this->addElement('checkbox', 'status_unscheduled', NULL, ts('Draft / Unscheduled'));
71 $this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE);
73 // Search by language, if multi-lingual
74 $enabledLanguages = CRM_Core_I18n
::languages(TRUE);
76 if (count($enabledLanguages) > 1) {
77 $this->addElement('select', 'language', ts('Language'), ['' => ts('- all languages -')] +
$enabledLanguages, ['class' => 'crm-select2']);
81 $this->addElement('hidden', 'sms', $parent->_sms
);
83 $this->add('hidden', 'hidden_find_mailings', 1);
88 'name' => ts('Search'),
97 public function setDefaultValues() {
98 $defaults = $statusVals = [];
99 $parent = $this->controller
->getParent();
101 if ($parent->get('unscheduled')) {
102 $defaults['status_unscheduled'] = 1;
104 if ($parent->get('scheduled')) {
105 $statusVals = array_keys(CRM_Core_SelectValues
::getMailingJobStatus());
106 $defaults['is_archived'] = 0;
108 if ($parent->get('archived')) {
109 $defaults['is_archived'] = 1;
111 foreach ($statusVals as $status) {
112 $defaults['mailing_status'][$status] = 1;
116 $defaults['sms'] = 1;
121 public function postProcess() {
122 $params = $this->controller
->exportValues($this->_name
);
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']);
128 elseif (!empty($params['mailing_high'])) {
129 $params['mailing_high'] .= ' ' . '23:59:59';
132 $parent = $this->controller
->getParent();
133 if (!empty($params)) {
142 'status_unscheduled',
145 'hidden_find_mailings',
147 foreach ($fields as $field) {
148 if (isset($params[$field]) &&
149 !CRM_Utils_System
::isNull($params[$field])
151 $parent->set($field, $params[$field]);
154 $parent->set($field, NULL);