Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.1 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2011 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
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. | | |
13 | | | | |
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. | | |
18 | | | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2011 | |
32 | * $Id$ | |
33 | * | |
34 | */ | |
35 | ||
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 { | |
38 | ||
430ae6dd TO |
39 | protected $_query; |
40 | ||
41 | function __construct(&$formValues) { | |
6a488035 TO |
42 | parent::__construct($formValues); |
43 | ||
44 | $this->normalize(); | |
45 | $this->_columns = array(ts('') => 'contact_type', | |
46 | ts('') => 'contact_sub_type', | |
47 | ts('Name') => 'sort_name', | |
48 | ts('Address') => 'street_address', | |
49 | ts('City') => 'city', | |
50 | ts('State') => 'state_province', | |
51 | ts('Postal') => 'postal_code', | |
52 | ts('Country') => 'country', | |
53 | ts('Email') => 'email', | |
54 | ts('Phone') => 'phone', | |
55 | ); | |
56 | ||
57 | $params = &CRM_Contact_BAO_Query::convertFormValues($this->_formValues); | |
58 | $returnProperties = array(); | |
59 | foreach ($this->_columns as $name => $field) { | |
60 | $returnProperties[$field] = 1; | |
61 | } | |
62 | ||
63 | $this->_query = new CRM_Contact_BAO_Query($params, $returnProperties, NULL, | |
64 | FALSE, FALSE, 1, FALSE, FALSE | |
65 | ); | |
66 | } | |
67 | ||
68 | /** | |
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) | |
72 | * | |
73 | * @return void | |
74 | * @access private | |
75 | */ | |
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; | |
81 | } | |
82 | ||
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; | |
87 | } | |
88 | ||
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; | |
93 | } | |
94 | ||
95 | return; | |
96 | } | |
97 | ||
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); | |
101 | ||
102 | // add select for groups | |
103 | $group = array('' => ts('- any group -')) + CRM_Core_PseudoConstant::group(); | |
104 | $form->addElement('select', 'group', ts('in'), $group); | |
105 | ||
106 | // add select for categories | |
cd43c5e3 | 107 | $tag = array('' => ts('- any tag -')) + CRM_Core_PseudoConstant::get('CRM_Core_DAO_EntityTag', 'tag_id', array('onlyActive' => FALSE)); |
6a488035 TO |
108 | $form->addElement('select', 'tag', ts('Tagged'), $tag); |
109 | ||
110 | // text for sort_name | |
111 | $form->add('text', 'sort_name', ts('Name')); | |
112 | ||
113 | $form->assign('elements', array('sort_name', 'contact_type', 'group', 'tag')); | |
114 | } | |
115 | ||
116 | function count() { | |
117 | return $this->_query->searchQuery(0, 0, NULL, TRUE); | |
118 | } | |
119 | ||
120 | function all($offset = 0, $rowCount = 0, $sort = NULL, | |
121 | $includeContactIDs = FALSE | |
122 | ) { | |
123 | return $this->_query->searchQuery($offset, $rowCount, $sort, | |
124 | FALSE, $includeContactIDs, | |
125 | FALSE, FALSE, TRUE | |
126 | ); | |
127 | } | |
128 | ||
129 | function from() { | |
130 | return $this->_query->_fromClause; | |
131 | } | |
132 | ||
133 | function where($includeContactIDs = FALSE) { | |
134 | if ($whereClause = $this->_query->whereClause()) { | |
135 | return $whereClause; | |
136 | } | |
137 | return ' (1) '; | |
138 | } | |
139 | ||
140 | function templateFile() { | |
141 | return 'CRM/Contact/Form/Search/Basic.tpl'; | |
142 | } | |
143 | } | |
144 |