3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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
35 class CRM_Contact_Form_Search_Custom_Sample
extends CRM_Contact_Form_Search_Custom_Base
implements CRM_Contact_Form_Search_Interface
{
39 function __construct(&$formValues) {
40 parent
::__construct($formValues);
42 if (!isset($formValues['state_province_id'])) {
43 $this->_stateID
= CRM_Utils_Request
::retrieve('stateID', 'Integer',
44 CRM_Core_DAO
::$_nullObject
46 if ($this->_stateID
) {
47 $formValues['state_province_id'] = $this->_stateID
;
51 $this->_columns
= array(
52 ts('Contact ID') => 'contact_id',
53 ts('Contact Type') => 'contact_type',
54 ts('Name') => 'sort_name',
55 ts('State') => 'state_province',
60 * @param CRM_Core_Form $form
62 function buildForm(&$form) {
70 $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant
::stateProvince();
71 $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
74 * You can define a custom title for the search form
76 $this->setTitle('My Search Title');
79 * if you are using the standard template, this array tells the template what elements
80 * are part of the search criteria
82 $form->assign('elements', array('household_name', 'state_province_id'));
90 'summary' => 'This is a summary',
96 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
109 function all($offset = 0, $rowcount = 0, $sort = NULL,
110 $includeContactIDs = FALSE, $justIDs = FALSE
113 $selectClause = "contact_a.id as contact_id";
114 $sort = 'contact_a.id';
118 contact_a.id as contact_id ,
119 contact_a.contact_type as contact_type,
120 contact_a.sort_name as sort_name,
121 state_province.name as state_province
125 return $this->sql($selectClause,
126 $offset, $rowcount, $sort,
127 $includeContactIDs, NULL
136 FROM civicrm_contact contact_a
137 LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
138 address.is_primary = 1 )
139 LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND
140 civicrm_email.is_primary = 1 )
141 LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id
146 * @param bool $includeContactIDs
150 function where($includeContactIDs = FALSE) {
152 $where = "contact_a.contact_type = 'Household'";
156 $name = CRM_Utils_Array
::value('household_name',
160 if (strpos($name, '%') === FALSE) {
163 $params[$count] = array($name, 'String');
164 $clause[] = "contact_a.household_name LIKE %{$count}";
168 $state = CRM_Utils_Array
::value('state_province_id',
174 $state = $this->_stateID
;
178 $params[$count] = array($state, 'Integer');
179 $clause[] = "state_province.id = %{$count}";
182 if (!empty($clause)) {
183 $where .= ' AND ' . implode(' AND ', $clause);
186 return $this->whereClause($where, $params);
192 function templateFile() {
193 return 'CRM/Contact/Form/Search/Custom.tpl';
199 function setDefaultValues() {
201 'household_name' => '',
208 function alterRow(&$row) {
209 $row['sort_name'] .= ' ( altered )';
215 function setTitle($title) {
217 CRM_Utils_System
::setTitle($title);
220 CRM_Utils_System
::setTitle(ts('Search'));