Skip to content

Commit

Permalink
New feature #07687 : RemoteControl2 export_responses should also have…
Browse files Browse the repository at this point in the history
… an Array / JSON with responses
  • Loading branch information
Shnoulle committed Aug 4, 2013
1 parent 0954b64 commit a500513
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 7 deletions.
69 changes: 69 additions & 0 deletions application/helpers/admin/export/JsonWriter.php
@@ -0,0 +1,69 @@
<?php
class JsonWriter extends Writer
{
private $output;
/**
* The open filehandle
*/
private $file = null;
/**
* first don't need seperator
*/
protected $havePrev = false;

function __construct()
{
$this->output = '';
}

public function init(SurveyObj $survey, $sLanguageCode, FormattingOptions $oOptions)
{
parent::init($survey, $sLanguageCode, $oOptions);
$sStartOutput='{'.json_encode("responses").': [';
if ($oOptions->output=='display') {
header("Content-type: application/json");
echo $sStartOutput;
} elseif ($oOptions->output == 'file') {
$this->file = fopen($this->filename, 'w');
fwrite($this->file, $sStartOutput);
}

}

protected function outputRecord($headers, $values, FormattingOptions $oOptions)
{
$aJson[$values[0]]=array_combine ($headers,$values);

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Aug 4, 2013

Author Collaborator

Don't know id anser id os OK, maybe best then index (0,1,2, ...)

$sJson=json_encode($aJson);
Yii::log($this->havePrev, 'info', 'info');
if($this->havePrev){
$sJson=','.$sJson;

}
$this->havePrev=true;
if ($oOptions->output=='display')
{
echo $sJson;
$this->output = '';
} elseif ($oOptions->output == 'file') {
$this->output .= $sJson;
fwrite($this->file, $this->output);
$this->output='';
}

}

public function close()
{
$sEndOutput=']}';
if (!$this->file)
{
echo $sEndOutput;
}
else
{
$this->output .= $sEndOutput;
fwrite($this->file, $this->output);
fclose($this->file);
}
}
}
8 changes: 6 additions & 2 deletions application/helpers/admin/exportresults_helper.php
Expand Up @@ -85,7 +85,8 @@ function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOpti
'xls' => '',
'pdf' => '',
'html' => '',
'csv' => ''
'csv' => '',
'json' => ''

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Aug 4, 2013

Author Collaborator

Think it's better in core than in Plugin.

This comment has been minimized.

Copy link
@SamMousa

SamMousa via email Aug 4, 2013

Contributor

This comment has been minimized.

Copy link
@mennodekker

mennodekker Aug 5, 2013

Contributor

It should be a plugin --> no changes needed for this file when it is a plugin. I am going to work on plugins and will convert all core exports to a plugin so i will create the plugin for this one as well.

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Aug 5, 2013

Author Collaborator

Hi.
XLSwriter are not n Plugin, Think core can be CSV and JSON.

But have to move vv to plugin too ....

We don't have importPlugin actually ?

This comment has been minimized.

Copy link
@mennodekker

mennodekker Aug 5, 2013

Contributor

I will move all current exports to plugin, so that includes xls, pdf, html, csv, r, spss and json. We can decide per export if it can be disabled or not.

This comment has been minimized.

Copy link
@Shnoulle

Shnoulle Aug 5, 2013

Author Collaborator

Yes, i understand :). Great work.

But why don't leave some export by default , in core, not in Plugin ? Think CSV only for example.

);
$event = new PluginEvent('listExportPlugins');
$oPluginManager = App()->getPluginManager();
Expand Down Expand Up @@ -114,6 +115,9 @@ function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOpti
case "html":
$writer = new HtmlWriter();
break;
case "json":
$writer = new JsonWriter();
break;
case "csv":
default:
$writer = new CsvWriter();
Expand Down Expand Up @@ -146,4 +150,4 @@ function exportSurvey($iSurveyId, $sLanguageCode, $sExportPlugin, FormattingOpti
return $result;
}
}
}
}
10 changes: 5 additions & 5 deletions application/helpers/remotecontrol/remotecontrol_handle.php
Expand Up @@ -2192,7 +2192,7 @@ public function add_response($sSessionKey, $iSurveyID, $aResponseData)
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID Id of the Survey
* @param string $sDocumentType pdf,csv,xls,doc
* @param string $sDocumentType pdf,csv,xls,doc,json
* @param string $sLanguageCode The language to be used
* @param string $sCompletionStatus Optional 'complete','incomplete' or 'all' - defaults to 'all'
* @param string $sHeadingType 'code','full' or 'abbreviated' Optional defaults to 'code'
Expand All @@ -2202,7 +2202,7 @@ public function add_response($sSessionKey, $iSurveyID, $aResponseData)
* @param array $aFields Optional Selected fields
* @return array|string On success: Requested file as base 64-encoded string. On failure array with error information
* */
public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLanguageCode=null, $sCompletionStatus='all', $sHeadingType='full', $sResponseType='short', $iFromResponseID=null, $iToResponseID=null, $aFields=null)
public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLanguageCode=null, $sCompletionStatus='all', $sHeadingType='code', $sResponseType='short', $iFromResponseID=null, $iToResponseID=null, $aFields=null)
{
if (!$this->_checkSessionKey($sSessionKey)) return array('status' => 'Invalid session key');
Yii::app()->loadHelper('admin/exportresults');
Expand Down Expand Up @@ -2246,7 +2246,7 @@ public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLan
* @access public
* @param string $sSessionKey Auth credentials
* @param int $iSurveyID Id of the Survey
* @param string $sDocumentType pdf,csv,xls,doc
* @param string $sDocumentType pdf,csv,xls,doc,json
* @param string $sToken The token for which responses needed
* @param string $sLanguageCode The language to be used
* @param string $sCompletionStatus Optional 'complete','incomplete' or 'all' - defaults to 'all'
Expand All @@ -2256,7 +2256,7 @@ public function export_responses($sSessionKey, $iSurveyID, $sDocumentType, $sLan
* @return array|string On success: Requested file as base 64-encoded string. On failure array with error information
*
*/
public function export_responses_by_token($sSessionKey, $iSurveyID, $sDocumentType, $sToken, $sLanguageCode=null, $sCompletionStatus='all', $sHeadingType='full', $sResponseType='short', $aFields=null)
public function export_responses_by_token($sSessionKey, $iSurveyID, $sDocumentType, $sToken, $sLanguageCode=null, $sCompletionStatus='all', $sHeadingType='code', $sResponseType='short', $aFields=null)
{
if (!$this->_checkSessionKey($sSessionKey)) return array('status' => 'Invalid session key');
if (!Permission::model()->hasSurveyPermission($iSurveyID, 'responses', 'export')) return array('status' => 'No permission');
Expand Down Expand Up @@ -2340,4 +2340,4 @@ protected function _checkSessionKey($sSessionKey)
return true;
}
}
}
}

0 comments on commit a500513

Please sign in to comment.