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.
50 static $_links = NULL;
53 * We use desc to remind us what that column is, name is used in the tpl
58 static $_columnHeaders;
61 * Properties of contact we're interested in displaying
65 static $_properties = array(
75 'mailing_job_end_date',
79 * Are we restricting ourselves to a single contact
83 protected $_single = FALSE;
86 * Are we restricting ourselves to a single contact
90 protected $_limit = NULL;
93 * What context are we being invoked from
97 protected $_context = NULL;
100 * What component context are we being invoked from
104 protected $_compContext = NULL;
107 * QueryParams is the array returned by exportValues called on
108 * the HTML_QuickForm_Controller for that page.
112 public $_queryParams;
115 * Represent the type of selector
122 * The additional clause that we restrict the search with
126 protected $_mailingClause = NULL;
138 * @param array $queryParams
139 * Array of parameters for query.
140 * @param \const|int $action - action of search basic or advanced.
141 * @param string $mailingClause
142 * If the caller wants to further restrict the search.
143 * @param bool $single
144 * Are we dealing only with one contact?.
146 * How many mailing do we want returned.
148 * @param string $context
149 * @param null $compContext
151 * @return \CRM_Mailing_Selector_Search
154 function __construct(
156 $action = CRM_Core_Action
::NONE
,
157 $mailingClause = NULL,
163 // submitted form values
164 $this->_queryParams
= &$queryParams;
166 $this->_single
= $single;
167 $this->_limit
= $limit;
168 $this->_context
= $context;
169 $this->_compContext
= $compContext;
171 $this->_mailingClause
= $mailingClause;
174 $this->_action
= $action;
175 $this->_query
= new CRM_Contact_BAO_Query($this->_queryParams
,
176 CRM_Mailing_BAO_Query
::defaultReturnProperties(CRM_Contact_BAO_Query
::MODE_MAILING
,
180 CRM_Contact_BAO_Query
::MODE_MAILING
183 $this->_query
->_distinctComponentClause
= " civicrm_mailing_recipients.id ";
187 * This method returns the links that are given for each search row.
188 * currently the links added for each row are
195 public static function &links() {
196 if (!(self
::$_links)) {
197 list($context, $key) = func_get_args();
198 $extraParams = ($key) ?
"&key={$key}" : NULL;
199 $searchContext = ($context) ?
"&context=$context" : NULL;
201 self
::$_links = array(
202 CRM_Core_Action
::VIEW
=> array(
203 'name' => ts('View'),
204 'url' => 'civicrm/contact/view',
205 'qs' => "reset=1&cid=%%cid%%{$searchContext}{$extraParams}",
206 'title' => ts('View Contact Details'),
208 CRM_Core_Action
::UPDATE
=> array(
209 'name' => ts('Edit'),
210 'url' => 'civicrm/contact/add',
211 'qs' => "reset=1&action=update&cid=%%cid%%{$searchContext}{$extraParams}",
212 'title' => ts('Edit Contact Details'),
214 CRM_Core_Action
::DELETE
=> array(
215 'name' => ts('Delete'),
216 'url' => 'civicrm/contact/view/delete',
217 'qs' => "reset=1&delete=1&cid=%%cid%%{$searchContext}{$extraParams}",
218 'title' => ts('Delete Contact'),
222 return self
::$_links;
226 * Getter for array of the parameters required for creating pager.
229 * @param array $params
231 public function getPagerParams($action, &$params) {
232 $params['status'] = ts('Mailing Recipient') . ' %%StatusMessage%%';
233 $params['csvString'] = NULL;
235 $params['rowCount'] = $this->_limit
;
238 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
241 $params['buttonTop'] = 'PagerTopButton';
242 $params['buttonBottom'] = 'PagerBottomButton';
246 * Returns total number of rows for the query.
251 * Total number of rows
253 public function getTotalCount($action) {
254 return $this->_query
->searchQuery(0, 0, NULL,
258 $this->_mailingClause
263 * Returns all the rows in the given offset and rowCount
265 * @param string $action
266 * The action being performed.
268 * The row number to start from.
269 * @param int $rowCount
270 * The number of rows to return.
271 * @param string $sort
272 * The sql string that describes the sort order.
273 * @param string $output
274 * What should the result set include (web/email/csv).
277 * the total number of rows for this action
279 public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) {
280 $result = $this->_query
->searchQuery($offset, $rowCount, $sort,
284 $this->_mailingClause
287 // process the result of the query
289 $permissions = array(CRM_Core_Permission
::getPermission());
290 if (CRM_Core_Permission
::check('delete contacts')) {
291 $permissions[] = CRM_Core_Permission
::DELETE
;
293 $mask = CRM_Core_Action
::mask($permissions);
294 $qfKey = $this->_key
;
296 while ($result->fetch()) {
298 // the columns we are interested in
299 foreach (self
::$_properties as $property) {
300 if (property_exists($result, $property)) {
301 $row[$property] = $result->$property;
305 $row['checkbox'] = CRM_Core_Form
::CB_PREFIX
. $result->mailing_recipients_id
;
308 'cid' => $result->contact_id
,
309 'cxt' => $this->_context
,
312 $row['action'] = CRM_Core_Action
::formLink(
313 self
::links($qfKey, $this->_context
),
318 'contact.mailing.row',
322 $row['contact_type'] = CRM_Contact_BAO_Contact_Utils
::getImage($result->contact_sub_type ?
$result->contact_sub_type
: $result->contact_type
, FALSE, $result->contact_id
333 public function getQILL() {
334 return $this->_query
->qill();
338 * Returns the column headers as an array of tuples:
339 * (name, sortName (key to the sort array))
341 * @param string $action
342 * The action being performed.
343 * @param string $output
344 * What should the result set include (web/email/csv).
347 * the column headers that need to be displayed
349 public function &getColumnHeaders($action = NULL, $output = NULL) {
350 if (!isset(self
::$_columnHeaders)) {
351 self
::$_columnHeaders = array(
352 array('desc' => ts('Contact Type')),
354 'name' => ts('Name'),
355 'sort' => 'sort_name',
356 'direction' => CRM_Utils_Sort
::DONTCARE
,
359 'name' => ts('Email'),
361 'direction' => CRM_Utils_Sort
::DONTCARE
,
364 'name' => ts('Mailing Name'),
365 'sort' => 'mailing_name',
366 'direction' => CRM_Utils_Sort
::DONTCARE
,
369 'name' => ts('Mailing Subject'),
370 'sort' => 'mailing_subject',
371 'direction' => CRM_Utils_Sort
::DONTCARE
,
374 'name' => ts('Mailing Status'),
375 'sort' => 'mailing_job_status',
376 'direction' => CRM_Utils_Sort
::DONTCARE
,
379 'name' => ts('Completed Date'),
380 'sort' => 'mailing_job_end_date',
381 'direction' => CRM_Utils_Sort
::DONTCARE
,
383 array('desc' => ts('Actions')),
386 return self
::$_columnHeaders;
392 public function alphabetQuery() {
393 return $this->_query
->searchQuery(NULL, NULL, NULL, FALSE, FALSE, TRUE);
399 public function &getQuery() {
400 return $this->_query
;
404 * Name of export file.
406 * @param string $output
412 public function getExportFileName($output = 'csv') {
413 return ts('CiviCRM Mailing Search');