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
33 class CRM_Contact_Form_Search_Custom_ZipCodeRange
extends CRM_Contact_Form_Search_Custom_Base
implements CRM_Contact_Form_Search_Interface
{
34 protected $_aclFrom = NULL;
35 protected $_aclWhere = NULL;
39 * @param array $formValues
41 public function __construct(&$formValues) {
42 parent
::__construct($formValues);
44 $this->_columns
= array(
45 // If possible, don't use aliases for the columns you select.
46 // You can prefix columns with table aliases, if needed.
48 // If you don't do this, selecting individual records from the
49 // custom search result won't work if your results are sorted on the
51 // (This is why we map Contact ID on contact_a.id, and not on contact_id).
52 ts('Contact ID') => 'contact_a.id',
53 ts('Name') => 'sort_name',
54 ts('Email') => 'email',
55 ts('Zip') => 'postal_code',
60 * @param CRM_Core_Form $form
62 public function buildForm(&$form) {
65 ts('Postal Code Start'),
71 ts('Postal Code End'),
76 * You can define a custom title for the search form
78 $this->setTitle('Zip Code Range Search');
81 * if you are using the standard template, this array tells the template what elements
82 * are part of the search criteria
84 $form->assign('elements', array('postal_code_low', 'postal_code_high'));
90 public function summary() {
97 * @param int $rowcount
99 * @param bool $returnSQL
103 public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
104 return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
109 * @param int $rowcount
111 * @param bool $includeContactIDs
112 * @param bool $justIDs
117 $offset = 0, $rowcount = 0, $sort = NULL,
118 $includeContactIDs = FALSE, $justIDs = FALSE
121 $selectClause = "contact_a.id as contact_id";
122 // Don't change sort order when $justIDs is TRUE, see CRM-14920.
125 // We select contact_a.id twice. Once as contact_a.id,
126 // because it is used to fill the prevnext_cache. And once
127 // as contact_a.id, for the patch of CRM-16587 to work when
128 // the results are sorted on contact ID.
130 contact_a.id as contact_id ,
132 contact_a.sort_name as sort_name ,
133 email.email as email ,
134 address.postal_code as postal_code
137 return $this->sql($selectClause,
138 $offset, $rowcount, $sort,
139 $includeContactIDs, NULL
146 public function from() {
147 $this->buildACLClause('contact_a');
149 FROM civicrm_contact contact_a
150 LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
151 address.is_primary = 1 )
152 LEFT JOIN civicrm_email email ON ( email.contact_id = contact_a.id AND
153 email.is_primary = 1 ) {$this->_aclFrom}
159 * @param bool $includeContactIDs
163 public function where($includeContactIDs = FALSE) {
166 $low = CRM_Utils_Array
::value('postal_code_low',
169 $high = CRM_Utils_Array
::value('postal_code_high',
172 if ($low == NULL ||
$high == NULL) {
173 CRM_Core_Error
::statusBounce(ts('Please provide start and end postal codes'),
174 CRM_Utils_System
::url('civicrm/contact/search/custom',
175 "reset=1&csid={$this->_formValues['customSearchID']}",
176 FALSE, NULL, FALSE, TRUE
181 $where = "ROUND(address.postal_code) >= %1 AND ROUND(address.postal_code) <= %2";
183 1 => array(trim($low), 'Integer'),
184 2 => array(trim($high), 'Integer'),
187 if ($this->_aclWhere
) {
188 $where .= " AND {$this->_aclWhere} ";
190 return $this->whereClause($where, $params);
196 public function templateFile() {
197 return 'CRM/Contact/Form/Search/Custom.tpl';
203 public function setTitle($title) {
205 CRM_Utils_System
::setTitle($title);
208 CRM_Utils_System
::setTitle(ts('Search'));
213 * @param string $tableAlias
215 public function buildACLClause($tableAlias = 'contact') {
216 list($this->_aclFrom
, $this->_aclWhere
) = CRM_Contact_BAO_Contact_Permission
::cacheClause($tableAlias);