<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 5 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
- | |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
+ | Copyright CiviCRM LLC. All rights reserved. |
| |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
- * @copyright CiviCRM LLC (c) 2004-2019
- */
-
-/**
- * Files required
+ * @copyright CiviCRM LLC https://civicrm.org/licensing
*/
/**
/**
* Are we restricting ourselves to a single contact.
*
- * @var boolean
+ * @var bool
*/
protected $_single = FALSE;
/**
* Are we restricting ourselves to a single contact.
*
- * @var boolean
+ * @var bool
*/
protected $_limit = NULL;
/**
* Prefix for the controller.
+ * @var string
*/
protected $_prefix = "event_";
*/
protected $_ssID;
+ /**
+ * Metadata of all fields to include on the form.
+ *
+ * @var array
+ */
+ protected $searchFieldMetadata = [];
+
+ /**
+ * Get the default entity for the form.
+ *
+ * @return string
+ */
+ public function getDefaultEntity() {
+ return 'Participant';
+ }
+
/**
* Processing needed for buildForm and later.
*
* @return void
+ *
+ * @throws \CRM_Core_Exception
+ * @throws \CiviCRM_API3_Exception
*/
public function preProcess() {
$this->set('searchFormName', 'Search');
$this->_actionButtonName = $this->getButtonName('next', 'action');
$this->_done = FALSE;
- $this->defaults = array();
-
- $this->loadStandardSearchOptionsFromUrl();
- $this->loadFormValues();
- if ($this->_force) {
- $this->postProcess();
- $this->set('force', 0);
- }
+ parent::preProcess();
- $sortID = NULL;
- if ($this->get(CRM_Utils_Sort::SORT_ID)) {
- $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
- $this->get(CRM_Utils_Sort::SORT_DIRECTION)
- );
- }
-
- $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id'));
+ $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, ['event_id']);
$selector = new CRM_Event_Selector_Search($this->_queryParams,
$this->_action,
NULL,
$controller = new CRM_Core_Selector_Controller($selector,
$this->get(CRM_Utils_Pager::PAGE_ID),
- $sortID,
+ $this->getSortID(),
CRM_Core_Action::VIEW,
$this,
CRM_Core_Selector_Controller::TRANSFER,
/**
* Build the form object.
*
- *
* @return void
+ *
+ * @throws \CRM_Core_Exception
*/
public function buildQuickForm() {
parent::buildQuickForm();
$rows = $this->get('rows');
if (is_array($rows)) {
- $lineItems = $eventIds = array();
+ $lineItems = $eventIds = [];
if (!$this->_single) {
$this->addRowSelectors($rows);
}
$participantCount = 0;
if (count($eventIds) == 1) {
//convert form values to clause.
- $seatClause = array();
+ $seatClause = [];
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 (!empty($this->_formValues['participant_status_id'])) {
- $seatClause[] = CRM_Contact_BAO_Query::buildClause("participant.status_id", '=', $this->_formValues['participant_status_id'], 'Int');
+ $seatClause[] = CRM_Contact_BAO_Query::buildClause("participant.status_id", 'IN', $this->_formValues['participant_status_id'], 'Int');
if ($status = CRM_Utils_Array::value('IN', $this->_formValues['participant_status_id'])) {
$this->_formValues['participant_status_id'] = $status;
}
}
if (!empty($this->_formValues['participant_role_id'])) {
- $escapedRoles = array();
+ $escapedRoles = [];
foreach ((array) $this->_formValues['participant_role_id'] as $participantRole) {
$escapedRoles[] = CRM_Utils_Type::escape($participantRole, 'String');
}
// CRM-15379
if (!empty($this->_formValues['participant_fee_id'])) {
$participant_fee_id = $this->_formValues['participant_fee_id'];
+ $val_regexp = [];
foreach ($participant_fee_id as $k => &$val) {
$val = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceFieldValue', $val, 'label');
+ $val_regexp[$k] = CRM_Core_DAO::escapeString(preg_quote(trim($val)));
$val = CRM_Core_DAO::escapeString(trim($val));
}
- $feeLabel = implode('|', $participant_fee_id);
+ $feeLabel = implode('|', $val_regexp);
$seatClause[] = "( participant.fee_level REGEXP '{$feeLabel}' )";
}
$tasks = CRM_Event_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission(), $taskParams);
if (isset($this->_ssID)) {
- $savedSearchValues = array(
+ $savedSearchValues = [
'id' => $this->_ssID,
'name' => CRM_Contact_BAO_SavedSearch::getName($this->_ssID, 'title'),
- );
+ ];
$this->assign_by_ref('savedSearch', $savedSearchValues);
$this->assign('ssID', $this->_ssID);
}
}
/**
- * The post processing of the form gets done here.
- *
- * Key things done during post processing are
- * - check for reset or next request. if present, skip post procesing.
- * - now check if user requested running a saved search, if so, then
- * the form values associated with the saved search are used for searching.
- * - if user has done a submit with new values the regular post submissing is
- * done.
- * The processing consists of using a Selector / Controller framework for getting the
- * search results.
- *
- * @param
- *
- * @return void
+ * Test submit the form.
+ * @param $formValues
*/
- public function postProcess() {
- if ($this->_done) {
- return;
- }
-
- $this->_done = TRUE;
-
- if (!empty($_POST)) {
- $this->_formValues = $this->controller->exportValues($this->_name);
- CRM_Contact_BAO_Query::processSpecialFormValue($this->_formValues, array('participant_status_id'));
- }
+ public function testSubmit($formValues) {
+ $this->submit($formValues);
+ }
- if (empty($this->_formValues)) {
- $this->_formValues = $this->controller->exportValues($this->_name);
- }
+ /**
+ * Submit the search form with given values.
+ * @param $formValues
+ */
+ private function submit($formValues) {
+ $this->_formValues = $formValues;
$this->fixFormValues();
CRM_Core_BAO_CustomValue::fixCustomFieldValue($this->_formValues);
- $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id'));
+ $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, ['event_id']);
$this->set('formValues', $this->_formValues);
$this->set('queryParams', $this->_queryParams);
return;
}
- $sortID = NULL;
- if ($this->get(CRM_Utils_Sort::SORT_ID)) {
- $sortID = CRM_Utils_Sort::sortIDValue($this->get(CRM_Utils_Sort::SORT_ID),
- $this->get(CRM_Utils_Sort::SORT_DIRECTION)
- );
- }
-
- $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, array('event_id'));
+ $this->_queryParams = CRM_Contact_BAO_Query::convertFormValues($this->_formValues, 0, FALSE, NULL, ['event_id']);
$selector = new CRM_Event_Selector_Search($this->_queryParams,
$this->_action,
$controller = new CRM_Core_Selector_Controller($selector,
$this->get(CRM_Utils_Pager::PAGE_ID),
- $sortID,
+ $this->getSortID(),
CRM_Core_Action::VIEW,
$this,
CRM_Core_Selector_Controller::SESSION,
}
/**
- * add the rules (mainly global rules) for form.
- * All local rules are added near the element
+ * The post processing of the form gets done here.
+ *
+ * Key things done during post processing are
+ * - check for reset or next request. if present, skip post procesing.
+ * - now check if user requested running a saved search, if so, then
+ * the form values associated with the saved search are used for searching.
+ * - if user has done a submit with new values the regular post submissing is
+ * done.
+ * The processing consists of using a Selector / Controller framework for getting the
+ * search results.
+ *
+ * @param
*
* @return void
- * @see valid_date
+ * @throws \CRM_Core_Exception
*/
- public function addRules() {
+ public function postProcess() {
+ if ($this->_done) {
+ return;
+ }
+
+ $this->_done = TRUE;
+ $formValues = $this->getFormValues();
+
+ $this->submit($formValues);
}
/**
- * Set the default form values.
- *
+ * add the rules (mainly global rules) for form.
+ * All local rules are added near the element
*
- * @return array
- * the default array reference
+ * @return void
+ * @see valid_date
*/
- public function setDefaultValues() {
- $defaults = array();
- $defaults = $this->_formValues;
- return $defaults;
+ public function addRules() {
}
public function fixFormValues() {
elseif (is_array($status) && !array_key_exists('IN', $status)) {
$statusTypes = array_keys($status);
}
- $this->_formValues['participant_status_id'] = is_array($statusTypes) ? array('IN' => array_keys($statusTypes)) : $statusTypes;
+ $this->_formValues['participant_status_id'] = is_array($statusTypes) ? ['IN' => array_keys($statusTypes)] : $statusTypes;
}
$role = CRM_Utils_Request::retrieve('role', 'String');
}
}
- /**
- * @return null
- */
- public function getFormValues() {
- return NULL;
- }
-
/**
* Return a descriptive name for the page, used in wizard header
*
return ts('Find Participants');
}
+ /**
+ * Set the metadata for the form.
+ *
+ * @throws \CiviCRM_API3_Exception
+ */
+ protected function setSearchMetadata() {
+ $this->addSearchFieldMetadata(['Participant' => CRM_Event_BAO_Query::getSearchFieldMetadata()]);
+ }
+
+ /**
+ * Set the default form values.
+ *
+ *
+ * @return array
+ * the default array reference
+ */
+ public function setDefaultValues() {
+ parent::setDefaultValues();
+ return $this->_formValues;
+ }
+
}