Skip to content

Commit

Permalink
dev: Moved export styles to plugin
Browse files Browse the repository at this point in the history
dev: used authdb since that is always enabled, we should move all core plugins that can not be deactivated here to prevent clutter in the plugin screen
dev: still todo: move r and spss here and update remote control
  • Loading branch information
mennodekker committed Aug 9, 2013
1 parent cdba9f0 commit 2dcb8c4
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 53 deletions.
3 changes: 2 additions & 1 deletion application/controllers/admin/export.php
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,8 @@ public function exportresults()
$oPluginManager->dispatchEvent($event, $plugin);
$exportData[$key] = array(
'onclick' => $event->get('onclick'),
'label' => $event->get('label')
'label' => $event->get('label'),
'checked' => $event->get('default', false)
);
}

Expand Down
109 changes: 108 additions & 1 deletion application/core/plugins/Authdb/Authdb.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Authdb extends AuthPluginBase

protected $_onepass = null;

static protected $description = 'Core: Database authentication';
static protected $description = 'Core: Database authentication + exports';
static protected $name = 'LimeSurvey internal database';

public function __construct(PluginManager $manager, $id) {
Expand All @@ -19,6 +19,12 @@ public function __construct(PluginManager $manager, $id) {
$this->subscribe('afterLoginFormSubmit');
$this->subscribe('newUserSession');
$this->subscribe('beforeDeactivate');

// Now register for the core exports
$this->subscribe('listExportPlugins');
$this->subscribe('listExportOptions');
$this->subscribe('newExport');

}

public function beforeDeactivate()
Expand Down Expand Up @@ -126,4 +132,105 @@ protected function setOnePass($onepass)

return $this;
}


// Now the export part:
public function listExportOptions()
{
$event = $this->getEvent();
$type = $event->get('type');

switch ($type) {
case 'csv':
$event->set('label', gT("CSV File (All charsets)"));
$event->set('onclick', 'document.getElementById("ansabbrev").disabled=false;');
if (!function_exists('iconv')) {
$event->set('default', true);
}
break;

case 'xls':
$label = gT("Microsoft Excel (All charsets)");
if (function_exists('iconv')) {
$event->set('default', true);
} else {
$label .= '<font class="warningtitle">'.$clang->gT("(Iconv Library not installed)").'</font>';
}
$event->set('label', $label);
$event->set('onclick', 'document.getElementById("ansabbrev").disabled=false;');
break;

case 'doc':
$event->set('label', gT("Microsoft Word (Latin charset)"));
$event->set('onclick', 'document.getElementById("ansfull").checked=true;document.getElementById("ansabbrev").disabled=true;');
break;

case 'pdf':
$event->set('label', gT("PDF"));
$event->set('onclick', 'document.getElementById("ansabbrev").disabled=false;');
break;

case 'html':
$event->set('label', gT("HTML"));
$event->set('onclick', 'document.getElementById("ansabbrev").disabled=false;');
break;

case 'json': // Not in the interface, only for RPC
default:
break;
}
}

/**
* Registers this export type
*/
public function listExportPlugins()
{
$event = $this->getEvent();
$exports = $event->get('exportplugins');

// Yes we overwrite existing classes if available
$className = get_class();
$exports['doc'] = $className;
$exports['xls'] = $className;
$exports['pdf'] = $className;
$exports['html'] = $className;
$exports['json'] = $className;
$exports['csv'] = $className;

$event->set('exportplugins', $exports);
}

/**
* Returns the required IWriter
*/
public function newExport()
{
$event = $this->getEvent();
$type = $event->get('type');

switch ($type) {
case "doc":
$writer = new DocWriter();
break;
case "xls":
$writer = new ExcelWriter();
break;
case "pdf":
$writer = new PdfWriter();
break;
case "html":
$writer = new HtmlWriter();
break;
case "json":
$writer = new JsonWriter();
break;
case "csv":
default:
$writer = new CsvWriter();
break;
}

$event->set('writer', $writer);
}
}
32 changes: 0 additions & 32 deletions application/helpers/admin/exportresults_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,6 @@ function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOpti
$oPluginManager = App()->getPluginManager();
$oPluginManager->dispatchEvent($event, $exports[$sExportPlugin]);
$writer = $event->get('writer');
} else {
// fallback for core exports before ported to a plugin
switch ( $sExportPlugin ) {
case "doc":
$writer = new DocWriter();
break;
case "xls":
$writer = new ExcelWriter();
break;
case "pdf":
$writer = new PdfWriter();
break;
case "html":
$writer = new HtmlWriter();
break;
case "json":
$writer = new JsonWriter();
break;
case "csv":
default:
$writer = new CsvWriter();
break;
}
}

if (!($writer instanceof IWriter)) {
Expand Down Expand Up @@ -155,15 +132,6 @@ function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOpti
public function getExports()
{
if (is_null($this->_exports)) {
// Add the core exports before they are plugins
$exports = array(
'doc' => '',
'xls' => '',
'pdf' => '',
'html' => '',
'csv' => '',
'json' => ''
);
$event = new PluginEvent('listExportPlugins');
$oPluginManager = App()->getPluginManager();
$oPluginManager->dispatchEvent($event);
Expand Down
21 changes: 2 additions & 19 deletions application/views/admin/export/exportresults_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,7 @@
<?php $clang->eT("Full answers");?></label></li>
</ul></fieldset>
<fieldset><legend><?php $clang->eT("Format");?></legend>
<ul>
<li><input type='radio' class='radiobtn' name='type' value='csv' id='csvdoc' <?php if (!function_exists('iconv'))
{ echo 'checked="checked" ';} ?> onclick='document.getElementById("ansabbrev").disabled=false;' />
<label for='csvdoc'><?php $clang->eT("CSV File (All charsets)");?></label></li>
<li><input type='radio' class='radiobtn' name='type' value='xls' checked id='exceldoc' <?php if (!function_exists('iconv')) echo ' disabled="disabled" ';?> onclick='document.getElementById("ansabbrev").disabled=false;' />
<label for='exceldoc'><?php $clang->eT("Microsoft Excel (All charsets)");?><?php if (!function_exists('iconv'))
{ echo '<font class="warningtitle">'.$clang->gT("(Iconv Library not installed)").'</font>'; } ?>
</label></li>
<li>
<input type='radio' class='radiobtn' name='type' value='doc' id='worddoc' onclick='document.getElementById("ansfull").checked=true;document.getElementById("ansabbrev").disabled=true;' />
<label for='worddoc'>
<?php $clang->eT("Microsoft Word (Latin charset)");?></label></li>
<li><input type='radio' class='radiobtn' name='type' value='pdf' id='pdfdoc' onclick='document.getElementById("ansabbrev").disabled=false;' />
<label for='pdfdoc'><?php $clang->eT("PDF");?><br />
</label></li>
<li><input type='radio' class='radiobtn' name='type' value='html' id='htmldoc' onclick='document.getElementById("ansabbrev").disabled=false;'/>
<label for='htmldoc'><?php $clang->eT("HTML");?><br />
</label></li>
<ul>
<?php
foreach ($exports as $key => $info)
{
Expand All @@ -88,7 +71,7 @@
$htmlOptions['onclick'] = $info['onclick'];
}
echo CHtml::openTag('li');
echo CHtml::radioButton('type', false, $htmlOptions);
echo CHtml::radioButton('type', $info['checked'], $htmlOptions);
echo " "; // Needed to get space between radio element and label
echo CHtml::label($info['label'] . CHtml::tag('br'), $key);
echo CHtml::closeTag('li');
Expand Down

0 comments on commit 2dcb8c4

Please sign in to comment.