Search code cleanup - move variables into parent class
[civicrm-core.git] / CRM / Event / Form / Search.php
index 3859a8a26448622cf93520a7e21066bfd92fa6b7..8ed56a77474f877cd43f97465cea6b7bfda40fe3 100644 (file)
@@ -1,9 +1,9 @@
 <?php
 /*
  +--------------------------------------------------------------------+
- | CiviCRM version 4.4                                                |
+ | CiviCRM version 4.5                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2013                                |
+ | Copyright CiviCRM LLC (c) 2004-2014                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
@@ -28,7 +28,7 @@
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2013
+ * @copyright CiviCRM LLC (c) 2004-2014
  * $Id$
  *
  */
 /**
  * This file is for civievent search
  */
-class CRM_Event_Form_Search extends CRM_Core_Form {
-
-  /**
-   * Are we forced to run a search
-   *
-   * @var int
-   * @access protected
-   */
-  protected $_force;
-
-  /**
-   * name of search button
-   *
-   * @var string
-   * @access protected
-   */
-  protected $_searchButtonName;
-
-  /**
-   * name of print button
-   *
-   * @var string
-   * @access protected
-   */
-  protected $_printButtonName;
-
-  /**
-   * name of action button
-   *
-   * @var string
-   * @access protected
-   */
-  protected $_actionButtonName;
-
-  /**
-   * form values that we will be using
-   *
-   * @var array
-   * @access protected
-   */
-  protected $_formValues;
+class CRM_Event_Form_Search extends CRM_Core_Form_Search {
 
   /**
    * the params that are sent to the query
@@ -90,14 +50,6 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
    */
   protected $_queryParams;
 
-  /**
-   * have we already done this search
-   *
-   * @access protected
-   * @var boolean
-   */
-  protected $_done;
-
   /**
    * are we restricting ourselves to a single contact
    *
@@ -114,14 +66,6 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
    */
   protected $_limit = NULL;
 
-  /**
-   * what context are we being invoked from
-   *
-   * @access protected
-   * @var string
-   */
-  protected $_context = NULL;
-
   /**
    * prefix for the controller
    *
@@ -151,7 +95,6 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
      * set the button names
      */
     $this->_searchButtonName = $this->getButtonName('refresh');
-    $this->_printButtonName = $this->getButtonName('next', 'print');
     $this->_actionButtonName = $this->getButtonName('next', 'action');
 
     $this->_done = FALSE;
@@ -233,6 +176,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
    * @return void
    */
   function buildQuickForm() {
+    parent::buildQuickForm();
     $this->addElement('text', 'sort_name', ts('Participant Name or Email'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Contact', 'sort_name'));
 
     CRM_Event_BAO_Query::buildSearchForm($this);
@@ -249,7 +193,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
           'toggleSelect',
           NULL,
           NULL,
-          array('onclick' => "toggleTaskAction( true ); return toggleCheckboxVals('mark_x_',this);")
+          array('onclick' => "toggleTaskAction( true );", 'class' => 'select-rows')
         );
       }
       foreach ($rows as $row) {
@@ -257,7 +201,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
         if (!$this->_single) {
           $this->addElement('checkbox', $row['checkbox'],
             NULL, NULL,
-            array('onclick' => "toggleTaskAction( true ); return checkSelectedBox('" . $row['checkbox'] . "');")
+            array('onclick' => "toggleTaskAction( true );", 'class' => 'select-row')
           );
         }
         if (CRM_Event_BAO_Event::usesPriceSet($row['event_id'])) {
@@ -275,11 +219,11 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
         if (CRM_Utils_Array::value('participant_test', $this->_formValues) == '1' || CRM_Utils_Array::value('participant_test', $this->_formValues) == '0' ) {
           $seatClause[] = "( participant.is_test = {$this->_formValues['participant_test']} )";
         }
-        if (CRM_Utils_Array::value('participant_status_id', $this->_formValues)) {
+        if (!empty($this->_formValues['participant_status_id'])) {
           $statuses = array_keys($this->_formValues['participant_status_id']);
           $seatClause[] = '( participant.status_id IN ( ' . implode(' , ', $statuses) . ' ) )';
         }
-        if (CRM_Utils_Array::value('participant_role_id', $this->_formValues)) {
+        if (!empty($this->_formValues['participant_role_id'])) {
           $roles = array_keys($this->_formValues['participant_role_id']);
           $seatClause[] = '( participant.role_id IN ( ' . implode(' , ', $roles) . ' ) )';
         }
@@ -297,7 +241,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
 
       $permission = CRM_Core_Permission::getPermission();
 
-      $tasks = array('' => ts('- actions -')) + CRM_Event_Task::permissionedTaskTitles($permission);
+      $tasks = CRM_Event_Task::permissionedTaskTitles($permission);
       if (isset($this->_ssID)) {
         if ($permission == CRM_Core_Permission::EDIT) {
           $tasks = $tasks + CRM_Event_Task::optionalTaskTitle();
@@ -311,39 +255,17 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
         $this->assign('ssID', $this->_ssID);
       }
 
-      $this->add('select', 'task', ts('Actions:') . ' ', $tasks);
-      $this->add('submit', $this->_actionButtonName, ts('Go'),
-        array(
-          'class' => 'form-submit',
-          'id' => 'Go',
-          'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 0);",
-        )
-      );
-
-      $this->add('submit', $this->_printButtonName, ts('Print'),
-        array(
-          'class' => 'form-submit',
-          'onclick' => "return checkPerformAction('mark_x', '" . $this->getName() . "', 1);",
-        )
-      );
+      $this->addTaskMenu($tasks);
 
       // need to perform tasks on all or selected items ? using radio_ts(task selection) for it
       $this->addElement('radio', 'radio_ts', NULL, '', 'ts_sel',
         array('checked' => 'checked')
       );
       $this->addElement('radio', 'radio_ts', NULL, '', 'ts_all',
-        array('onclick' => $this->getName() . ".toggleSelect.checked = false; toggleCheckboxVals('mark_x_',this); toggleTaskAction( true );")
+        array('class' => 'select-rows', 'onclick' => $this->getName() . ".toggleSelect.checked = false; toggleTaskAction( true );")
       );
     }
 
-    // add buttons
-    $this->addButtons(array(
-        array(
-          'type' => 'refresh',
-          'name' => ts('Search'),
-          'isDefault' => TRUE,
-        ),
-      ));
   }
 
   /**
@@ -398,7 +320,7 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
     $this->set('queryParams', $this->_queryParams);
 
     $buttonName = $this->controller->getButtonName();
-    if ($buttonName == $this->_actionButtonName || $buttonName == $this->_printButtonName) {
+    if ($buttonName == $this->_actionButtonName) {
       // check actionName and if next, then do not repeat a search, since we are going to the next page
 
       // hack, make sure we reset the task values
@@ -456,40 +378,11 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
    * This function is used to add the rules (mainly global rules) for form.
    * All local rules are added near the element
    *
-   * @return None
-   * @access public
-   * @see valid_date
-   */
-  function addRules() {
-    $this->addFormRule(array('CRM_Event_Form_Search', 'formRule'));
-  }
-
-  /**
-   * global validation rules for the form
-   *
-   * @param array $fields posted values of the form
-   * @param array $errors list of errors to be posted back to the form
-   *
    * @return void
-   * @static
    * @access public
+   * @see valid_date
    */
-  static function formRule($fields) {
-    $errors = array();
-
-    if ($fields['event_name'] && !is_numeric($fields['event_id'])) {
-      $errors['event_id'] = ts('Please select valid event.');
-    }
-
-    if ($fields['event_type'] && !is_numeric($fields['event_type_id'])) {
-      $errors['event_type'] = ts('Please select valid event type.');
-    }
-    if (!empty($errors)) {
-      return $errors;
-    }
-
-    return TRUE;
-  }
+  function addRules() {}
 
   /**
    * Set the default form values
@@ -580,6 +473,9 @@ class CRM_Event_Form_Search extends CRM_Core_Form {
     }
   }
 
+  /**
+   * @return null
+   */
   function getFormValues() {
     return NULL;
   }