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
{
13 public function __construct(&$formValues) {
14 parent
::__construct($formValues);
18 * Prepare a set of search fields.
20 * @param CRM_Core_Form $form
24 public function buildForm(&$form) {
25 CRM_Utils_System
::setTitle(ts('My Search Title'));
33 $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant
::stateProvince();
34 $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
36 // Optionally define default search values
37 $form->setDefaults(array(
38 'household_name' => '',
39 'state_province_id' => NULL,
43 * if you are using the standard template, this array tells the template what elements
44 * are part of the search criteria
46 $form->assign('elements', array('household_name', 'state_province_id'));
50 * Get a list of summary data points.
53 * - NULL or array with keys:
57 public function summary() {
60 // 'summary' => 'This is a summary',
66 * Get a list of displayable columns.
68 * @return array, keys are printable column headers and values are SQL column names
70 public function &columns() {
71 // return by reference
73 ts('Contact ID') => 'contact_id',
74 ts('Contact Type') => 'contact_type',
75 ts('Name') => 'sort_name',
76 ts('State') => 'state_province',
82 * Construct a full SQL query which returns one page worth of results.
85 * @param int $rowcount
87 * @param bool $includeContactIDs
91 public function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE) {
92 // delegate to $this->sql(), $this->select(), $this->from(), $this->where(), etc.
93 return $this->sql($this->select(), $offset, $rowcount, $sort, $includeContactIDs, NULL);
97 * Construct a SQL SELECT clause.
99 * @return string, sql fragment with SELECT arguments
101 public function select() {
103 contact_a.id as contact_id ,
104 contact_a.contact_type as contact_type,
105 contact_a.sort_name as sort_name,
106 state_province.name as state_province
111 * Construct a SQL FROM clause.
113 * @return string, sql fragment with FROM and JOIN clauses
115 public function from() {
117 FROM civicrm_contact contact_a
118 LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
119 address.is_primary = 1 )
120 LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND
121 civicrm_email.is_primary = 1 )
122 LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id
127 * Construct a SQL WHERE clause.
129 * @param bool $includeContactIDs
131 * @return string, sql fragment with conditional expressions
133 public function where($includeContactIDs = FALSE) {
135 $where = "contact_a.contact_type = 'Household'";
139 $name = CRM_Utils_Array
::value('household_name',
143 if (strpos($name, '%') === FALSE) {
146 $params[$count] = array($name, 'String');
147 $clause[] = "contact_a.household_name LIKE %{$count}";
151 $state = CRM_Utils_Array
::value('state_province_id',
157 $state = $this->_stateID
;
161 $params[$count] = array($state, 'Integer');
162 $clause[] = "state_province.id = %{$count}";
165 if (!empty($clause)) {
166 $where .= ' AND ' . implode(' AND ', $clause);
169 return $this->whereClause($where, $params);
173 * Determine the Smarty template for the search screen.
175 * @return string, template path (findable through Smarty template path)
177 public function templateFile() {
178 return 'CRM/Contact/Form/Search/Custom.tpl';
182 * Modify the content of each row.
185 * Modifiable SQL result row.
188 public function alterRow(&$row) {
189 $row['sort_name'] .= ' ( altered )';