Skip to content

Commit

Permalink
Dev: Fixed issue : Browse response is not filtered by exiting stat fi…
Browse files Browse the repository at this point in the history
…lter
  • Loading branch information
Shnoulle committed Jul 27, 2015
1 parent 434ce30 commit 75e4de4
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 21 deletions.
58 changes: 48 additions & 10 deletions application/controllers/admin/responses.php
Expand Up @@ -310,10 +310,7 @@ public function index($iSurveyID)
* it containts
* $fnames[] = array(<dbfieldname>, <some strange title>, <questiontext>, <group_id>, <questiontype>);
*/
if (Yii::app()->request->getPost('sql'))
{
$aViewUrls[] = 'browseallfiltered_view';
}


$aData['num_total_answers'] = SurveyDynamic::model($iSurveyID)->count();
$aData['num_completed_answers'] = SurveyDynamic::model($iSurveyID)->count('submitdate IS NOT NULL');
Expand Down Expand Up @@ -416,6 +413,19 @@ function browse($iSurveyId)
'align'=>'center',
'label' => gt("Completed"),
);
$defaultSearch=array();
if (incompleteAnsFilterState() == "incomplete")
{
$defaultSearch['completed']="N";
}
elseif (incompleteAnsFilterState() == "complete")
{
$defaultSearch['completed']="Y";
}
else
{
$defaultSearch['completed']="";
}

//add token to top of list if survey is not private
if ($aData['surveyinfo']['anonymized'] == "N" && tableExists('tokens_' . $iSurveyId)) //add token to top of list if survey is not private
Expand Down Expand Up @@ -578,8 +588,23 @@ function browse($iSurveyId)
$aData['column_names_txt']= ls_json_encode($column_names);;
$aData['hasUpload']=hasFileUploadQuestion($iSurveyId);


$this->_renderWrappedTemplate('responses', 'listResponses_view', $aData);
$aData['jsonBaseUrl']=App()->createUrl('/admin/responses', array('surveyid'=>$iSurveyId, 'browselang'=>$sBrowseLanguage));
$aData['jsonUrl']=App()->createUrl('/admin/responses', array(
'sa'=> 'getResponses_json',
'surveyid' => $iSurveyId,
'browselang'=>$sBrowseLanguage,
'statfilter'=>App()->request->getQuery('statfilter',0)
));
$aData['jsonActionUrl']=App()->createUrl('/admin/responses', array('sa'=> 'actionResponses', 'surveyid' => $iSurveyId,'browselang'=>$sBrowseLanguage));

$aData['defaultSearch']=json_encode($defaultSearch);
$aViewUrls=array();
if (App()->request->getQuery('statfilter'))
{
$aViewUrls[] = 'filterListResponses_view';
}
$aViewUrls[] = 'listResponses_view';
$this->_renderWrappedTemplate('responses', $aViewUrls, $aData);

}

Expand Down Expand Up @@ -628,10 +653,6 @@ public function getResponses_json($iSurveyID)
$aSpecificColumns=array_merge($aSpecificColumns,TokenDynamic::model($iSurveyID)->getTableSchema()->getColumnNames());
}

//Get the filter data
//if (Yii::app()->request->getPost('sql') && stripcslashes(Yii::app()->request->getPost('sql')) !== "" && Yii::app()->request->getPost('sql') != "NULL")
// $oCriteria->addCondition(stripcslashes(Yii::app()->request->getPost('sql')));

$aKnowColumns=array_keys(SurveyDynamic::model($iSurveyID)->attributes);
if($bHaveToken){
$aKnowColumns[]='firstname';
Expand All @@ -657,9 +678,26 @@ public function getResponses_json($iSurveyID)
if(($value=Yii::app()->request->getParam('completed')))
{
if($value=='Y')
{
$oCriteria->addCondition("submitdate IS NOT NULL");
Yii::app()->session['incompleteanswers']='complete';
}
elseif($value=='N')
{
$oCriteria->addCondition("submitdate IS NULL");
Yii::app()->session['incompleteanswers']='incomplete';
}
else
Yii::app()->session['incompleteanswers']='all';
}
//Get the filter data
if (App()->request->getQuery('statfilter'))
{
$aSessionStatFilters= Yii::app()->session['statistics_selects_'.$iSurveyID];
foreach($aSessionStatFilters as $sCondition)
{
$oCriteria->addCondition($sCondition);
}
}
foreach($aKnowColumns as $sFiltering)
{
Expand Down
@@ -0,0 +1,6 @@
<p>
<?php eT("Showing Filtered Results"); ?>
</p>
<p>
<?php echo CHtml::link(gT("View without the filter."),array("admin/responses","sa"=>'browse','surveyid'=>$surveyid),array('class'=>'button btn-link')); ?>
</p>
17 changes: 6 additions & 11 deletions application/views/admin/responses/listResponses_view.php
Expand Up @@ -3,8 +3,6 @@
var strDeleteAllConfirm='<?php eT('Do you really want to delete all marked responses?', 'js'); ?>';
var noFilesSelectedForDeletion = '<?php eT('Please select at least one file for deletion', 'js'); ?>';
</script>

<br />
<script type='text/javascript'>
var sCaption ='<?php eT("Survey responses",'js');?>';
var sSelectColumns ='<?php eT("Select columns",'js');?>';
Expand Down Expand Up @@ -38,9 +36,12 @@
var sRefreshTitle ='<?php eT("Reload responses list",'js');?>';
var delBtnCaption ='<?php eT("Delete",'js');?>';
var sEmptyRecords ='<?php eT("There are currently no responses.",'js');?>';
var jsonBaseUrl = "<?php echo App()->createUrl('/admin/responses', array('surveyid'=>$surveyid, 'browselang'=>$language)); ?>";
var jsonUrl = "<?php echo App()->createUrl('/admin/responses', array('sa'=> 'getResponses_json', 'surveyid' => $surveyid,'browselang'=>$language)); ?>";
var jsonActionUrl = "<?php echo App()->createUrl('/admin/responses', array('sa'=> 'actionResponses', 'surveyid' => $surveyid,'browselang'=>$language)); ?>";

var jsonBaseUrl = "<?php echo $jsonBaseUrl; ?>";
var jsonUrl = "<?php echo $jsonUrl; ?>";
var jsonActionUrl = "<?php echo $jsonActionUrl; ?>";

var defaultSearch = <?php echo $defaultSearch; ?>;

var colNames = <?php echo $column_names_txt; ?>;
var colModels = <?php echo $column_model_txt; ?>;
Expand All @@ -55,10 +56,4 @@
var sConfirmationArchiveMessage='<?php eT("This function creates a ZIP archive of several survey archives and can take some time - please be patient! Do you want to continue?",'js');?>';
<?php } ?>
</script>
<br/>

<table id="displayresponses"></table> <div id="pager"></div>


<br />

8 changes: 8 additions & 0 deletions scripts/admin/listresponse.js
Expand Up @@ -19,6 +19,8 @@ $(window).scroll(function(){
});
});

// Trace firstload of grid
firstload=true;
$(document).on("click","[data-delete]",function(event){
event.preventDefault();
var responseid=$(this).data("delete")
Expand Down Expand Up @@ -73,6 +75,7 @@ $(function() {
loadonce : false, // use ajax request
pager : "#pager",
caption : sCaption,
postData: defaultSearch ,
beforeRequest: function(){
/* activate tooltip on header */
for (i = 0; i < colModels.length; i++) {
Expand Down Expand Up @@ -140,6 +143,11 @@ $(function() {
searchOnEnter : false,
defaultSearch : 'cn'
});
if(firstload)
{
$("#gs_completed").val(defaultSearch.completed);
firstload=false;
}
/* Column button */
jQuery("#displayresponses").jqGrid(
'navButtonAdd',
Expand Down

0 comments on commit 75e4de4

Please sign in to comment.