3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
29 * Base class for most search forms
31 class CRM_Core_Form_Search
extends CRM_Core_Form
{
34 * Are we forced to run a search
41 * Name of search button
45 protected $_searchButtonName;
48 * Name of action button
52 protected $_actionButtonName;
55 * Form values that we will be using
62 * Have we already done this search
69 * What context are we being invoked from
73 protected $_context = NULL;
76 * The list of tasks or actions that a searcher can perform on a result set.
80 protected $_taskList = array();
83 * Builds the list of tasks or actions that a searcher can perform on a result set.
85 * To modify the task list, child classes should alter $this->_taskList,
86 * preferably by extending this method.
90 protected function buildTaskList() {
91 return $this->_taskList
;
95 * Common buildform tasks required by all searches
97 public function buildQuickform() {
98 CRM_Core_Resources
::singleton()
99 ->addScriptFile('civicrm', 'js/crm.searchForm.js', 1, 'html-header')
100 ->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
102 $this->addButtons(array(
105 'name' => ts('Search'),
110 $this->addClass('crm-search-form');
112 // for backwards compatibility we pass an argument to addTaskMenu even though
113 // it could just as well access $this->_taskList internally
114 $tasks = $this->buildTaskList();
115 $this->addTaskMenu($tasks);
119 * Add checkboxes for each row plus a master checkbox
121 public function addRowSelectors($rows) {
122 $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
124 foreach ($rows as $row) {
125 if (CRM_Utils_Array
::value('checkbox', $row)) {
126 $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('class' => 'select-row'));
133 * Add actions menu to search results form
136 public function addTaskMenu($tasks) {
137 if (is_array($tasks) && !empty($tasks)) {
138 $tasks = array('' => ts('Actions')) +
$tasks;
139 $this->add('select', 'task', NULL, $tasks, FALSE, array('class' => 'crm-select2 crm-action-menu huge crm-search-result-actions'));
140 $this->add('submit', $this->_actionButtonName
, ts('Go'), array('class' => 'hiddenElement crm-search-go-button'));
142 // Radio to choose "All items" or "Selected items only"
143 $selectedRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel', array('checked' => 'checked'));
144 $allRowsRadio = $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all');
145 $this->assign('ts_sel_id', $selectedRowsRadio->_attributes
['id']);
146 $this->assign('ts_all_id', $allRowsRadio->_attributes
['id']);