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 public function __construct(&$formValues) {
13 parent
::__construct($formValues);
17 * Prepare a set of search fields.
19 * @param CRM_Core_Form $form
23 public function buildForm(&$form) {
24 CRM_Utils_System
::setTitle(ts('My Search Title'));
32 $stateProvince = array('' => ts('- any state/province -')) + CRM_Core_PseudoConstant
::stateProvince();
33 $form->addElement('select', 'state_province_id', ts('State/Province'), $stateProvince);
35 // Optionally define default search values
36 $form->setDefaults(array(
37 'household_name' => '',
38 'state_province_id' => NULL,
42 * if you are using the standard template, this array tells the template what elements
43 * are part of the search criteria
45 $form->assign('elements', array('household_name', 'state_province_id'));
49 * Get a list of summary data points.
51 * @return mixed; NULL or array with keys:
55 public function summary() {
58 // 'summary' => 'This is a summary',
64 * Get a list of displayable columns.
66 * @return array, keys are printable column headers and values are SQL column names
68 public function &columns() {
69 // return by reference
71 ts('Contact ID') => 'contact_id',
72 ts('Contact Type') => 'contact_type',
73 ts('Name') => 'sort_name',
74 ts('State') => 'state_province',
80 * Construct a full SQL query which returns one page worth of results.
83 * @param int $rowcount
85 * @param bool $includeContactIDs
89 public function all($offset = 0, $rowcount = 0, $sort = NULL, $includeContactIDs = FALSE) {
90 // delegate to $this->sql(), $this->select(), $this->from(), $this->where(), etc.
91 return $this->sql($this->select(), $offset, $rowcount, $sort, $includeContactIDs, NULL);
95 * Construct a SQL SELECT clause.
97 * @return string, sql fragment with SELECT arguments
99 public function select() {
101 contact_a.id as contact_id ,
102 contact_a.contact_type as contact_type,
103 contact_a.sort_name as sort_name,
104 state_province.name as state_province
109 * Construct a SQL FROM clause.
111 * @return string, sql fragment with FROM and JOIN clauses
113 public function from() {
115 FROM civicrm_contact contact_a
116 LEFT JOIN civicrm_address address ON ( address.contact_id = contact_a.id AND
117 address.is_primary = 1 )
118 LEFT JOIN civicrm_email ON ( civicrm_email.contact_id = contact_a.id AND
119 civicrm_email.is_primary = 1 )
120 LEFT JOIN civicrm_state_province state_province ON state_province.id = address.state_province_id
125 * Construct a SQL WHERE clause.
127 * @param bool $includeContactIDs
129 * @return string, sql fragment with conditional expressions
131 public function where($includeContactIDs = FALSE) {
133 $where = "contact_a.contact_type = 'Household'";
137 $name = CRM_Utils_Array
::value('household_name',
141 if (strpos($name, '%') === FALSE) {
144 $params[$count] = array($name, 'String');
145 $clause[] = "contact_a.household_name LIKE %{$count}";
149 $state = CRM_Utils_Array
::value('state_province_id',
155 $state = $this->_stateID
;
159 $params[$count] = array($state, 'Integer');
160 $clause[] = "state_province.id = %{$count}";
163 if (!empty($clause)) {
164 $where .= ' AND ' . implode(' AND ', $clause);
167 return $this->whereClause($where, $params);
171 * Determine the Smarty template for the search screen.
173 * @return string, template path (findable through Smarty template path)
175 public function templateFile() {
176 return 'CRM/Contact/Form/Search/Custom.tpl';
180 * Modify the content of each row.
183 * Modifiable SQL result row.
186 public function alterRow(&$row) {
187 $row['sort_name'] .= ' ( altered )';