3 require_once 'CRM/Contact/Form/Search/Custom/Base.php';
4 class test_extension_manager_searchtest
extends CRM_Contact_Form_Search_Custom_Base
implements CRM_Contact_Form_Search_Interface
{
5 function __construct(&$formValues) {
6 parent
::__construct($formValues);
10 * Prepare a set of search fields
12 * @param CRM_Core_Form $form modifiable
15 function buildForm(&$form) {
16 CRM_Utils_System
::setTitle(ts('My Search Title'));
24 $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant
::stateProvince();
25 $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
27 // Optionally define default search values
28 $form->setDefaults(array(
29 'household_name' => '',
30 'state_province_id' => NULL,
34 * if you are using the standard template, this array tells the template what elements
35 * are part of the search criteria
37 $form->assign('elements', array('household_name', 'state_province_id'));
41 * Get a list of summary data points
43 * @return mixed; NULL or array with keys:
50 // 'summary' => 'This is a summary',
56 * Get a list of displayable columns
58 * @return array, keys are printable column headers and values are SQL column names
61 // return by reference
63 ts('Contact Id') => 'contact_id',
64 ts('Contact Type') => 'contact_type',
65 ts('Name') => 'sort_name',
66 ts('State') => 'state_province',
72 * Construct a full SQL query which returns one page worth of results
75 * @param int $rowcount
77 * @param bool $includeContactIDs
81 function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE) {
82 // delegate to $this->sql(), $this->select(), $this->from(), $this->where(), etc.
83 return $this->sql($this->select(), $offset, $rowcount, $sort, $includeContactIDs, NULL);
87 * Construct a SQL SELECT clause
89 * @return string, sql fragment with SELECT arguments
93 contact_a.id as contact_id ,
94 contact_a.contact_type as contact_type,
95 contact_a.sort_name as sort_name,
96 state_province.name as state_province
101 * Construct a SQL FROM clause
103 * @return string, sql fragment with FROM and JOIN clauses
107 FROM civicrm_contact contact_a
108 LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
109 address.is_primary = 1 )
110 LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND
111 civicrm_email.is_primary = 1 )
112 LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id
117 * Construct a SQL WHERE clause
119 * @param bool $includeContactIDs
121 * @return string, sql fragment with conditional expressions
123 function where($includeContactIDs = FALSE) {
125 $where = "contact_a.contact_type = 'Household'";
129 $name = CRM_Utils_Array
::value('household_name',
133 if (strpos($name, '%') === FALSE) {
136 $params[$count] = array($name, 'String');
137 $clause[] = "contact_a.household_name LIKE %{$count}";
141 $state = CRM_Utils_Array
::value('state_province_id',
147 $state = $this->_stateID
;
151 $params[$count] = array($state, 'Integer');
152 $clause[] = "state_province.id = %{$count}";
155 if (!empty($clause)) {
156 $where .= ' AND ' . implode(' AND ', $clause);
159 return $this->whereClause($where, $params);
163 * Determine the Smarty template for the search screen
165 * @return string, template path (findable through Smarty template path)
167 function templateFile() {
168 return 'CRM/Contact/Form/Search/Custom.tpl';
172 * Modify the content of each row
174 * @param array $row modifiable SQL result row
177 function alterRow(&$row) {
178 $row['sort_name'] .= ' ( altered )';