3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
36 require_once 'CRM/Contact/Form/Search/Custom/Base.php';
39 * Class org_civicrm_search_basic
41 class org_civicrm_search_basic
extends CRM_Contact_Form_Search_Custom_BaseimplementsCRM_Contact_Form_Search_Interface
{
48 function __construct(&$formValues) {
49 parent
::__construct($formValues);
52 $this->_columns
= array(ts('') => 'contact_type',
53 ts('') => 'contact_sub_type',
54 ts('Name') => 'sort_name',
55 ts('Address') => 'street_address',
57 ts('State') => 'state_province',
58 ts('Postal') => 'postal_code',
59 ts('Country') => 'country',
60 ts('Email') => 'email',
61 ts('Phone') => 'phone',
64 $params = &CRM_Contact_BAO_Query
::convertFormValues($this->_formValues
);
65 $returnProperties = array();
66 foreach ($this->_columns
as $name => $field) {
67 $returnProperties[$field] = 1;
70 $this->_query
= new CRM_Contact_BAO_Query($params, $returnProperties, NULL,
71 FALSE, FALSE, 1, FALSE, FALSE
76 * normalize the form values to make it look similar to the advanced form values
77 * this prevents a ton of work downstream and allows us to use the same code for
78 * multiple purposes (queries, save/edit etc)
83 function normalize() {
84 $contactType = CRM_Utils_Array
::value('contact_type', $this->_formValues
);
85 if ($contactType && !is_array($contactType)) {
86 unset($this->_formValues
['contact_type']);
87 $this->_formValues
['contact_type'][$contactType] = 1;
90 $group = CRM_Utils_Array
::value('group', $this->_formValues
);
91 if ($group && !is_array($group)) {
92 unset($this->_formValues
['group']);
93 $this->_formValues
['group'][$group] = 1;
96 $tag = CRM_Utils_Array
::value('tag', $this->_formValues
);
97 if ($tag && !is_array($tag)) {
98 unset($this->_formValues
['tag']);
99 $this->_formValues
['tag'][$tag] = 1;
106 * @param CRM_Core_Form $form
108 function buildForm(&$form) {
110 //@todo FIXME - using the CRM_Core_DAO::VALUE_SEPARATOR creates invalid html - if you can find the form
111 // this is loaded onto then replace with something like '__' & test
112 $separator = CRM_Core_DAO
::VALUE_SEPARATOR
;
113 $contactTypes = array('' => ts('- any contact type -')) + CRM_Contact_BAO_ContactType
::getSelectElements(FALSE, TRUE, $separator);
114 $form->add('select', 'contact_type', ts('Find...'), $contactTypes);
116 // add select for groups
117 $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant
::group();
118 $form->addElement('select', 'group', ts('in'), $group);
120 // add select for categories
121 $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant
::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE));
122 $form->addElement('select', 'tag', ts('Tagged'), $tag);
124 // text for sort_name
125 $form->add('text', 'sort_name', ts('Name'));
127 $form->assign('elements', array('sort_name', 'contact_type', 'group', 'tag'));
131 * @return CRM_Contact_DAO_Contact
134 return $this->_query
->searchQuery(0, 0, NULL, TRUE);
139 * @param int $rowCount
141 * @param bool $includeContactIDs
143 * @return CRM_Contact_DAO_Contact
145 function all($offset = 0, $rowCount = 0, $sort = NULL,
146 $includeContactIDs = FALSE
148 return $this->_query
->searchQuery($offset, $rowCount, $sort,
149 FALSE, $includeContactIDs,
158 return $this->_query
->_fromClause
;
162 * @param bool $includeContactIDs
166 function where($includeContactIDs = FALSE) {
167 if ($whereClause = $this->_query
->whereClause()) {
176 function templateFile() {
177 return 'CRM/Contact/Form/Search/Basic.tpl';