Merge pull request #5379 from rohankatkar/webtest-4.6
[civicrm-core.git] / CRM / Core / Form / Search.php
CommitLineData
3efb5b86
CW
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
3efb5b86 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
3efb5b86
CW
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. |
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 along with this program; if not, contact CiviCRM LLC |
21 | at info[AT]civicrm[DOT]org. If you have questions about the |
22 | GNU Affero General Public License or the licensing of CiviCRM, |
23 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
24 +--------------------------------------------------------------------+
d25dd0ee 25 */
3efb5b86
CW
26
27/**
28 * Base class for most search forms
29 */
30class CRM_Core_Form_Search extends CRM_Core_Form {
31
48473171
CW
32 /**
33 * Are we forced to run a search
34 *
35 * @var int
48473171
CW
36 */
37 protected $_force;
38
39 /**
100fef9d 40 * Name of search button
48473171
CW
41 *
42 * @var string
48473171
CW
43 */
44 protected $_searchButtonName;
45
46 /**
100fef9d 47 * Name of action button
48473171
CW
48 *
49 * @var string
48473171
CW
50 */
51 protected $_actionButtonName;
52
53 /**
100fef9d 54 * Form values that we will be using
48473171
CW
55 *
56 * @var array
48473171
CW
57 */
58 public $_formValues;
59
60 /**
100fef9d 61 * Have we already done this search
48473171 62 *
48473171
CW
63 * @var boolean
64 */
65 protected $_done;
66
67 /**
100fef9d 68 * What context are we being invoked from
48473171 69 *
48473171
CW
70 * @var string
71 */
72 protected $_context = NULL;
73
7a3978aa
FG
74 /**
75 * The list of tasks or actions that a searcher can perform on a result set.
76 *
77 * @var array
78 */
79 protected $_taskList = array();
80
81 /**
82 * Builds the list of tasks or actions that a searcher can perform on a result set.
83 *
84 * To modify the task list, child classes should alter $this->_taskList,
85 * preferably by extending this method.
86 *
87 * @return array
88 */
89 protected function buildTaskList() {
90 return $this->_taskList;
91 }
92
34197a55
CW
93 /**
94 * Common buildform tasks required by all searches
95 */
00be9182 96 public function buildQuickform() {
3efb5b86
CW
97 $resources = CRM_Core_Resources::singleton();
98
99 if ($resources->ajaxPopupsEnabled) {
3efb5b86
CW
100 // Script needed by some popups
101 $this->assign('includeWysiwygEditor', TRUE);
102 }
103
562fda4b
CW
104 $resources
105 ->addScriptFile('civicrm', 'js/crm.searchForm.js', 1, 'html-header')
106 ->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
3efb5b86
CW
107
108 $this->addButtons(array(
109 array(
110 'type' => 'refresh',
111 'name' => ts('Search'),
112 'isDefault' => TRUE,
113 ),
114 ));
8d36b801 115
023e90c3 116 $this->addClass('crm-search-form');
7a3978aa
FG
117
118 // for backwards compatibility we pass an argument to addTaskMenu even though
119 // it could just as well access $this->_taskList internally
120 $tasks = $this->buildTaskList();
121 $this->addTaskMenu($tasks);
8d36b801
CW
122 }
123
124 /**
125 * Add checkboxes for each row plus a master checkbox
126 */
00be9182 127 public function addRowSelectors($rows) {
8d36b801
CW
128 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
129 foreach ($rows as $row) {
130 $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('class' => 'select-row'));
131 }
3efb5b86 132 }
34197a55
CW
133
134 /**
135 * Add actions menu to search results form
136 * @param $tasks
137 */
00be9182 138 public function addTaskMenu($tasks) {
34197a55
CW
139 if (is_array($tasks) && !empty($tasks)) {
140 $tasks = array('' => ts('Actions')) + $tasks;
141 $this->add('select', 'task', NULL, $tasks, FALSE, array('class' => 'crm-select2 crm-action-menu huge crm-search-result-actions'));
142 $this->add('submit', $this->_actionButtonName, ts('Go'), array('class' => 'hiddenElement crm-search-go-button'));
8d36b801
CW
143
144 // Radio to choose "All items" or "Selected items only"
145 $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
146 $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
147 $this->assign('ts_sel_id', $selectedRowsRadio->_attributes['id']);
148 $this->assign('ts_all_id', $allRowsRadio->_attributes['id']);
34197a55
CW
149 }
150 }
96025800 151
3efb5b86 152}