Skip to content
Snippets Groups Projects
Commit a944aeb2 authored by jaapjansma's avatar jaapjansma
Browse files

Merge branch 'master' into 'master'

added participant search

See merge request extensions/dataprocessor!1
parents 09d5ae6b 4946dc33
No related branches found
No related tags found
No related merge requests found
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
/**
* This class is used by the Search functionality.
*
* - the search controller is used for building/processing multiform
* searches.
*
* Typically the first form will display the search criteria and it's results
*
* The second form is used to process search results with the associated actions.
*/
class CRM_DataprocessorSearch_Controller_ParticipantSearch extends CRM_Core_Controller {
/**
* Class constructor.
*
* @param string $title
* @param bool $modal
* @param int|mixed|null $action
*/
public function __construct($title = NULL, $modal = TRUE, $action = CRM_Core_Action::NONE) {
parent::__construct($title, $modal);
$this->_stateMachine = new CRM_DataprocessorSearch_StateMachine_ParticipantSearch($this, $action);
// create and instantiate the pages
$this->addPages($this->_stateMachine, $action);
// add all the actions
$this->addActions();
}
/**
* Process the request, overrides the default QFC run method
* This routine actually checks if the QFC is modal and if it
* is the first invalid page, if so it call the requested action
* if not, it calls the display action on the first invalid page
* avoids the issue of users hitting the back button and getting
* a broken page
*
* This run is basically a composition of the original run and the
* jump action
*
* @return mixed
*/
public function run() {
$actionName = $this->getActionName();
list($pageName, $action) = $actionName;
// Hack to replace to userContext for redirecting after a Task has been completed.
// We want the redirect
if (!$this->_pages[$pageName] instanceof CRM_DataprocessorSearch_Form_ParticipantSearch) {
$session = CRM_Core_Session::singleton();
$qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
$urlPath = CRM_Utils_System::getUrlPath();
$urlParams = 'force=1';
if ($qfKey) {
$urlParams .= "&qfKey=$qfKey";
}
$this->setDestination(CRM_Utils_System::url($urlPath, $urlParams));
}
return parent::run();
}
/**
* @return mixed
*/
public function selectorName() {
return $this->get('selectorName');
}
}
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
use CRM_Dataprocessor_ExtensionUtil as E;
class CRM_DataprocessorSearch_Form_ParticipantSearch extends CRM_DataprocessorSearch_Form_AbstractSearch {
/**
* Returns the url for view of the record action
*
* @param $row
*
* @return false|string
*/
protected function link($row) {
return CRM_Utils_System::url('civicrm/contact/view/participant', 'reset=1&id='.$row['id'].'&cid='.$row['id'].'&action=view');
}
/**
* Returns the link text for view of the record action
*
* @param $row
*
* @return false|string
*/
protected function linkText($row) {
return E::ts('View participant');
}
/**
* Checks whether the output has a valid configuration
*
* @return bool
*/
protected function isConfigurationValid() {
if (!isset($this->dataProcessorOutput['configuration']['participant_id_field'])) {
return false;
}
return true;
}
/**
* Return the data processor ID
*
* @return String
*/
protected function getDataProcessorName() {
$dataProcessorName = str_replace('civicrm/dataprocessor_participant_search/', '', CRM_Utils_System::getUrlPath());
return $dataProcessorName;
}
/**
* Returns the name of the output for this search
*
* @return string
*/
protected function getOutputName() {
return 'participant_search';
}
/**
* Returns the name of the ID field in the dataset.
*
* @return string
*/
protected function getIdFieldName() {
return $this->dataProcessorOutput['configuration']['participant_id_field'];
}
/**
* @return string
*/
protected function getEntityTable() {
return 'civicrm_participant';
}
/**
* Returns whether we want to use the prevnext cache.
* @return bool
*/
protected function usePrevNextCache() {
return true;
}
/**
* Builds the list of tasks or actions that a searcher can perform on a result set.
*
* @return array
*/
public function buildTaskList() {
if (!$this->_taskList) {
$taskParams['deletedParticipants'] = FALSE;
$this->_taskList = CRM_Event_Task::permissionedTaskTitles(CRM_Core_Permission::getPermission(), $taskParams);
}
return $this->_taskList;
}
}
\ No newline at end of file
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
use Civi\DataProcessor\Output\UIOutputInterface;
use CRM_Dataprocessor_ExtensionUtil as E;
class CRM_DataprocessorSearch_ParticipantSearch implements UIOutputInterface {
/**
* Returns true when this filter has additional configuration
*
* @return bool
*/
public function hasConfiguration() {
return true;
}
/**
* When this filter type has additional configuration you can add
* the fields on the form with this function.
*
* @param \CRM_Core_Form $form
* @param array $filter
*/
public function buildConfigurationForm(\CRM_Core_Form $form, $output=array()) {
$navigation = CRM_Dataprocessor_Utils_Navigation::singleton();
$dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $output['data_processor_id']));
$dataProcessorClass = \CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($dataProcessor);
$fields = array();
foreach($dataProcessorClass->getDataFlow()->getOutputFieldHandlers() as $outputFieldHandler) {
$field = $outputFieldHandler->getOutputFieldSpecification();
$fields[$field->alias] = $field->title;
}
$form->add('text', 'title', E::ts('Title'), true);
$form->add('select','permission', E::ts('Permission'), \CRM_Core_Permission::basicPermissions(), true, array(
'style' => 'min-width:250px',
'class' => 'crm-select2 huge',
'placeholder' => E::ts('- select -'),
));
$form->add('select', 'participant_id_field', E::ts('Participant ID field'), $fields, true, array(
'style' => 'min-width:250px',
'class' => 'crm-select2 huge',
'placeholder' => E::ts('- select -'),
));
$form->add('select', 'hide_id_field', E::ts('Show participant ID field'), array(0=>'Participant ID is Visible', 1=> 'Participant ID is hidden'));
$form->add('wysiwyg', 'help_text', E::ts('Help text for this search'), array('rows' => 6, 'cols' => 80));
// navigation field
$navigationOptions = $navigation->getNavigationOptions();
if (isset($output['configuration']['navigation_id'])) {
$navigationPath = $navigation->getNavigationPathById($output['configuration']['navigation_id']);
unset($navigationOptions[$navigationPath]);
}
$form->add('select', 'navigation_parent_path', ts('Parent Menu'), array('' => ts('- select -')) + $navigationOptions, true);
$defaults = array();
if ($output) {
if (isset($output['permission'])) {
$defaults['permission'] = $output['permission'];
}
if (isset($output['configuration']) && is_array($output['configuration'])) {
if (isset($output['configuration']['participant_id_field'])) {
$defaults['participant_id_field'] = $output['configuration']['participant_id_field'];
}
if (isset($output['configuration']['navigation_id'])) {
$defaults['navigation_parent_path'] = $navigation->getNavigationParentPathById($output['configuration']['navigation_id']);
}
if (isset($output['configuration']['title'])) {
$defaults['title'] = $output['configuration']['title'];
}
if (isset($output['configuration']['hide_id_field'])) {
$defaults['hide_id_field'] = $output['configuration']['hide_id_field'];
}
if (isset($output['configuration']['help_text'])) {
$defaults['help_text'] = $output['configuration']['help_text'];
}
}
}
if (!isset($defaults['permission'])) {
$defaults['permission'] = 'access CiviCRM';
}
if (empty($defaults['title'])) {
$defaults['title'] = civicrm_api3('DataProcessor', 'getvalue', array('id' => $output['data_processor_id'], 'return' => 'title'));
}
$form->setDefaults($defaults);
}
/**
* When this filter type has configuration specify the template file name
* for the configuration form.
*
* @return false|string
*/
public function getConfigurationTemplateFileName() {
return "CRM/DataprocessorSearch/Form/OutputConfiguration/ParticipantSearch.tpl";
}
/**
* Process the submitted values and create a configuration array
*
* @param $submittedValues
* @param array $output
* @return array
*/
public function processConfiguration($submittedValues, &$output) {
$output['permission'] = $submittedValues['permission'];
$configuration['title'] = $submittedValues['title'];
$configuration['participant_id_field'] = $submittedValues['participant_id_field'];
$configuration['navigation_parent_path'] = $submittedValues['navigation_parent_path'];
$configuration['hide_id_field'] = $submittedValues['hide_id_field'];
$configuration['help_text'] = $submittedValues['help_text'];
return $configuration;
}
/**
* Returns the url for the page/form this output will show to the user
*
* @param array $output
* @param array $dataProcessor
* @return string
*/
public function getUrlToUi($output, $dataProcessor) {
return "civicrm/dataprocessor_participant_search/{$dataProcessor['name']}";
}
/**
* Returns the url for the page/form this output will show to the user
*
* @param array $output
* @param array $dataProcessor
* @return string
*/
public function getTitleForUiLink($output, $dataProcessor) {
return isset($output['configuration']['title']) ? $output['configuration']['title'] : $dataProcessor['title'];
}
/**
* Returns the url for the page/form this output will show to the user
*
* @param array $output
* @param array $dataProcessor
* @return string|false
*/
public function getIconForUiLink($output, $dataProcessor) {
return false;
}
/**
* Returns the callback for the UI.
*
* @return string
*/
public function getCallbackForUi() {
return 'CRM_DataprocessorSearch_Controller_ParticipantSearch';
}
/**
* Checks whether the current user has access to this output
*
* @param array $output
* @param array $dataProcessor
* @return bool
*/
public function checkUIPermission($output, $dataProcessor) {
return CRM_Core_Permission::check(array(
$output['permission']
));
}
}
\ No newline at end of file
<?php
/**
* @author Jaap Jansma <jaap.jansma@civicoop.org>
* @license AGPL-3.0
*/
class CRM_DataprocessorSearch_StateMachine_ParticipantSearch extends CRM_Core_StateMachine {
/**
* The task that the wizard is currently processing
*
* @var string
*/
protected $_task;
/**
* Class constructor.
*
* @param object $controller
* @param \const|int $action
*/
public function __construct($controller, $action = CRM_Core_Action::NONE) {
parent::__construct($controller, $action);
$this->_pages = array();
$this->_pages['Basic'] = array(
'className' => 'CRM_DataprocessorSearch_Form_ParticipantSearch',
);
list($task, $result) = $this->taskName($controller);
$this->_task = $task;
if (is_array($task)) {
foreach ($task as $t) {
$this->_pages[$t] = NULL;
}
}
else {
$this->_pages[$task] = NULL;
}
if ($result) {
$this->_pages['CRM_Participant_Form_Task_Result'] = NULL;
}
$this->addSequentialPages($this->_pages, $action);
}
/**
* Determine the form name based on the action. This allows us
* to avoid using conditional state machine, much more efficient
* and simpler
*
* @param CRM_Core_Controller $controller
* The controller object.
*
* @return array
* the name of the form that will handle the task
*/
public function taskName($controller) {
// total hack, check POST vars and then session to determine stuff
$value = CRM_Utils_Array::value('task', $_POST);
if (!isset($value)) {
$value = $controller->get('task');
}
$this->_controller->set('task', $value);
return CRM_Event_Task::getTask($value);
}
/**
* Return the form name of the task.
*
* @return string
*/
public function getTaskFormName() {
if (is_array($this->_task)) {
// return first page
return CRM_Utils_String::getClassName($this->_task[0]);
}
else {
return CRM_Utils_String::getClassName($this->_task);
}
}
/**
* Since this is a state machine for search and we want to come back to the same state
* we dont want to issue a reset of the state session when we are done processing a task
*/
public function shouldReset() {
return FALSE;
}
}
......@@ -123,6 +123,7 @@ class Factory {
$this->addOutput('api', 'Civi\DataProcessor\Output\Api', E::ts('API'));
$this->addOutput('contact_search', 'CRM_DataprocessorSearch_ContactSearch', E::ts('Contact Search'));
$this->addOutput('activity_search', 'CRM_DataprocessorSearch_ActivitySearch', E::ts('Activity Search'));
$this->addOutput('participant_search', 'CRM_DataprocessorSearch_ParticipantSearch', E::ts('Participant Search'));
$this->addOutput('export_csv', 'CRM_DataprocessorOutputExport_CSV', E::ts('CSV Export'));
$this->addFilter('simple_sql_filter', 'Civi\DataProcessor\FilterHandler\SimpleSqlFilter', E::ts('Field filter'));
$this->addjoinType('simple_join', 'Civi\DataProcessor\DataFlow\MultipleDataFlows\SimpleJoin', E::ts('Select fields to join on'));
......
{crmScope extensionKey='dataprocessor'}
<div class="crm-section">
<div class="label">{$form.title.label}</div>
<div class="content">{$form.title.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.navigation_parent_path.label}</div>
<div class="content">{$form.navigation_parent_path.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.permission.label}</div>
<div class="content">{$form.permission.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.participant_id_field.label}</div>
<div class="content">{$form.participant_id_field.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.hide_id_field.label}</div>
<div class="content">{$form.hide_id_field.html}</div>
<div class="clear"></div>
</div>
<div class="crm-section">
<div class="label">{$form.help_text.label}</div>
<div class="content">{$form.help_text.html}</div>
<div class="clear"></div>
</div>
{/crmScope}
\ No newline at end of file
{include file="CRM/DataprocessorSearch/Form/Search.tpl"}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment