Merge pull request #5580 from eileenmcnaughton/CRM-16247
[civicrm-core.git] / CRM / Core / Form / Search.php
index 419a42923afb82db1300cd1fd84f3bde5af50708..9aba90f82489f07ab4f47dd399dc42b192b66a51 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -22,7 +22,7 @@
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  * Base class for most search forms
@@ -33,7 +33,6 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    * Are we forced to run a search
    *
    * @var int
-   * @access protected
    */
   protected $_force;
 
@@ -41,7 +40,6 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    * Name of search button
    *
    * @var string
-   * @access protected
    */
   protected $_searchButtonName;
 
@@ -49,7 +47,6 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    * Name of action button
    *
    * @var string
-   * @access protected
    */
   protected $_actionButtonName;
 
@@ -57,14 +54,12 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    * Form values that we will be using
    *
    * @var array
-   * @access public
    */
   public $_formValues;
 
   /**
    * Have we already done this search
    *
-   * @access protected
    * @var boolean
    */
   protected $_done;
@@ -72,15 +67,33 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
   /**
    * What context are we being invoked from
    *
-   * @access protected
    * @var string
    */
   protected $_context = NULL;
 
+  /**
+   * The list of tasks or actions that a searcher can perform on a result set.
+   *
+   * @var array
+   */
+  protected $_taskList = array();
+
+  /**
+   * Builds the list of tasks or actions that a searcher can perform on a result set.
+   *
+   * To modify the task list, child classes should alter $this->_taskList,
+   * preferably by extending this method.
+   *
+   * @return array
+   */
+  protected function buildTaskList() {
+    return $this->_taskList;
+  }
+
   /**
    * Common buildform tasks required by all searches
    */
-  function buildQuickform() {
+  public function buildQuickform() {
     $resources = CRM_Core_Resources::singleton();
 
     if ($resources->ajaxPopupsEnabled) {
@@ -88,7 +101,9 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
       $this->assign('includeWysiwygEditor', TRUE);
     }
 
-    $resources->addScriptFile('civicrm', 'js/crm.searchForm.js', 1, 'html-header');
+    $resources
+      ->addScriptFile('civicrm', 'js/crm.searchForm.js', 1, 'html-header')
+      ->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
 
     $this->addButtons(array(
       array(
@@ -99,12 +114,17 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
     ));
 
     $this->addClass('crm-search-form');
+
+    // for backwards compatibility we pass an argument to addTaskMenu even though
+    // it could just as well access $this->_taskList internally
+    $tasks = $this->buildTaskList();
+    $this->addTaskMenu($tasks);
   }
 
   /**
    * Add checkboxes for each row plus a master checkbox
    */
-  function addRowSelectors($rows) {
+  public function addRowSelectors($rows) {
     $this->addElement('checkbox', 'toggleSelect', NULL, NULL, array('class' => 'select-rows'));
     foreach ($rows as $row) {
       $this->addElement('checkbox', $row['checkbox'], NULL, NULL, array('class' => 'select-row'));
@@ -115,7 +135,7 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
    * Add actions menu to search results form
    * @param $tasks
    */
-  function addTaskMenu($tasks) {
+  public function addTaskMenu($tasks) {
     if (is_array($tasks) && !empty($tasks)) {
       $tasks = array('' => ts('Actions')) + $tasks;
       $this->add('select', 'task', NULL, $tasks, FALSE, array('class' => 'crm-select2 crm-action-menu huge crm-search-result-actions'));
@@ -128,4 +148,5 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
       $this->assign('ts_all_id', $allRowsRadio->_attributes['id']);
     }
   }
+
 }