From dc5238decb687df0c9a59241c4f85dff31732f19 Mon Sep 17 00:00:00 2001 From: louis Date: Fri, 18 Sep 2015 16:47:51 +0200 Subject: [PATCH] Dev: search, group filter and pagination for questions list. --- application/controllers/admin/surveyadmin.php | 2 - application/core/Survey_Common_Action.php | 68 +++---- application/models/Question.php | 68 ++++++- .../views/admin/super/listquestiongroups.php | 2 +- .../views/admin/super/listquestions.php | 192 ++++++++++-------- 5 files changed, 204 insertions(+), 128 deletions(-) diff --git a/application/controllers/admin/surveyadmin.php b/application/controllers/admin/surveyadmin.php index b064359e60c..f5c0285d710 100644 --- a/application/controllers/admin/surveyadmin.php +++ b/application/controllers/admin/surveyadmin.php @@ -486,8 +486,6 @@ public function listquestions($surveyid) $survey = Survey::model()->findByPk($iSurveyID); - - $aData['surveyid'] = $iSurveyID; $aData['display']['menu_bars']['listquestions'] = true; $aData['sidebar']['listquestions'] = true; diff --git a/application/core/Survey_Common_Action.php b/application/core/Survey_Common_Action.php index 5a1f4b0e9ce..bc4d3ce764b 100644 --- a/application/core/Survey_Common_Action.php +++ b/application/core/Survey_Common_Action.php @@ -908,50 +908,32 @@ function _listquestions($aData) $iSurveyID = $aData['surveyid']; $baselang = Survey::model()->findByPk($iSurveyID)->language; - $sort = new CSort(); - $sort->attributes = array( - 'Question id'=>array( - 'asc'=>'qid', - 'desc'=>'qid desc', - ), - 'Question order'=>array( - 'asc'=>'question_order', - 'desc'=>'question_order desc', - ), - 'Title'=>array( - 'asc'=>'title', - 'desc'=>'title desc', - ), - 'Question'=>array( - 'asc'=>'question', - 'desc'=>'question desc', - ), - - 'Group'=>array( - 'asc'=>'groups.group_name', - 'desc'=>'groups.group_name desc', - ), - ); - - + // The DataProvider will be build from the Question model, search method + $model = new Question('search'); + + // Global filter + if (isset($_GET['Question'])) + { + $model->attributes = $_GET['Question']; + } - $dataProvider=new CActiveDataProvider('Question', array( - 'criteria'=>array( - 'condition'=>'t.sid=:surveyid AND t.language=:language', - 'params'=>array(':surveyid'=>$iSurveyID,':language'=>$baselang), - 'join' => 'LEFT JOIN {{groups}} AS groups ON ( groups.gid = t.gid AND t.language = groups.language )', - ), - - 'sort'=>$sort, - - 'pagination'=>array( - 'pageSize'=>15, - ), - )); - - - - $aData['questionsDatas'] = $dataProvider; + // Filter group + if (isset($_GET['group_name'])) + { + $model->group_name = $_GET['group_name']; + } + + // Set number of page + if (isset($_GET['pageSize'])) + { + Yii::app()->user->setState('pageSize',(int)$_GET['pageSize']); + } + + // We filter the current survey id + $model['sid'] = $iSurveyID; + $model['language'] = $baselang; + $aData['model']=$model; + $this->getController()->renderPartial("/admin/super/listquestions", $aData); } } diff --git a/application/models/Question.php b/application/models/Question.php index 3511b9f6353..13c492ebd66 100644 --- a/application/models/Question.php +++ b/application/models/Question.php @@ -18,6 +18,9 @@ class Question extends LSActiveRecord { + + // Stock the active group_name for questions list filtering + public $group_name; /** * Returns the static model of Settings table @@ -702,6 +705,15 @@ public static function getQuestionClass($sType) }; } + /** + * Return all group of the active survey + * Used to render group filter in questions list + */ + public function getAllGroups() + { + return QuestionGroup::model()->findAll("sid=:sid",array(':sid'=>$this->sid)); + } + public function getbuttons() { @@ -716,6 +728,58 @@ public function getbuttons() $button .= ''; return $button; } - } -?> + + public function search() + { + $pageSize=Yii::app()->user->getState('pageSize',Yii::app()->params['defaultPageSize']); + + $sort = new CSort(); + $sort->attributes = array( + 'Question id'=>array( + 'asc'=>'qid', + 'desc'=>'qid desc', + ), + 'Question order'=>array( + 'asc'=>'question_order', + 'desc'=>'question_order desc', + ), + 'Title'=>array( + 'asc'=>'title', + 'desc'=>'title desc', + ), + 'Question'=>array( + 'asc'=>'question', + 'desc'=>'question desc', + ), + + 'Group'=>array( + 'asc'=>'groups.group_name', + 'desc'=>'groups.group_name desc', + ), + ); + + $criteria = new CDbCriteria; + $criteria->condition='t.sid=:surveyid AND t.language=:language'; + $criteria->params=(array(':surveyid'=>$this->sid,':language'=>$this->language)); + $criteria->join='LEFT JOIN {{groups}} AS groups ON ( groups.gid = t.gid AND t.language = groups.language )'; + + if($this->group_name != '') + { + $criteria->addCondition('groups.group_name = :group_name'); + $criteria->params=(array(':surveyid'=>$this->sid,':language'=>$this->language, ':group_name'=>$this->group_name)); + } + + $criteria->compare('title', $this->title, true, 'AND'); + $criteria->compare('question', $this->title, true, 'OR'); + + $dataProvider=new CActiveDataProvider('Question', array( + 'criteria'=>$criteria, + 'sort'=>$sort, + 'pagination'=>array( + 'pageSize'=>$pageSize, + ), + )); + return $dataProvider; + } + } \ No newline at end of file diff --git a/application/views/admin/super/listquestiongroups.php b/application/views/admin/super/listquestiongroups.php index 0e8c928394f..5b1323cbfa9 100644 --- a/application/views/admin/super/listquestiongroups.php +++ b/application/views/admin/super/listquestiongroups.php @@ -32,7 +32,7 @@
'btn btn-success')); ?> - +
endWidget(); ?> diff --git a/application/views/admin/super/listquestions.php b/application/views/admin/super/listquestions.php index 61b7b11969c..9de1748c9bb 100644 --- a/application/views/admin/super/listquestions.php +++ b/application/views/admin/super/listquestions.php @@ -4,93 +4,125 @@ */ ?> -
-

- -
-
- widget('bootstrap.widgets.TbGridView', array( - 'dataProvider' => $questionsDatas, - 'columns' => array( - array( - 'name' => 'Question id', - 'value'=>'$data->qid', - 'htmlOptions' => array('class' => 'col-md-1'), - ), - array( - 'name' => 'Question order', - 'value'=>'$data->question_order', - 'htmlOptions' => array('class' => 'col-md-2'), - ), - array( - 'name' => 'Title', - 'value'=>'$data->title', - 'htmlOptions' => array('class' => 'col-md-1'), - ), - array( - 'name' => 'Question', - 'value'=>'$data->question', - ), - array( - 'name' => 'Group', - //'value'=>'$data->groupName', - 'value'=>'$data->groups->group_name', - 'htmlOptions' => array('class' => 'col-md-2'), - ), +user->getState('pageSize',Yii::app()->params['defaultPageSize']);?> - array( - 'name'=>'', - 'type'=>'raw', - 'value'=>'$data->buttons', - 'htmlOptions' => array('class' => 'col-md-2 text-right'), - ), - - ), - 'ajaxUpdate' => false, - /* - 'columns' => array( +
+

- array( - 'name'=>'Group id', - 'value'=>'$data->gid', - 'htmlOptions' => array('class' => 'col-md-1'), - ), +
+
+ +
+
+
+ + beginWidget('CActiveForm', array( + 'action' => Yii::app()->createUrl('admin/survey/sa/listquestions/surveyid/'.$surveyid), + 'method' => 'get', + 'htmlOptions'=>array( + 'class'=>'form-horizontal', + ), + )); ?> + + +
+ label($model, 'filter: ', array('class'=>'col-sm-2 control-label text-right col-sm-offset-6')); ?> +
+ textField($model, 'title', array('class'=>'form-control')); ?> +
+
- array( - 'name'=>'Group Order', - 'value'=>'$data->group_order', - 'htmlOptions' => array('class' => 'col-md-1'), - ), - - array( - 'name'=>'Group Name', - 'value'=>'$data->group_name', - 'htmlOptions' => array('class' => 'col-md-2'), - ), - - array( - 'name'=>'Description', - 'type'=>'raw', - 'value'=>'$data->description', - 'htmlOptions' => array('class' => 'col-md-2'), - ), - - ), - - 'htmlOptions'=>array('style'=>'cursor: pointer;', 'class'=>'hoverAction'), - 'selectionChanged'=>"function(id){window.location='" . Yii::app()->urlManager->createUrl('admin/survey/sa/view/surveyid/'.$surveyid.'/gid/' ) . '/' . "' + $.fn.yiiGridView.getSelection(id.split(',', 1));}", - 'ajaxUpdate' => true, - */ - )); - ?> -
-
-
+ +
+ label($model, 'Group:', array('class'=>'col-sm-2 control-label text-right col-sm-offset-6')); ?> +
+ +
+
+ 'btn btn-success')); ?> + +
+
+ + endWidget(); ?> +
+
+
+ + + widget('bootstrap.widgets.TbGridView', array( + 'dataProvider' => $model->search(), + 'id' => 'question-grid', + + // Number of row per page selection + 'summaryText'=>gT('Displaying {start}-{end} of {count} result(s).') . + CHtml::dropDownList( + 'pageSize', + $pageSize, + Yii::app()->params['pageSizeOptions'], + array('class'=>'changePageSize form-control', 'style'=>'display: inline; width: auto')) . + gT(' rows per page'), + + 'columns' => array( + array( + 'name' => 'Question id', + 'value'=>'$data->qid', + 'htmlOptions' => array('class' => 'col-md-1'), + ), + array( + 'name' => 'Question order', + 'value'=>'$data->question_order', + 'htmlOptions' => array('class' => 'col-md-2'), + ), + array( + 'name' => 'Title', + 'value'=>'$data->title', + 'htmlOptions' => array('class' => 'col-md-1'), + ), + array( + 'name' => 'Question', + 'value'=>'$data->question', + ), + array( + 'name' => 'Group', + //'value'=>'$data->groupName', + 'value'=>'$data->groups->group_name', + 'htmlOptions' => array('class' => 'col-md-2'), + ), + array( + 'name'=>'', + 'type'=>'raw', + 'value'=>'$data->buttons', + 'htmlOptions' => array('class' => 'col-md-2 text-right'), + ), + + ), + 'ajaxUpdate' => false, + )); + ?> +
+
+
+ +