3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
37 * This class is used to retrieve and display a range of
38 * contacts that match the given criteria (specifically for
39 * results of advanced search options.
42 class CRM_Mailing_Selector_Search
extends CRM_Core_Selector_Base
implements CRM_Core_Selector_API
{
45 * This defines two actions- View and Edit.
49 static $_links = NULL;
52 * We use desc to remind us what that column is, name is used in the tpl
56 static $_columnHeaders;
59 * Properties of contact we're interested in displaying
62 static $_properties = array(
72 'mailing_job_end_date',
76 * Are we restricting ourselves to a single contact
80 protected $_single = FALSE;
83 * Are we restricting ourselves to a single contact
87 protected $_limit = NULL;
90 * What context are we being invoked from
94 protected $_context = NULL;
97 * What component context are we being invoked from
101 protected $_compContext = NULL;
104 * QueryParams is the array returned by exportValues called on
105 * the HTML_QuickForm_Controller for that page.
109 public $_queryParams;
112 * Represent the type of selector
119 * The additional clause that we restrict the search with
123 protected $_mailingClause = NULL;
135 * @param array $queryParams
136 * Array of parameters for query.
137 * @param \const|int $action - action of search basic or advanced.
138 * @param string $mailingClause
139 * If the caller wants to further restrict the search.
140 * @param bool $single
141 * Are we dealing only with one contact?.
143 * How many mailing do we want returned.
145 * @param string $context
146 * @param null $compContext
148 * @return \CRM_Mailing_Selector_Search
151 function __construct(
153 $action = CRM_Core_Action
::NONE
,
154 $mailingClause = NULL,
160 // submitted form values
161 $this->_queryParams
= &$queryParams;
163 $this->_single
= $single;
164 $this->_limit
= $limit;
165 $this->_context
= $context;
166 $this->_compContext
= $compContext;
168 $this->_mailingClause
= $mailingClause;
171 $this->_action
= $action;
172 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
173 CRM_Mailing_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MAILING
,
177 CRM_Contact_BAO_Query
::MODE_MAILING
180 $this->_query
->_distinctComponentClause
= " civicrm_mailing_recipients.id ";
184 * This method returns the links that are given for each search row.
185 * currently the links added for each row are
192 public static function &links() {
193 if (!(self
::$_links)) {
194 list($context, $key) = func_get_args();
195 $extraParams = ($key) ?
"&key={$key}" : NULL;
196 $searchContext = ($context) ?
"&context=$context" : NULL;
198 self
::$_links = array(
199 CRM_Core_Action
::VIEW
=> array(
200 'name' => ts('View'),
201 'url' => 'civicrm/contact/view',
202 'qs' => "reset=1&cid=%%cid%%{$searchContext}{$extraParams}",
203 'title' => ts('View Contact Details'),
205 CRM_Core_Action
::UPDATE
=> array(
206 'name' => ts('Edit'),
207 'url' => 'civicrm/contact/add',
208 'qs' => "reset=1&action=update&cid=%%cid%%{$searchContext}{$extraParams}",
209 'title' => ts('Edit Contact Details'),
211 CRM_Core_Action
::DELETE
=> array(
212 'name' => ts('Delete'),
213 'url' => 'civicrm/contact/view/delete',
214 'qs' => "reset=1&delete=1&cid=%%cid%%{$searchContext}{$extraParams}",
215 'title' => ts('Delete Contact'),
219 return self
::$_links;
223 * Getter for array of the parameters required for creating pager.
226 * @param array $params
228 public function getPagerParams($action, &$params) {
229 $params['status'] = ts('Mailing Recipient') . ' %%StatusMessage%%';
230 $params['csvString'] = NULL;
232 $params['rowCount'] = $this->_limit
;
235 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
238 $params['buttonTop'] = 'PagerTopButton';
239 $params['buttonBottom'] = 'PagerBottomButton';
243 * Returns total number of rows for the query.
248 * Total number of rows
250 public function getTotalCount($action) {
251 return $this->_query
->searchQuery(0, 0, NULL,
255 $this->_mailingClause
260 * Returns all the rows in the given offset and rowCount
262 * @param string $action
263 * The action being performed.
265 * The row number to start from.
266 * @param int $rowCount
267 * The number of rows to return.
268 * @param string $sort
269 * The sql string that describes the sort order.
270 * @param string $output
271 * What should the result set include (web/email/csv).
274 * the total number of rows for this action
276 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
277 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
281 $this->_mailingClause
284 // process the result of the query
286 $permissions = array(CRM_Core_Permission
::getPermission());
287 if (CRM_Core_Permission
::check('delete contacts')) {
288 $permissions[] = CRM_Core_Permission
::DELETE
;
290 $mask = CRM_Core_Action
::mask($permissions);
291 $qfKey = $this->_key
;
293 while ($result->fetch()) {
295 // the columns we are interested in
296 foreach (self
::$_properties as $property) {
297 if (property_exists($result, $property)) {
298 $row[$property] = $result->$property;
302 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->mailing_recipients_id
;
305 'cid' => $result->contact_id
,
306 'cxt' => $this->_context
,
309 $row['action'] = CRM_Core_Action
::formLink(
310 self
::links($qfKey, $this->_context
),
315 'contact.mailing.row',
319 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
330 public function getQILL() {
331 return $this->_query
->qill();
335 * Returns the column headers as an array of tuples:
336 * (name, sortName (key to the sort array))
338 * @param string $action
339 * The action being performed.
340 * @param string $output
341 * What should the result set include (web/email/csv).
344 * the column headers that need to be displayed
346 public function &getColumnHeaders($action = NULL, $output = NULL) {
347 if (!isset(self
::$_columnHeaders)) {
348 self
::$_columnHeaders = array(
349 array('desc' => ts('Contact Type')),
351 'name' => ts('Name'),
352 'sort' => 'sort_name',
353 'direction' => CRM_Utils_Sort
::DONTCARE
,
356 'name' => ts('Email'),
358 'direction' => CRM_Utils_Sort
::DONTCARE
,
361 'name' => ts('Mailing Name'),
362 'sort' => 'mailing_name',
363 'direction' => CRM_Utils_Sort
::DONTCARE
,
366 'name' => ts('Mailing Subject'),
367 'sort' => 'mailing_subject',
368 'direction' => CRM_Utils_Sort
::DONTCARE
,
371 'name' => ts('Mailing Status'),
372 'sort' => 'mailing_job_status',
373 'direction' => CRM_Utils_Sort
::DONTCARE
,
376 'name' => ts('Completed Date'),
377 'sort' => 'mailing_job_end_date',
378 'direction' => CRM_Utils_Sort
::DONTCARE
,
380 array('desc' => ts('Actions')),
383 return self
::$_columnHeaders;
389 public function alphabetQuery() {
390 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
396 public function &getQuery() {
397 return $this->_query
;
401 * Name of export file.
403 * @param string $output
409 public function getExportFileName($output = 'csv') {
410 return ts('CiviCRM Mailing Search');