copyright and version fixes
[civicrm-core.git] / CRM / Contact / Form / Search / Custom / Sample.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26*/
27
28/**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35class CRM_Contact_Form_Search_Custom_Sample extends CRM_Contact_Form_Search_Custom_Base implements CRM_Contact_Form_Search_Interface {
36 function __construct(&$formValues) {
37 parent::__construct($formValues);
38
39 if (!isset($formValues['state_province_id'])) {
40 $this->_stateID = CRM_Utils_Request::retrieve('stateID', 'Integer',
41 CRM_Core_DAO::$_nullObject
42 );
43 if ($this->_stateID) {
44 $formValues['state_province_id'] = $this->_stateID;
45 }
46 }
47
48 $this->_columns = array(
49 ts('Contact Id') => 'contact_id',
50 ts('Contact Type') => 'contact_type',
51 ts('Name') => 'sort_name',
52 ts('State') => 'state_province',
53 );
54 }
55
56 function buildForm(&$form) {
57
58 $form->add('text',
59 'household_name',
60 ts('Household Name'),
61 TRUE
62 );
63
64 $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant::stateProvince();
65 $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
66
67 /**
68 * You can define a custom title for the search form
69 */
70 $this->setTitle('My Search Title');
71
72 /**
73 * if you are using the standard template, this array tells the template what elements
74 * are part of the search criteria
75 */
76 $form->assign('elements', array('household_name', 'state_province_id'));
77 }
78
79 function summary() {
80 $summary = array(
81 'summary' => 'This is a summary',
82 'total' => 50.0,
83 );
84 return $summary;
85 }
86
87 function all($offset = 0, $rowcount = 0, $sort = NULL,
88 $includeContactIDs = FALSE, $justIDs = FALSE
89 ) {
90 if ($justIDs) {
91 $selectClause = "contact_a.id as contact_id";
92 }
93 else {
94 $selectClause = "
95contact_a.id as contact_id ,
96contact_a.contact_type as contact_type,
97contact_a.sort_name as sort_name,
98state_province.name as state_province
99";
100 }
101
102 return $this->sql($selectClause,
103 $offset, $rowcount, $sort,
104 $includeContactIDs, NULL
105 );
106 }
107
108 function from() {
109 return "
110FROM civicrm_contact contact_a
111LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
112 address.is_primary = 1 )
113LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND
114 civicrm_email.is_primary = 1 )
115LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id
116";
117 }
118
119 function where($includeContactIDs = FALSE) {
120 $params = array();
121 $where = "contact_a.contact_type = 'Household'";
122
123 $count = 1;
124 $clause = array();
125 $name = CRM_Utils_Array::value('household_name',
126 $this->_formValues
127 );
128 if ($name != NULL) {
129 if (strpos($name, '%') === FALSE) {
130 $name = "%{$name}%";
131 }
132 $params[$count] = array($name, 'String');
133 $clause[] = "contact_a.household_name LIKE %{$count}";
134 $count++;
135 }
136
137 $state = CRM_Utils_Array::value('state_province_id',
138 $this->_formValues
139 );
140 if (!$state &&
141 $this->_stateID
142 ) {
143 $state = $this->_stateID;
144 }
145
146 if ($state) {
147 $params[$count] = array($state, 'Integer');
148 $clause[] = "state_province.id = %{$count}";
149 }
150
151 if (!empty($clause)) {
152 $where .= ' AND ' . implode(' AND ', $clause);
153 }
154
155 return $this->whereClause($where, $params);
156 }
157
158 function templateFile() {
159 return 'CRM/Contact/Form/Search/Custom.tpl';
160 }
161
162 function setDefaultValues() {
163 return array(
164 'household_name' => '',
165 );
166 }
167
168 function alterRow(&$row) {
169 $row['sort_name'] .= ' ( altered )';
170 }
171
172 function setTitle($title) {
173 if ($title) {
174 CRM_Utils_System::setTitle($title);
175 }
176 else {
177 CRM_Utils_System::setTitle(ts('Search'));
178 }
179 }
180}
181