3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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-2018
35 * This class is used to retrieve and display a range of
36 * contacts that match the given criteria (specifically for
37 * results of advanced search options.
39 class CRM_Mailing_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
42 * This defines two actions- View and Edit.
46 static $_links = NULL;
49 * We use desc to remind us what that column is, name is used in the tpl
53 static $_columnHeaders;
56 * Properties of contact we're interested in displaying
59 static $_properties = array(
70 'mailing_job_end_date',
74 * Are we restricting ourselves to a single contact
78 protected $_single = FALSE;
81 * Are we restricting ourselves to a single contact
85 protected $_limit = NULL;
88 * What context are we being invoked from
92 protected $_context = NULL;
95 * What component context are we being invoked from
99 protected $_compContext = NULL;
102 * QueryParams is the array returned by exportValues called on
103 * the HTML_QuickForm_Controller for that page.
107 public $_queryParams;
110 * Represent the type of selector.
117 * The additional clause that we restrict the search with.
121 protected $_mailingClause = NULL;
133 * @param array $queryParams
134 * Array of parameters for query.
135 * @param \const|int $action - action of search basic or advanced.
136 * @param string $mailingClause
137 * If the caller wants to further restrict the search.
138 * @param bool $single
139 * Are we dealing only with one contact?.
141 * How many mailing do we want returned.
143 * @param string $context
144 * @param null $compContext
146 * @return \CRM_Mailing_Selector_Search
148 public function __construct(
150 $action = CRM_Core_Action
::NONE
,
151 $mailingClause = NULL,
157 // submitted form values
158 $this->_queryParams
= &$queryParams;
160 $this->_single
= $single;
161 $this->_limit
= $limit;
162 $this->_context
= $context;
163 $this->_compContext
= $compContext;
165 $this->_mailingClause
= $mailingClause;
168 $this->_action
= $action;
169 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
170 CRM_Mailing_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MAILING
,
174 CRM_Contact_BAO_Query
::MODE_MAILING
177 $this->_query
->_distinctComponentClause
= " civicrm_mailing_recipients.id ";
181 * This method returns the links that are given for each search row.
182 * currently the links added for each row are
189 public static function &links() {
190 if (!(self
::$_links)) {
191 list($context, $key) = func_get_args();
192 $extraParams = ($key) ?
"&key={$key}" : NULL;
193 $searchContext = ($context) ?
"&context=$context" : NULL;
195 self
::$_links = array(
196 CRM_Core_Action
::VIEW
=> array(
197 'name' => ts('View'),
198 'url' => 'civicrm/contact/view',
199 'qs' => "reset=1&cid=%%cid%%{$searchContext}{$extraParams}",
200 'title' => ts('View Contact Details'),
202 CRM_Core_Action
::UPDATE
=> array(
203 'name' => ts('Edit'),
204 'url' => 'civicrm/contact/add',
205 'qs' => "reset=1&action=update&cid=%%cid%%{$searchContext}{$extraParams}",
206 'title' => ts('Edit Contact Details'),
208 CRM_Core_Action
::DELETE
=> array(
209 'name' => ts('Delete'),
210 'url' => 'civicrm/contact/view/delete',
211 'qs' => "reset=1&delete=1&cid=%%cid%%{$searchContext}{$extraParams}",
212 'title' => ts('Delete Contact'),
216 return self
::$_links;
220 * Getter for array of the parameters required for creating pager.
223 * @param array $params
225 public function getPagerParams($action, &$params) {
226 $params['status'] = ts('Mailing Recipient') . ' %%StatusMessage%%';
227 $params['csvString'] = NULL;
229 $params['rowCount'] = $this->_limit
;
232 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
235 $params['buttonTop'] = 'PagerTopButton';
236 $params['buttonBottom'] = 'PagerBottomButton';
240 * Returns total number of rows for the query.
242 * @param string $action
245 * Total number of rows
247 public function getTotalCount($action) {
248 return $this->_query
->searchQuery(0, 0, NULL,
252 $this->_mailingClause
257 * Returns all the rows in the given offset and rowCount.
259 * @param string $action
260 * The action being performed.
262 * The row number to start from.
263 * @param int $rowCount
264 * The number of rows to return.
265 * @param string $sort
266 * The sql string that describes the sort order.
267 * @param string $output
268 * What should the result set include (web/email/csv).
271 * the total number of rows for this action
273 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
274 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
278 $this->_mailingClause
281 // process the result of the query
283 $permissions = array(CRM_Core_Permission
::getPermission());
284 if (CRM_Core_Permission
::check('delete contacts')) {
285 $permissions[] = CRM_Core_Permission
::DELETE
;
287 $mask = CRM_Core_Action
::mask($permissions);
288 $qfKey = $this->_key
;
290 while ($result->fetch()) {
292 // the columns we are interested in
293 foreach (self
::$_properties as $property) {
294 if (property_exists($result, $property)) {
295 $row[$property] = $result->$property;
299 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->mailing_recipients_id
;
302 'cid' => $result->contact_id
,
303 'cxt' => $this->_context
,
306 $row['action'] = CRM_Core_Action
::formLink(
307 self
::links($qfKey, $this->_context
),
312 'contact.mailing.row',
316 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
327 public function getQILL() {
328 return $this->_query
->qill();
332 * Returns the column headers as an array of tuples:
333 * (name, sortName (key to the sort array))
335 * @param string $action
336 * The action being performed.
337 * @param string $output
338 * What should the result set include (web/email/csv).
341 * the column headers that need to be displayed
343 public function &getColumnHeaders($action = NULL, $output = NULL) {
344 if (!isset(self
::$_columnHeaders)) {
345 self
::$_columnHeaders = array(
346 array('desc' => ts('Contact Type')),
348 'name' => ts('Name'),
349 'sort' => 'sort_name',
350 'direction' => CRM_Utils_Sort
::DONTCARE
,
353 'name' => ts('Email'),
355 'direction' => CRM_Utils_Sort
::DONTCARE
,
358 'name' => ts('Mailing Name'),
359 'sort' => 'mailing_name',
360 'direction' => CRM_Utils_Sort
::DONTCARE
,
363 'name' => ts('Language'),
364 'sort' => 'language',
365 'direction' => CRM_Utils_Sort
::DONTCARE
,
368 'name' => ts('Mailing Subject'),
369 'sort' => 'mailing_subject',
370 'direction' => CRM_Utils_Sort
::DONTCARE
,
373 'name' => ts('Mailing Status'),
374 'sort' => 'mailing_job_status',
375 'direction' => CRM_Utils_Sort
::DONTCARE
,
378 'name' => ts('Completed Date'),
379 'sort' => 'mailing_job_end_date',
380 'direction' => CRM_Utils_Sort
::DONTCARE
,
382 array('desc' => ts('Actions')),
385 return self
::$_columnHeaders;
391 public function alphabetQuery() {
392 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
398 public function &getQuery() {
399 return $this->_query
;
403 * Name of export file.
405 * @param string $output
411 public function getExportFileName($output = 'csv') {
412 return ts('CiviCRM Mailing Search');