Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core/dev#692 : Support search arguments to Mailing Search form #15369

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions CRM/Mailing/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public static function select(&$query) {
* rather than a static function.
*/
public static function getSearchFieldMetadata() {
$fields = ['mailing_job_start_date'];
$fields = ['mailing_name', 'mailing_job_start_date', 'mailing_job_status', 'is_archived'];
$metadata = civicrm_api3('Mailing', 'getfields', [])['values'];
$metadata = array_merge($metadata, civicrm_api3('MailingJob', 'getfields', [])['values']);
return array_intersect_key($metadata, array_flip($fields));
Expand Down Expand Up @@ -258,13 +258,16 @@ public static function whereClauseSingle(&$values, &$query) {

case 'mailing_name':
$value = addslashes($value);
if ($wildcard) {
$value = "%$value%";
$op = 'LIKE';
}

$query->_where[$grouping][] = "civicrm_mailing.name $op '$value'";
$query->_qill[$grouping][] = "Mailing Namename $op \"$value\"";
$name = 'name';
$query->_where[$grouping][] = CRM_Contact_BAO_Query::buildClause("civicrm_mailing.$name", $op, $value, 'String');
list($op, $value) = CRM_Contact_BAO_Query::buildQillForFieldValue('CRM_Mailing_DAO_Mailing', $name, $value, $op);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We haven't made it generic to the other forms yet - but we started making the qill handling generic - would need some moving around

bf99326

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also note that we have a getFields() function on Contribution_BAO_Query $fields = self::getFields(); & are working towards using that metadata for the various bits of value


$query->_qill[$grouping][] = ts('%1 %2 %3', [
1 => ts('Mailing Name'),
2 => $op,
3 => $value,
]);
$query->_tables['civicrm_mailing'] = $query->_whereTables['civicrm_mailing'] = 1;
$query->_tables['civicrm_mailing_recipients'] = $query->_whereTables['civicrm_mailing_recipients'] = 1;
return;
Expand Down Expand Up @@ -399,7 +402,6 @@ public static function buildSearchForm(&$form) {

// mailing selectors
$mailings = CRM_Mailing_BAO_Mailing::getMailingsList();

if (!empty($mailings)) {
$form->add('select', 'mailing_id', ts('Mailing Name(s)'), $mailings, FALSE,
['id' => 'mailing_id', 'multiple' => 'multiple', 'class' => 'crm-select2']
Expand All @@ -413,7 +415,9 @@ public static function buildSearchForm(&$form) {
'Running' => 'Running',
'Canceled' => 'Canceled',
];
$form->addElement('select', 'mailing_job_status', ts('Mailing Job Status'), $mailingJobStatuses, FALSE);
$form->add('select', 'mailing_job_status', ts('Mailing Job Status'), $mailingJobStatuses, FALSE,
['id' => 'mailing_job_status', 'multiple' => 'multiple', 'class' => 'crm-select2']
);

$mailingBounceTypes = CRM_Core_PseudoConstant::get(
'CRM_Mailing_Event_DAO_Bounce', 'bounce_type_id',
Expand Down
61 changes: 32 additions & 29 deletions CRM/Mailing/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,27 @@ public function getDefaultEntity() {

public function preProcess() {
parent::preProcess();
$this->loadStandardSearchOptionsFromUrl();
if ($this->_force) {
$this->_formValues = $this->getEntityDefaults($this->getDefaultEntity());
$this->postProcess();
}
}

public function buildQuickForm() {
$parent = $this->controller->getParent();
$nameTextLabel = ($parent->_sms) ? ts('SMS Name') : ts('Mailing Name');

$this->add('text', 'mailing_name', $nameTextLabel,
CRM_Core_DAO::getAttribute('CRM_Mailing_DAO_Mailing', 'title')
);

$dateFieldLabel = ($parent->_sms) ? ts('SMS Date') : ts('Mailing Date');
$this->addDatePickerRange('mailing', $dateFieldLabel);

$this->add('text', 'sort_name', ts('Created or Sent by'),
CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name')
);
$this->addSortNameField();

CRM_Mailing_BAO_Query::buildSearchForm($this);

CRM_Campaign_BAO_Campaign::addCampaignInComponentSearch($this);

// CRM-15434 - Fix mailing search by status in non-English languages
$statusVals = CRM_Core_SelectValues::getMailingJobStatus();
foreach ($statusVals as $statusId => $statusName) {
$this->addElement('checkbox', "mailing_status[$statusId]", NULL, $statusName);
}
$this->addElement('checkbox', 'status_unscheduled', NULL, ts('Draft / Unscheduled'));
$this->addYesNo('is_archived', ts('Mailing is Archived'), TRUE);

// Search by language, if multi-lingual
$enabledLanguages = CRM_Core_I18n::languages(TRUE);
Expand All @@ -79,31 +74,39 @@ public function buildQuickForm() {
* @return array
*/
public function setDefaultValues() {
$defaults = $statusVals = [];
$defaults = [];
$parent = $this->controller->getParent();

if ($parent->get('unscheduled')) {
$defaults['status_unscheduled'] = 1;
}
if ($parent->get('scheduled')) {
$statusVals = array_keys(CRM_Core_SelectValues::getMailingJobStatus());
$defaults['is_archived'] = 0;
}
if ($parent->get('archived')) {
$defaults['is_archived'] = 1;
}
foreach ($statusVals as $status) {
$defaults['mailing_status'][$status] = 1;
if ($this->_force) {
$this->_formValues = $defaults = $this->getEntityDefaults($this->getDefaultEntity());
}
else {
if ($parent->get('unscheduled')) {
$defaults['status_unscheduled'] = 1;
}
if ($parent->get('scheduled')) {
$defaults['mailing_job_status'] = array_keys(CRM_Core_SelectValues::getMailingJobStatus());
$defaults['is_archived'] = 0;
}
if ($parent->get('archived')) {
$defaults['is_archived'] = 1;
}

if ($parent->_sms) {
$defaults['sms'] = 1;
if ($parent->_sms) {
$defaults['sms'] = 1;
}
}

return $defaults;
}

public function postProcess() {
$params = $this->controller->exportValues($this->_name);
if (!empty($this->_force)) {
$params = $this->getEntityDefaults($this->getDefaultEntity());
}
else {
$params = $this->controller->exportValues($this->_name);
}

if (!empty($params['mailing_relative'])) {
list($params['mailing_low'], $params['mailing_high']) = CRM_Utils_Date::getFromTo($params['mailing_relative'], $params['mailing_low'], $params['mailing_high']);
Expand Down
13 changes: 2 additions & 11 deletions templates/CRM/Mailing/Form/Search.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,9 @@
{$form.is_archived.html}
</div>
</td>
{if $form.mailing_status}
{if $form.mailing_job_status}
<td width="100%"><label>{if $sms eq 1}{ts}SMS Status{/ts}{else}{ts}Mailing Status{/ts}{/if}</label><br />
<div class="listing-box" style="height: auto">
{foreach from=$form.mailing_status item="mailing_status_val"}
<div class="{cycle values="odd-row,even-row"}">
{$mailing_status_val.html}
</div>
{/foreach}
<div class="{cycle values="odd-row,even-row"}">
{$form.status_unscheduled.html}
</div>
</div><br />
{$form.mailing_job_status.html|crmAddClass:big}
</td>
{/if}
</tr>
Expand Down