3 require_once 'CRM/Contact/Form/Search/Custom/Base.php';
6 * Class test_extension_manager_searchtest
8 class test_extension_manager_searchtest
extends CRM_Contact_Form_Search_Custom_Base
implements CRM_Contact_Form_Search_Interface
{
12 function __construct(&$formValues) {
13 parent
::__construct($formValues);
17 * Prepare a set of search fields
19 * @param CRM_Core_Form $form modifiable
22 function buildForm(&$form) {
23 CRM_Utils_System
::setTitle(ts('My Search Title'));
31 $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant
::stateProvince();
32 $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
34 // Optionally define default search values
35 $form->setDefaults(array(
36 'household_name' => '',
37 'state_province_id' => NULL,
41 * if you are using the standard template, this array tells the template what elements
42 * are part of the search criteria
44 $form->assign('elements', array('household_name', 'state_province_id'));
48 * Get a list of summary data points
50 * @return mixed; NULL or array with keys:
57 // 'summary' => 'This is a summary',
63 * Get a list of displayable columns
65 * @return array, keys are printable column headers and values are SQL column names
68 // return by reference
70 ts('Contact Id') => 'contact_id',
71 ts('Contact Type') => 'contact_type',
72 ts('Name') => 'sort_name',
73 ts('State') => 'state_province',
79 * Construct a full SQL query which returns one page worth of results
82 * @param int $rowcount
84 * @param bool $includeContactIDs
88 function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE) {
89 // delegate to $this->sql(), $this->select(), $this->from(), $this->where(), etc.
90 return $this->sql($this->select(), $offset, $rowcount, $sort, $includeContactIDs, NULL);
94 * Construct a SQL SELECT clause
96 * @return string, sql fragment with SELECT arguments
100 contact_a.id as contact_id ,
101 contact_a.contact_type as contact_type,
102 contact_a.sort_name as sort_name,
103 state_province.name as state_province
108 * Construct a SQL FROM clause
110 * @return string, sql fragment with FROM and JOIN clauses
114 FROM civicrm_contact contact_a
115 LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
116 address.is_primary = 1 )
117 LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND
118 civicrm_email.is_primary = 1 )
119 LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id
124 * Construct a SQL WHERE clause
126 * @param bool $includeContactIDs
128 * @return string, sql fragment with conditional expressions
130 function where($includeContactIDs = FALSE) {
132 $where = "contact_a.contact_type = 'Household'";
136 $name = CRM_Utils_Array
::value('household_name',
140 if (strpos($name, '%') === FALSE) {
143 $params[$count] = array($name, 'String');
144 $clause[] = "contact_a.household_name LIKE %{$count}";
148 $state = CRM_Utils_Array
::value('state_province_id',
154 $state = $this->_stateID
;
158 $params[$count] = array($state, 'Integer');
159 $clause[] = "state_province.id = %{$count}";
162 if (!empty($clause)) {
163 $where .= ' AND ' . implode(' AND ', $clause);
166 return $this->whereClause($where, $params);
170 * Determine the Smarty template for the search screen
172 * @return string, template path (findable through Smarty template path)
174 function templateFile() {
175 return 'CRM/Contact/Form/Search/Custom.tpl';
179 * Modify the content of each row
181 * @param array $row modifiable SQL result row
184 function alterRow(&$row) {
185 $row['sort_name'] .= ' ( altered )';