3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
17 class CRM_Contact_Form_Search_Custom_Sample
extends CRM_Contact_Form_Search_Custom_Base
implements CRM_Contact_Form_Search_Interface
{
18 protected $_aclFrom = NULL;
19 protected $_aclWhere = NULL;
24 * @param array $formValues
26 public function __construct(&$formValues) {
27 parent
::__construct($formValues);
29 if (!isset($formValues['state_province_id'])) {
30 $this->_stateID
= CRM_Utils_Request
::retrieve('stateID', 'Integer');
31 if ($this->_stateID
) {
32 $formValues['state_province_id'] = $this->_stateID
;
37 ts('Contact ID') => 'contact_id',
38 ts('Contact Type') => 'contact_type',
39 ts('Name') => 'sort_name',
40 ts('State') => 'state_province',
47 * @param CRM_Core_Form $form
49 public function buildForm(&$form) {
57 $stateProvince = ['' => ts('- any state/province -')] + CRM_Core_PseudoConstant
::stateProvince();
58 $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
61 * You can define a custom title for the search form
63 $this->setTitle(ts('My Search Title'));
66 * if you are using the standard template, this array tells the template what elements
67 * are part of the search criteria
69 $form->assign('elements', ['household_name', 'state_province_id']);
75 public function summary() {
77 'summary' => 'This is a summary',
85 * @param int $rowcount
86 * @param string|null $sort
87 * @param bool $returnSQL
91 public function contactIDs($offset = 0, $rowcount = 0, $sort = NULL, $returnSQL = FALSE) {
92 return $this->all($offset, $rowcount, $sort, FALSE, TRUE);
97 * @param int $rowcount
98 * @param string|null $sort
99 * @param bool $includeContactIDs
100 * @param bool $justIDs
104 public function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE, $justIDs = FALSE) {
106 $selectClause = "contact_a.id as contact_id";
107 $sort = 'contact_a.id';
111 contact_a.id as contact_id ,
112 contact_a.contact_type as contact_type,
113 contact_a.sort_name as sort_name,
114 state_province.name as state_province
118 return $this->sql($selectClause,
119 $offset, $rowcount, $sort,
120 $includeContactIDs, NULL
127 public function from() {
128 $this->buildACLClause('contact_a');
130 FROM civicrm_contact contact_a
131 LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
132 address.is_primary = 1 )
133 LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND
134 civicrm_email.is_primary = 1 )
135 LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id {$this->_aclFrom}
141 * @param bool $includeContactIDs
145 public function where($includeContactIDs = FALSE) {
147 $where = "contact_a.contact_type = 'Household'";
151 $name = CRM_Utils_Array
::value('household_name',
155 if (strpos($name, '%') === FALSE) {
158 $params[$count] = [$name, 'String'];
159 $clause[] = "contact_a.household_name LIKE %{$count}";
163 $state = CRM_Utils_Array
::value('state_province_id',
169 $state = $this->_stateID
;
173 $params[$count] = [$state, 'Integer'];
174 $clause[] = "state_province.id = %{$count}";
177 if ($this->_aclWhere
) {
178 $clause[] = " {$this->_aclWhere} ";
181 if (!empty($clause)) {
182 $where .= ' AND ' . implode(' AND ', $clause);
185 return $this->whereClause($where, $params);
191 public function templateFile() {
192 return 'CRM/Contact/Form/Search/Custom.tpl';
198 public function setDefaultValues() {
199 return array_merge(['household_name' => ''], $this->_formValues
);
205 public function alterRow(&$row) {
206 $row['sort_name'] .= ' ( altered )';
210 * @param string $tableAlias
212 public function buildACLClause($tableAlias = 'contact') {
213 list($this->_aclFrom
, $this->_aclWhere
) = CRM_Contact_BAO_Contact_Permission
::cacheClause($tableAlias);