3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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-2015
35 class CRM_Contact_Form_Search_Custom_ZipCodeRange
extends CRM_Contact_Form_Search_Custom_Base
implements CRM_Contact_Form_Search_Interface
{
36 protected $_aclFrom = NULL;
37 protected $_aclWhere = NULL;
41 public function __construct(&$formValues) {
42 parent
::__construct($formValues);
44 $this->_columns
= array(
45 ts('Contact ID') => 'contact_id',
46 ts('Name') => 'sort_name',
47 ts('Email') => 'email',
48 ts('Zip') => 'postal_code',
53 * @param CRM_Core_Form $form
55 public function buildForm(&$form) {
58 ts('Postal Code Start'),
64 ts('Postal Code End'),
69 * You can define a custom title for the search form
71 $this->setTitle('Zip Code Range Search');
74 * if you are using the standard template, this array tells the template what elements
75 * are part of the search criteria
77 $form->assign('elements', array('postal_code_low', 'postal_code_high'));
83 public function summary() {
90 * @param int $rowcount
92 * @param bool $returnSQL
96 public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
97 return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
102 * @param int $rowcount
104 * @param bool $includeContactIDs
105 * @param bool $justIDs
110 $offset = 0, $rowcount = 0, $sort = NULL,
111 $includeContactIDs = FALSE, $justIDs = FALSE
114 $selectClause = "contact_a.id as contact_id";
115 $sort = "contact_a.id";
119 contact_a.id as contact_id ,
120 contact_a.sort_name as sort_name ,
121 email.email as email ,
122 address.postal_code as postal_code
125 return $this->sql($selectClause,
126 $offset, $rowcount, $sort,
127 $includeContactIDs, NULL
134 public function from() {
135 $this->buildACLClause('contact_a');
137 FROM civicrm_contact contact_a
138 LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
139 address.is_primary = 1 )
140 LEFT JOIN civicrm_email email ON ( email.contact_id = contact_a.id AND
141 email.is_primary = 1 ) {$this->_aclFrom}
147 * @param bool $includeContactIDs
151 public function where($includeContactIDs = FALSE) {
154 $low = CRM_Utils_Array
::value('postal_code_low',
157 $high = CRM_Utils_Array
::value('postal_code_high',
160 if ($low == NULL ||
$high == NULL) {
161 CRM_Core_Error
::statusBounce(ts('Please provide start and end postal codes'),
162 CRM_Utils_System
::url('civicrm/contact/search/custom',
163 "reset=1&csid={$this->_formValues['customSearchID']}",
164 FALSE, NULL, FALSE, TRUE
169 $where = "ROUND(address.postal_code) >= %1 AND ROUND(address.postal_code) <= %2";
171 1 => array(trim($low), 'Integer'),
172 2 => array(trim($high), 'Integer'),
175 if ($this->_aclWhere
) {
176 $where .= " AND {$this->_aclWhere} ";
178 return $this->whereClause($where, $params);
184 public function setDefaultValues() {
191 public function templateFile() {
192 return 'CRM/Contact/Form/Search/Custom.tpl';
198 public function setTitle($title) {
200 CRM_Utils_System
::setTitle($title);
203 CRM_Utils_System
::setTitle(ts('Search'));
208 * @param string $tableAlias
210 public function buildACLClause($tableAlias = 'contact') {
211 list($this->_aclFrom
, $this->_aclWhere
) = CRM_Contact_BAO_Contact_Permission
::cacheClause($tableAlias);