3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * This class is used to retrieve and display a range of
20 * contacts that match the given criteria (specifically for
21 * results of advanced search options.
23 class CRM_Mailing_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
26 * This defines two actions- View and Edit.
30 public static $_links = NULL;
33 * We use desc to remind us what that column is, name is used in the tpl
37 public static $_columnHeaders;
40 * Properties of contact we're interested in displaying
43 public static $_properties = [
54 'mailing_job_end_date',
58 * Are we restricting ourselves to a single contact
62 protected $_single = FALSE;
65 * Are we restricting ourselves to a single contact
69 protected $_limit = NULL;
72 * What context are we being invoked from
76 protected $_context = NULL;
79 * What component context are we being invoked from
83 protected $_compContext = NULL;
86 * QueryParams is the array returned by exportValues called on
87 * the HTML_QuickForm_Controller for that page.
94 * Represent the type of selector.
101 * The additional clause that we restrict the search with.
105 protected $_mailingClause = NULL;
117 * @param array $queryParams
118 * Array of parameters for query.
119 * @param \const|int $action - action of search basic or advanced.
120 * @param string $mailingClause
121 * If the caller wants to further restrict the search.
122 * @param bool $single
123 * Are we dealing only with one contact?.
125 * How many mailing do we want returned.
127 * @param string $context
128 * @param null $compContext
130 * @return \CRM_Mailing_Selector_Search
132 public function __construct(
134 $action = CRM_Core_Action
::NONE
,
135 $mailingClause = NULL,
141 // submitted form values
142 $this->_queryParams
= &$queryParams;
144 $this->_single
= $single;
145 $this->_limit
= $limit;
146 $this->_context
= $context;
147 $this->_compContext
= $compContext;
149 $this->_mailingClause
= $mailingClause;
152 $this->_action
= $action;
153 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
154 CRM_Mailing_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MAILING
,
158 CRM_Contact_BAO_Query
::MODE_MAILING
161 $this->_query
->_distinctComponentClause
= " civicrm_mailing_recipients.id ";
165 * This method returns the links that are given for each search row.
166 * currently the links added for each row are
173 public static function &links() {
174 if (!(self
::$_links)) {
175 list($context, $key) = func_get_args();
176 $extraParams = ($key) ?
"&key={$key}" : NULL;
177 $searchContext = ($context) ?
"&context=$context" : NULL;
180 CRM_Core_Action
::VIEW
=> [
181 'name' => ts('View'),
182 'url' => 'civicrm/contact/view',
183 'qs' => "reset=1&cid=%%cid%%{$searchContext}{$extraParams}",
184 'title' => ts('View Contact Details'),
186 CRM_Core_Action
::UPDATE
=> [
187 'name' => ts('Edit'),
188 'url' => 'civicrm/contact/add',
189 'qs' => "reset=1&action=update&cid=%%cid%%{$searchContext}{$extraParams}",
190 'title' => ts('Edit Contact Details'),
192 CRM_Core_Action
::DELETE
=> [
193 'name' => ts('Delete'),
194 'url' => 'civicrm/contact/view/delete',
195 'qs' => "reset=1&delete=1&cid=%%cid%%{$searchContext}{$extraParams}",
196 'title' => ts('Delete Contact'),
200 return self
::$_links;
204 * Getter for array of the parameters required for creating pager.
207 * @param array $params
209 public function getPagerParams($action, &$params) {
210 $params['status'] = ts('Mailing Recipient') . ' %%StatusMessage%%';
211 $params['csvString'] = NULL;
213 $params['rowCount'] = $this->_limit
;
216 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
219 $params['buttonTop'] = 'PagerTopButton';
220 $params['buttonBottom'] = 'PagerBottomButton';
224 * Returns total number of rows for the query.
226 * @param string $action
229 * Total number of rows
231 public function getTotalCount($action) {
232 return $this->_query
->searchQuery(0, 0, NULL,
236 $this->_mailingClause
241 * Returns all the rows in the given offset and rowCount.
243 * @param string $action
244 * The action being performed.
246 * The row number to start from.
247 * @param int $rowCount
248 * The number of rows to return.
249 * @param string $sort
250 * The sql string that describes the sort order.
251 * @param string $output
252 * What should the result set include (web/email/csv).
255 * the total number of rows for this action
257 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
258 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
262 $this->_mailingClause
265 // process the result of the query
267 $permissions = [CRM_Core_Permission
::getPermission()];
268 if (CRM_Core_Permission
::check('delete contacts')) {
269 $permissions[] = CRM_Core_Permission
::DELETE
;
271 $mask = CRM_Core_Action
::mask($permissions);
272 $qfKey = $this->_key
;
274 while ($result->fetch()) {
276 // the columns we are interested in
277 foreach (self
::$_properties as $property) {
278 if (property_exists($result, $property)) {
279 $row[$property] = $result->$property;
283 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->mailing_recipients_id
;
286 'cid' => $result->contact_id
,
287 'cxt' => $this->_context
,
290 $row['action'] = CRM_Core_Action
::formLink(
291 self
::links($qfKey, $this->_context
),
296 'contact.mailing.row',
300 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
311 public function getQILL() {
312 return $this->_query
->qill();
316 * Returns the column headers as an array of tuples:
317 * (name, sortName (key to the sort array))
319 * @param string $action
320 * The action being performed.
321 * @param string $output
322 * What should the result set include (web/email/csv).
325 * the column headers that need to be displayed
327 public function &getColumnHeaders($action = NULL, $output = NULL) {
329 if (!isset(self
::$_columnHeaders)) {
330 $isMultiLingual = CRM_Core_I18n
::isMultiLingual();
332 ['desc' => ts('Contact Type')],
334 'name' => ts('Name'),
335 'sort' => 'sort_name',
336 'direction' => CRM_Utils_Sort
::DONTCARE
,
339 'name' => ts('Email'),
341 'direction' => CRM_Utils_Sort
::DONTCARE
,
344 'name' => ts('Mailing Name'),
345 'sort' => 'mailing_name',
346 'direction' => CRM_Utils_Sort
::DONTCARE
,
350 // Check to see if languages column should be displayed.
351 if ($isMultiLingual) {
353 'name' => ts('Language'),
354 'sort' => 'language',
355 'direction' => CRM_Utils_Sort
::DONTCARE
,
358 self
::$_columnHeaders = array_merge($headers, [
360 'name' => ts('Mailing Subject'),
361 'sort' => 'mailing_subject',
362 'direction' => CRM_Utils_Sort
::DONTCARE
,
365 'name' => ts('Mailing Status'),
366 'sort' => 'mailing_job_status',
367 'direction' => CRM_Utils_Sort
::DONTCARE
,
370 'name' => ts('Completed Date'),
371 'sort' => 'mailing_job_end_date',
372 'direction' => CRM_Utils_Sort
::DONTCARE
,
374 ['desc' => ts('Actions')],
377 return self
::$_columnHeaders;
383 public function alphabetQuery() {
384 return $this->_query
->alphabetQuery();
390 public function &getQuery() {
391 return $this->_query
;
395 * Name of export file.
397 * @param string $output
403 public function getExportFileName($output = 'csv') {
404 return ts('CiviCRM Mailing Search');