From ace73491aaec95c3fb7f77969dcc28c7b60c6902 Mon Sep 17 00:00:00 2001 From: lacrioque Date: Wed, 23 Oct 2019 13:55:02 +0200 Subject: [PATCH] Fixed issue #15450: The GridView in "Saved but not submitted[...]" is incomplete and lacks pagination and filtering --- application/controllers/admin/saved.php | 32 ++++-- application/models/SavedControl.php | 102 +++++++++++++++--- .../views/admin/saved/savedlist_view.php | 47 +++----- 3 files changed, 124 insertions(+), 57 deletions(-) diff --git a/application/controllers/admin/saved.php b/application/controllers/admin/saved.php index 948ad6decdf..0aa61c8beac 100644 --- a/application/controllers/admin/saved.php +++ b/application/controllers/admin/saved.php @@ -40,23 +40,33 @@ public function view($iSurveyId) } $aThisSurvey = getSurveyInfo($iSurveyId); + $oSavedControlModel = SavedControl::model(); + $oSavedControlModel->sid = $iSurveyId; + $aData['model'] = $oSavedControlModel; $aData['sSurveyName'] = $aThisSurvey['name']; $aData['iSurveyId'] = $iSurveyId; - $aData['dataProvider'] = new CActiveDataProvider('SavedControl', array( - 'criteria'=>array( - 'condition'=>'sid=:sid', - 'params'=>[':sid'=>$iSurveyId], - ), - 'countCriteria'=>array( - 'condition'=>'sid=:sid', - 'params'=>[':sid'=>$iSurveyId], - ), - )); - $aData['SavedControlModel'] = SavedControl::model(); + // Set page size + if (Yii::app()->request->getPost('savedResponsesPageSize')) { + Yii::app()->user->setState('savedResponsesPageSize', Yii::app()->request->getPost('savedResponsesPageSize')); + } + $aData['savedResponsesPageSize'] = Yii::app()->user->getState('savedResponsesPageSize', Yii::app()->params['defaultPageSize']); $aViewUrls[] = 'savedlist_view'; $this->_renderWrappedTemplate('saved', $aViewUrls, $aData); } + /** + * Undocumented function + * + * @todo write function + * @param [type] $surveyid + * @param [type] $id + * @return void + */ + public function resend_accesscode($surveyid, $id) { + + } + + /** * Function responsible to delete saved responses. * @param int $surveyid diff --git a/application/models/SavedControl.php b/application/models/SavedControl.php index 93cc96f7f14..5d40cb76e19 100644 --- a/application/models/SavedControl.php +++ b/application/models/SavedControl.php @@ -52,7 +52,6 @@ public static function model($class = __CLASS__) return parent::model($class); } - public function getAllRecords($condition = false) { if ($condition != false) { @@ -89,7 +88,7 @@ public function deleteSomeRecords($condition) $criteria = new CDbCriteria; if ($condition != false) { - foreach ($condition as $column=>$value) { + foreach ($condition as $column => $value) { $criteria->addCondition("$column='$value'"); } } @@ -102,33 +101,104 @@ public function insertRecords($data) return $this->db->insert('saved_control', $data); } - public function getGridButtons($surveyid) + public function getGridButtons() { $gridButtons = array(); $gridButtons['editresponse'] = array( - 'label'=>''.gT("Edit").'', - 'imageUrl'=>false, + 'label' => '' . gT("Edit") . '', + 'imageUrl' => false, 'url' => 'App()->createUrl("admin/dataentry/sa/editdata/subaction/edit",array("surveyid"=>$data->sid,"id"=>$data->srid));', 'options' => array( - 'class'=>"btn btn-default btn-xs btn-edit", - 'data-toggle'=>"tooltip", - 'title'=>gT("Edit response") + 'class' => "btn btn-default btn-xs btn-edit", + 'data-toggle' => "tooltip", + 'title' => gT("Edit response"), + ), + 'visible' => 'boolval(' . Permission::model()->hasSurveyPermission($this->sid, 'responses', 'update') . ')', + ); + $gridButtons['resend_accesscode'] = array( + 'label' => '' . gT("Edit") . '', + 'imageUrl' => false, + 'url' => 'App()->createUrl("admin/saved/sa/resend_accesscode",array("surveyid"=>$data->sid,"id"=>$data->srid));', + 'options' => array( + 'class' => "btn btn-default btn-xs btn-edit", + 'data-toggle' => "tooltip", + 'title' => gT("Resend access code"), ), - 'visible'=> 'boolval('.Permission::model()->hasSurveyPermission($surveyid, 'responses', 'update').')', + // 'visible'=> 'boolval('.Permission::model()->hasSurveyPermission($surveyid, 'responses', 'update').')', + 'visible' => false, ); $gridButtons['delete'] = array( - 'label'=>''.gT("Delete").'', - 'imageUrl'=>false, - 'icon'=>false, + 'label' => '' . gT("Delete") . '', + 'imageUrl' => false, + 'icon' => false, 'url' => 'App()->createUrl("admin/saved/sa/actionDelete",array("surveyid"=>$data->sid,"scid"=>$data->scid,"srid"=>$data->srid));', 'options' => array( - 'class'=>"btn btn-default btn-xs btn-delete", - 'data-toggle'=>"tooltip", - 'title'=>gT("Delete this entry and related response") + 'class' => "btn btn-default btn-xs btn-delete", + 'data-toggle' => "tooltip", + 'title' => gT("Delete this entry and related response"), ), - 'visible'=> 'boolval('.Permission::model()->hasSurveyPermission($surveyid, 'responses', 'delete').')', + 'visible' => 'boolval(' . Permission::model()->hasSurveyPermission($this->sid, 'responses', 'delete') . ')', 'click' => 'function(event){ window.LS.gridButton.confirmGridAction(event,$(this)); }', ); return $gridButtons; } + + public function getColumns() + { + return array( + array( + 'header' => gT("ID"), + 'name' => 'scid', + 'filter' => false, + ), + array( + 'class' => 'bootstrap.widgets.TbButtonColumn', + 'template' => '{editresponse}{delete}', + //~ 'htmlOptions' => array('class' => 'text-left response-buttons'), + 'buttons' => $this->gridButtons, + ), + array( + 'header' => gT("Identifier"), + 'name' => 'identifier', + ), + array( + 'header' => gT("IP address"), + 'name' => 'ip', + ), + array( + 'header' => gT("Date saved"), + 'name' => 'saved_date', + ), + array( + 'header' => gT("Email address"), + 'name' => 'email', + ), + ); + } + + public function search() + { + // @todo Please modify the following code to remove attributes that should not be searched. + $criteria = new CDbCriteria; + $criteria->compare('sid', $this->sid, true); //will not be searchable + $criteria->compare('srid', $this->srid, true); + $criteria->compare('access_code', $this->access_code, true); + + $criteria->compare('scid', $this->scid); + $criteria->compare('identifier', $this->identifier, true); + $criteria->compare('email', $this->email); + $criteria->compare('ip', $this->ip, true); + $criteria->compare('saved_thisstep', $this->saved_thisstep, true); + $criteria->compare('status', $this->status, true); + $criteria->compare('saved_date', $this->saved_date, true); + $criteria->compare('refurl', $this->refurl, true); + $pageSize = Yii::app()->user->getState('savedResponsesPageSize', Yii::app()->params['defaultPageSize']); + + return new CActiveDataProvider($this, array( + 'criteria' => $criteria, + 'pagination' => array( + 'pageSize' => $pageSize, + ), + )); + } } diff --git a/application/views/admin/saved/savedlist_view.php b/application/views/admin/saved/savedlist_view.php index 94e2c3b8d8f..47e15b9159c 100644 --- a/application/views/admin/saved/savedlist_view.php +++ b/application/views/admin/saved/savedlist_view.php @@ -7,39 +7,26 @@
widget('ext.LimeGridView.LimeGridView', array( + $this->widget('bootstrap.widgets.TbGridView', array( 'id' => 'saved-grid', - 'ajaxUpdate' => 'saved-grid', - 'dataProvider' => $dataProvider, + 'ajaxUpdate' => 'saved-grid', + 'dataProvider' => $model->search(), + 'columns' => $model->columns, + 'filter' => $model, 'ajaxType' => 'POST', 'template' => "{items}\n
{pager}
{summary}
", - 'columns' => array( - array( - 'header' => gT("ID"), - 'name' => 'scid', - ), - array( - 'class'=>'bootstrap.widgets.TbButtonColumn', - 'template'=>'{editresponse}{delete}', - //~ 'htmlOptions' => array('class' => 'text-left response-buttons'), - 'buttons'=> $SavedControlModel->getGridButtons($iSurveyId), - ), - array( - 'header' => gT("Identifier"), - 'name' => 'identifier', - ), - array( - 'header' => gT("IP address"), - 'name' => 'ip', - ), - array( - 'header' => gT("Date saved"), - 'name' => 'saved_date', - ), - array( - 'header' => gT("Email address"), - 'name' => 'email', - ), + 'emptyText'=>gT('No customizable entries found.'), + 'summaryText'=>gT('Displaying {start}-{end} of {count} result(s).').' '. sprintf(gT('%s rows per page'), + CHtml::dropDownList( + 'savedResponsesPageSize', + $savedResponsesPageSize, + Yii::app()->params['pageSizeOptions'], + array( + 'class'=>'changePageSize form-control', + 'style'=>'display: inline; width: auto', + 'onchange' => "$.fn.yiiGridView.update('saved-grid',{ data:{ savedResponsesPageSize: $(this).val() }});" + ) + ) ), ) );