3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
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_Sample
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 if (!isset($formValues['state_province_id'])) {
45 $this->_stateID
= CRM_Utils_Request
::retrieve('stateID', 'Integer',
46 CRM_Core_DAO
::$_nullObject
48 if ($this->_stateID
) {
49 $formValues['state_province_id'] = $this->_stateID
;
53 $this->_columns
= array(
54 ts('Contact ID') => 'contact_id',
55 ts('Contact Type') => 'contact_type',
56 ts('Name') => 'sort_name',
57 ts('State') => 'state_province',
62 * @param CRM_Core_Form $form
64 public function buildForm(&$form) {
72 $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant
::stateProvince();
73 $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
76 * You can define a custom title for the search form
78 $this->setTitle('My Search Title');
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('household_name', 'state_province_id'));
90 public function summary() {
92 'summary' => 'This is a summary',
100 * @param int $rowcount
102 * @param bool $returnSQL
106 public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
107 return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
112 * @param int $rowcount
114 * @param bool $includeContactIDs
115 * @param bool $justIDs
119 public function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE) {
121 $selectClause = "contact_a.id as contact_id";
122 $sort = 'contact_a.id';
126 contact_a.id as contact_id ,
127 contact_a.contact_type as contact_type,
128 contact_a.sort_name as sort_name,
129 state_province.name as state_province
133 return $this->sql($selectClause,
134 $offset, $rowcount, $sort,
135 $includeContactIDs, NULL
142 public function from() {
143 $this->buildACLClause('contact_a');
145 FROM civicrm_contact contact_a
146 LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
147 address.is_primary = 1 )
148 LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND
149 civicrm_email.is_primary = 1 )
150 LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id {$this->_aclFrom}
156 * @param bool $includeContactIDs
160 public function where($includeContactIDs = FALSE) {
162 $where = "contact_a.contact_type = 'Household'";
166 $name = CRM_Utils_Array
::value('household_name',
170 if (strpos($name, '%') === FALSE) {
173 $params[$count] = array($name, 'String');
174 $clause[] = "contact_a.household_name LIKE %{$count}";
178 $state = CRM_Utils_Array
::value('state_province_id',
184 $state = $this->_stateID
;
188 $params[$count] = array($state, 'Integer');
189 $clause[] = "state_province.id = %{$count}";
192 if ($this->_aclWhere
) {
193 $clause[] = " {$this->_aclWhere} ";
196 if (!empty($clause)) {
197 $where .= ' AND ' . implode(' AND ', $clause);
200 return $this->whereClause($where, $params);
206 public function templateFile() {
207 return 'CRM/Contact/Form/Search/Custom.tpl';
213 public function setDefaultValues() {
214 return array_merge(array('household_name' => ''), $this->_formValues
);
220 public function alterRow(&$row) {
221 $row['sort_name'] .= ' ( altered )';
227 public function setTitle($title) {
229 CRM_Utils_System
::setTitle($title);
232 CRM_Utils_System
::setTitle(ts('Search'));
237 * @param string $tableAlias
239 public function buildACLClause($tableAlias = 'contact') {
240 list($this->_aclFrom
, $this->_aclWhere
) = CRM_Contact_BAO_Contact_Permission
::cacheClause($tableAlias);