3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.1 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2011 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2011
36 require_once 'CRM/Contact/Form/Search/Custom/Base.php';
37 class org_civicrm_search_basic
extends CRM_Contact_Form_Search_Custom_BaseimplementsCRM_Contact_Form_Search_Interface
{
41 function __construct(&$formValues) {
42 parent
::__construct($formValues);
45 $this->_columns
= array(ts('') => 'contact_type',
46 ts('') => 'contact_sub_type',
47 ts('Name') => 'sort_name',
48 ts('Address') => 'street_address',
50 ts('State') => 'state_province',
51 ts('Postal') => 'postal_code',
52 ts('Country') => 'country',
53 ts('Email') => 'email',
54 ts('Phone') => 'phone',
57 $params = &CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
58 $returnProperties = array();
59 foreach ($this->_columns
as $name => $field) {
60 $returnProperties[$field] = 1;
63 $this->_query
= new CRM_Contact_BAO_Query($params, $returnProperties, NULL,
64 FALSE, FALSE, 1, FALSE, FALSE
69 * normalize the form values to make it look similar to the advanced form values
70 * this prevents a ton of work downstream and allows us to use the same code for
71 * multiple purposes (queries, save/edit etc)
76 function normalize() {
77 $contactType = CRM_Utils_Array
::value('contact_type', $this->_formValues
);
78 if ($contactType && !is_array($contactType)) {
79 unset($this->_formValues
['contact_type']);
80 $this->_formValues
['contact_type'][$contactType] = 1;
83 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
84 if ($group && !is_array($group)) {
85 unset($this->_formValues
['group']);
86 $this->_formValues
['group'][$group] = 1;
89 $tag = CRM_Utils_Array
::value('tag', $this->_formValues
);
90 if ($tag && !is_array($tag)) {
91 unset($this->_formValues
['tag']);
92 $this->_formValues
['tag'][$tag] = 1;
98 function buildForm(&$form) {
99 $contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType
::getSelectElements();
100 $form->add('select', 'contact_type', ts('Find...'), $contactTypes);
102 // add select for groups
103 $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant
::group();
104 $form->addElement('select', 'group', ts('in'), $group);
106 // add select for categories
107 $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
108 $form->addElement('select', 'tag', ts('Tagged'), $tag);
110 // text for sort_name
111 $form->add('text', 'sort_name', ts('Name'));
113 $form->assign('elements', array('sort_name', 'contact_type', 'group', 'tag'));
117 return $this->_query
->searchQuery(0, 0, NULL, TRUE);
120 function all($offset = 0, $rowCount = 0, $sort = NULL,
121 $includeContactIDs = FALSE
123 return $this->_query
->searchQuery($offset, $rowCount, $sort,
124 FALSE, $includeContactIDs,
130 return $this->_query
->_fromClause
;
133 function where($includeContactIDs = FALSE) {
134 if ($whereClause = $this->_query
->whereClause()) {
140 function templateFile() {
141 return 'CRM/Contact/Form/Search/Basic.tpl';