diff --git a/CRM/Contact/DataProcessorContactSearch.php b/CRM/Contact/DataProcessorContactSearch.php index b5dd908bccd1bbac9868faded217564f844f8ece..2227c2830017d6436d51cb174d93827a41f31da3 100644 --- a/CRM/Contact/DataProcessorContactSearch.php +++ b/CRM/Contact/DataProcessorContactSearch.php @@ -35,7 +35,16 @@ class CRM_Contact_DataProcessorContactSearch implements UIOutputInterface { $fields[$field->alias] = $field->title; } - $form->add('text', 'title', E::ts('Title'), true); + $form->add('text', 'title', E::ts('Title'),NULL, true); + + // form elements for adding Dashlet + // $output['dashlet'] 1-> Yes 2->No + + if(isset($output['dashlet']) && $output['dashlet']==1){ + $form->add('text', 'dashlet_title', E::ts('Dashlet Title'), NULL, true); + $form->add('text', 'dashlet_name', E::ts('Dashlet Name (system name)'), NULL, true); + $form->add('select', 'dashlet_active', E::ts('Is Dashlet Active ?'), array(1=>'Yes', 0=> 'No'), true); + } $form->add('select','permission', E::ts('Permission'), \CRM_Core_Permission::basicPermissions(), true, array( 'style' => 'min-width:250px', @@ -61,9 +70,15 @@ class CRM_Contact_DataProcessorContactSearch implements UIOutputInterface { $defaults = array(); if ($output) { + if (isset($output['permission'])) { $defaults['permission'] = $output['permission']; } + if (isset($output['dashlet_name'])) { + $defaults['dashlet_name'] = $output['dashlet_name']; + $defaults['dashlet_title'] = $output['dashlet_title']; + $defaults['dashlet_active'] = $output['dashlet_active']; + } if (isset($output['configuration']) && is_array($output['configuration'])) { if (isset($output['configuration']['contact_id_field'])) { $defaults['contact_id_field'] = $output['configuration']['contact_id_field']; @@ -88,6 +103,7 @@ class CRM_Contact_DataProcessorContactSearch implements UIOutputInterface { if (empty($defaults['title'])) { $defaults['title'] = civicrm_api3('DataProcessor', 'getvalue', array('id' => $output['data_processor_id'], 'return' => 'title')); } + $form->setDefaults($defaults); } @@ -119,6 +135,25 @@ class CRM_Contact_DataProcessorContactSearch implements UIOutputInterface { return $configuration; } + /** + * Process the submitted values and create a configuration array + * + * @param $submittedValues + * @param array $output + * @return array + */ + public function processDashletConfiguration($submittedValues) { + + $configuration['domain_id'] = 1; + $configuration['name'] = $submittedValues['dashlet_name']; + $configuration['label'] = $submittedValues['dashlet_title']; + $configuration['permission'] = $submittedValues['permission']; + $configuration['is_active'] = $submittedValues['dashlet_active']; + $configuration['cache_minutes'] = 60; + + return $configuration; + } + /** * Returns the url for the page/form this output will show to the user * diff --git a/CRM/Dataprocessor/Form/Output.php b/CRM/Dataprocessor/Form/Output.php index cea74b394ba643182208d863d028161f6ca7ee2f..1fc2c49366a12e861a21298462b728b5e318e3a0 100644 --- a/CRM/Dataprocessor/Form/Output.php +++ b/CRM/Dataprocessor/Form/Output.php @@ -13,6 +13,10 @@ class CRM_Dataprocessor_Form_Output extends CRM_Core_Form { private $id; + private $dashlet; + + private $dashlet_id; + private $output; /** @@ -28,7 +32,9 @@ class CRM_Dataprocessor_Form_Output extends CRM_Core_Form { * @access public */ function preProcess() { + $this->snippet = CRM_Utils_Request::retrieve('snippet', 'String'); + if ($this->snippet) { $this->assign('suppressForm', TRUE); $this->controller->_generateQFKey = FALSE; @@ -41,11 +47,34 @@ class CRM_Dataprocessor_Form_Output extends CRM_Core_Form { $this->id = CRM_Utils_Request::retrieve('id', 'Integer'); $this->assign('id', $this->id); + $dashlet = CRM_Utils_Request::retrieve('dashlet', 'Integer'); + // dashlet 1->Yes 2->No + if ($this->id) { $this->output = civicrm_api3('DataProcessorOutput', 'getsingle', array('id' => $this->id)); $this->assign('output', $this->output); $this->outputTypeClass = $factory->getOutputByName($this->output['type']); $this->assign('has_configuration', $this->outputTypeClass->hasConfiguration()); + + + // Check for Dashlet + $dashlet_url = $this->createDashletUrl($this->id,$this->dataProcessorId); + try{ + $result_dashlet = civicrm_api3('Dashboard', 'getsingle', [ + 'url' => $dashlet_url, + ]); + $this->dashlet = 1; + $this->dashlet_id = $result_dashlet['id']; + $this->output['dashlet'] = $this->dashlet; + $this->output['dashlet_name'] = $result_dashlet['name']; + $this->output['dashlet_title'] = $result_dashlet['label']; + $this->output['dashlet_active'] = $result_dashlet['is_active']; + } + catch(Exception $e){ + $this->dashlet = 2; + $this->output['dashlet'] = $this->dashlet; + } + } $type = CRM_Utils_Request::retrieve('type', 'String'); @@ -57,6 +86,10 @@ class CRM_Dataprocessor_Form_Output extends CRM_Core_Form { if (!$this->output) { $this->output['data_processor_id'] = $this->dataProcessorId; } + if($dashlet){ + $this->dashlet = $dashlet; + $this->output['dashlet'] = $this->dashlet; + } $title = E::ts('Data Processor Output'); CRM_Utils_System::setTitle($title); @@ -73,7 +106,7 @@ class CRM_Dataprocessor_Form_Output extends CRM_Core_Form { $factory = dataprocessor_get_factory(); $types = array(' - select - ') + $factory->getOutputs(); $this->add('select', 'type', ts('Select output'), $types, true, array('class' => 'crm-select2')); - + $this->add('select', 'dashlet', E::ts('Add Output as Dashlet'), array(''=>' - select - ', 1=>'Yes', 2=> 'No'), true,array('id' => 'dashlet')); if ($this->outputTypeClass && $this->outputTypeClass->hasConfiguration()) { $this->outputTypeClass->buildConfigurationForm($this, $this->output); $this->assign('configuration_template', $this->outputTypeClass->getConfigurationTemplateFileName()); @@ -94,6 +127,9 @@ class CRM_Dataprocessor_Form_Output extends CRM_Core_Form { if (isset($this->output['type'])) { $defaults['type'] = $this->output['type']; } + if (isset($this->output['dashlet'])) { + $defaults['dashlet'] = $this->output['dashlet']; + } return $defaults; } @@ -132,10 +168,41 @@ class CRM_Dataprocessor_Form_Output extends CRM_Core_Form { $params['id'] = $this->id; } $params['configuration'] = $this->outputTypeClass->processConfiguration($values, $params); + $result = civicrm_api3('DataProcessorOutput', 'create', $params); + + if($this->dashlet == 1){ + + $dashlet_params = $this->outputTypeClass->processDashletConfiguration($values); + $dashlet_params['url'] = $this->createDashletUrl($result['id'],$this->dataProcessorId); + if ($this->dashlet_id) { + $dashlet_params['id'] = $this->dashlet_id; + } + $dashlet_result = civicrm_api3('Dashboard', 'create', $dashlet_params); + } + elseif($this->dashlet == 2){ + if ($this->dashlet_id) { + $dashlet_params['id'] = $this->dashlet_id; + $dashlet_result = civicrm_api3('Dashboard', 'delete', $dashlet_params); + } + } CRM_Utils_System::redirect($redirectUrl); parent::postProcess(); } + /** + * Returns the url for the dashlet url + * + * @param array $outputId + * @param array $dataProcessorId + * @return string + */ + + public function createDashletUrl($outputId,$dataProcessorId){ + $url = CRM_Utils_System::url('civicrm/dataprocessor/form/dashlet', array('outputId' => $outputId, 'dataProcessorId' => $dataProcessorId)); + //substr is used to remove starting slash + return substr($url, 1); + } + } diff --git a/CRM/Dataprocessor/Page/AJAX.php b/CRM/Dataprocessor/Page/AJAX.php new file mode 100644 index 0000000000000000000000000000000000000000..c6521c18338b3d3e0a8de159369bb7fd3d29f0bf --- /dev/null +++ b/CRM/Dataprocessor/Page/AJAX.php @@ -0,0 +1,71 @@ +<?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. | + | | + | 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 | + +--------------------------------------------------------------------+ + */ + +/** + * + * @package CRM + * @copyright CiviCRM LLC (c) 2004-2019 + * + */ + +/** + * This class contains all contact related functions that are called using AJAX (jQuery) + */ +class CRM_Dataprocessor_Page_AJAX { + + public static function getDashlet() { + + $outputId = CRM_Utils_Request::retrieve('outputId', 'Integer'); + $dataProcessorId = CRM_Utils_Request::retrieve('dataProcessorId', 'Integer'); + $dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $dataProcessorId)); + $dataProcessorClass = CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($dataProcessor); + + $results = []; + + try { + while($record = $dataProcessorClass->getDataFlow()->nextRecord()) { + $row = array(); + $row['record'] = $record; + $result = array(); + foreach($record as $key => $value) { + $result[$key] = $value->formattedValue; + } + + $results[] = $result; + } + } + catch (\Civi\DataProcessor\DataFlow\EndOfFlowException $e) { + // Do nothing + } + + $return_output['data'] = $results; + + CRM_Utils_JSON::output($return_output); + + } + +} diff --git a/CRM/Dataprocessor/Page/Dashlet.php b/CRM/Dataprocessor/Page/Dashlet.php new file mode 100644 index 0000000000000000000000000000000000000000..9f8cc95b0c17c0e12aeefce5460fdc3dafb91228 --- /dev/null +++ b/CRM/Dataprocessor/Page/Dashlet.php @@ -0,0 +1,72 @@ +<?php + +use CRM_Dataprocessor_ExtensionUtil as E; + +/** + * Main page for Data Processor Output dashlet + * + */ +class CRM_Dataprocessor_Page_Dashlet extends CRM_Core_Page { + + /** + * @var int + */ + private $outputId; + + /** + * @var int + */ + private $dataProcessorId; + + /** + * @var array + */ + private $dataProcessor; + + /** + * @var Civi\DataProcessor\ProcessorType\AbstractProcessorType + */ + private $dataProcessorClass; + + /** + * Pre Process the results + * + * @return void + */ + + protected function preProcess() { + $this->outputId = CRM_Utils_Request::retrieve('outputId', 'Integer'); + $this->dataProcessorId = CRM_Utils_Request::retrieve('dataProcessorId', 'Integer'); + + $this->dataProcessor = civicrm_api3('DataProcessor', 'getsingle', array('id' => $this->dataProcessorId)); + $this->dataProcessorClass = CRM_Dataprocessor_BAO_DataProcessor::dataProcessorToClass($this->dataProcessor); + $this->assign('dataProcessorId', $this->dataProcessorId); + $this->assign('outputId', $this->outputId); + } + + /** + * Dataprocessor Output as dashlet. + * + * @return void + */ + + public function run() { + $this->preProcess(); + $this->addColumnHeaders(); + + return parent::run(); + } + + /** + * Add the headers for the columns + * + */ + protected function addColumnHeaders() { + $columnHeaders = array(); + foreach($this->dataProcessorClass->getDataFlow()->getOutputFieldHandlers() as $outputFieldHandler) { + $field = $outputFieldHandler->getOutputFieldSpecification(); + $columnHeaders[$field->alias] = $field->title; + } + $this->assign('columnHeaders', $columnHeaders); + } +} diff --git a/CRM/DataprocessorSearch/Controller/CaseSearch.php b/CRM/DataprocessorSearch/Controller/CaseSearch.php index 9198fc75da1313ca19bb8e54ac777404234496b0..8008084b4dacf808d2f841375dde4b1cce25ddc7 100644 --- a/CRM/DataprocessorSearch/Controller/CaseSearch.php +++ b/CRM/DataprocessorSearch/Controller/CaseSearch.php @@ -55,7 +55,7 @@ class CRM_DataprocessorSearch_Controller_CaseSearch extends CRM_Core_Controller 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_CaseySearch) { + if (!$this->_pages[$pageName] instanceof CRM_DataprocessorSearch_Form_CaseSearch) { $session = CRM_Core_Session::singleton(); $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this); $urlPath = CRM_Utils_System::getUrlPath(); diff --git a/CRM/DataprocessorSearch/ParticipantSearch.php b/CRM/DataprocessorSearch/ParticipantSearch.php index 92697330383867fa6a2c116352d94a20033e0768..bd71f3b5f959de9d6a3fd2bf2fc6948538c2a823 100644 --- a/CRM/DataprocessorSearch/ParticipantSearch.php +++ b/CRM/DataprocessorSearch/ParticipantSearch.php @@ -27,6 +27,7 @@ class CRM_DataprocessorSearch_ParticipantSearch implements UIOutputInterface { * @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); @@ -36,7 +37,7 @@ class CRM_DataprocessorSearch_ParticipantSearch implements UIOutputInterface { $fields[$field->alias] = $field->title; } - $form->add('text', 'title', E::ts('Title'), true); + $form->add('text', 'title', E::ts('Title'), NULL,true); $form->add('select','permission', E::ts('Permission'), \CRM_Core_Permission::basicPermissions(), true, array( 'style' => 'min-width:250px', diff --git a/templates/CRM/Contact/Form/OutputConfiguration/DashletConfiguration.tpl b/templates/CRM/Contact/Form/OutputConfiguration/DashletConfiguration.tpl new file mode 100644 index 0000000000000000000000000000000000000000..3c657772f62ae2c98a606d266f92a7877559e2a1 --- /dev/null +++ b/templates/CRM/Contact/Form/OutputConfiguration/DashletConfiguration.tpl @@ -0,0 +1,22 @@ +{crmScope extensionKey='dataprocessor'} + +<div id="dashlet_configuration"> + <div class="crm-section"> + <div class="label">{$form.dashlet_title.label}</div> + <div class="content">{$form.dashlet_title.html}</div> + <div class="clear"></div> + </div> + <div class="crm-section"> + <div class="label">{$form.dashlet_name.label}</div> + <div class="content">{$form.dashlet_name.html}</div> + <div class="clear"></div> + </div> + <div class="crm-section"> + <div class="label">{$form.dashlet_active.label}</div> + <div class="content">{$form.dashlet_active.html}</div> + <div class="clear"></div> + </div> +</div> + +{/crmScope} + diff --git a/templates/CRM/Contact/Form/OutputConfiguration/DataProcessorContactSearch.tpl b/templates/CRM/Contact/Form/OutputConfiguration/DataProcessorContactSearch.tpl index 4a606293ef2e0aafff2b40c1c695a0cfa0f52665..7d0f459c1c4950a6f0fb516defed9067b2d80337 100644 --- a/templates/CRM/Contact/Form/OutputConfiguration/DataProcessorContactSearch.tpl +++ b/templates/CRM/Contact/Form/OutputConfiguration/DataProcessorContactSearch.tpl @@ -1,4 +1,5 @@ {crmScope extensionKey='dataprocessor'} + {include file='CRM/Contact/Form/OutputConfiguration/DashletConfiguration.tpl'} <div class="crm-section"> <div class="label">{$form.title.label}</div> <div class="content">{$form.title.html}</div> @@ -29,4 +30,5 @@ <div class="content">{$form.help_text.html}</div> <div class="clear"></div> </div> + {/crmScope} \ No newline at end of file diff --git a/templates/CRM/Dataprocessor/Form/Output.tpl b/templates/CRM/Dataprocessor/Form/Output.tpl index f0628bc93d11a4c0aeff8571d5123ec43d879360..e09526515c14da9c7d01fd83530dc8773bb830bf 100644 --- a/templates/CRM/Dataprocessor/Form/Output.tpl +++ b/templates/CRM/Dataprocessor/Form/Output.tpl @@ -20,6 +20,12 @@ <div class="content">{$form.type.html}</div> <div class="clear"></div> </div> + <div class="crm-section"> + <div class="label">{$form.dashlet.label}</div> + <div class="content">{$form.dashlet.html}</div> + <div class="clear"></div> + </div> + <div id="type_configuration"> {if ($configuration_template)} @@ -39,6 +45,16 @@ var id = {/literal}{if ($output)}{$output.id}{else}false{/if}{literal}; var data_processor_id = {/literal}{$data_processor_id}{literal}; + $('#dashlet').on('change', function() { + var type = $('#type').val(); + var dashlet_check = $('#dashlet').val(); + if(dashlet_check){ + console.log(dashlet_check); + var dataUrl = CRM.url('civicrm/dataprocessor/form/output', {type: type, 'data_processor_id': data_processor_id, 'id': id,'dashlet':dashlet_check}); + CRM.loadPage(dataUrl, {'target': '#type_configuration'}); + } + }); + $('#type').on('change', function() { var type = $('#type').val(); if (type) { @@ -47,7 +63,9 @@ } }); + $('#type').change(); + $('#dashlet').change(); }); {/literal} </script> diff --git a/templates/CRM/Dataprocessor/Page/Dashlet.tpl b/templates/CRM/Dataprocessor/Page/Dashlet.tpl new file mode 100644 index 0000000000000000000000000000000000000000..cb1d82ea21e50a376806a7d530b158decf4342d0 --- /dev/null +++ b/templates/CRM/Dataprocessor/Page/Dashlet.tpl @@ -0,0 +1,29 @@ +<div> + <table class="case-selector"> + <thead> + <tr> + {foreach from=$columnHeaders key=headerName item=headerTitle} + <th data-data={$headerName} class="crm-dashlet-{$headerName}" data-orderable="true"> + {$headerTitle} + </th> + {/foreach} + </tr> + </thead> + </table> +</div> + +{literal} +<script type="text/javascript"> +(function($) { +$('table.case-selector').DataTable({ + "pageLength":5, + "order":[], + "lengthMenu": [[5, 10, 20], [5, 10, 20]], + "searching": true, + "ajax": { + "url": {/literal}'{crmURL p="civicrm/ajax/getDashlet" q="dataProcessorId=$dataProcessorId&outputId=$outputId"}'{literal}, + } + }); +})(CRM.$); +</script> +{/literal} \ No newline at end of file diff --git a/xml/Menu/dataprocessor.xml b/xml/Menu/dataprocessor.xml index 73c5e0ae047dbb217b5b2828bb77e4a3fedbfb4e..84e26d4da71768cd4de520a5f713891e4accd4ec 100644 --- a/xml/Menu/dataprocessor.xml +++ b/xml/Menu/dataprocessor.xml @@ -63,10 +63,22 @@ <access_arguments>access CiviCRM</access_arguments> <access_arguments>administer CiviCRM</access_arguments> </item> + <item> + <path>civicrm/dataprocessor/form/dashlet</path> + <page_callback>CRM_Dataprocessor_Page_Dashlet</page_callback> + <title>DataProcessor</title> + <access_arguments>access CiviCRM</access_arguments> + <access_arguments>administer CiviCRM</access_arguments> + </item> <item> <path>civicrm/dataprocessor/form/output/download</path> <title>Browse Uploaded files</title> <access_arguments>access uploaded files</access_arguments> <page_callback>CRM_DataprocessorOutputExport_Page_Download</page_callback> </item> + <item> + <path>civicrm/ajax/getDashlet</path> + <page_callback>CRM_Dataprocessor_Page_AJAX::getDashlet</page_callback> + <access_arguments>access CiviCRM</access_arguments> +</item> </menu>