From b2070d09d46caef44c708b0e86191a2e2f4cb42e Mon Sep 17 00:00:00 2001 From: markusfluer Date: Mon, 27 Nov 2017 19:20:41 +0100 Subject: [PATCH] Dev: created yii grid view for asessements --- application/config/third_party.php | 1 + application/controllers/admin/assessments.php | 9 +- application/models/Assessment.php | 109 ++++++++++++++++++ application/models/Surveymenu.php | 1 + application/views/admin/assessments_view.php | 75 +++++++++--- assets/scripts/admin/assessments.js | 16 +++ 6 files changed, 188 insertions(+), 23 deletions(-) diff --git a/application/config/third_party.php b/application/config/third_party.php index 5e40ba8ea80..de505163d87 100755 --- a/application/config/third_party.php +++ b/application/config/third_party.php @@ -356,6 +356,7 @@ ), 'jquery-datatable' => array( 'basePath' => 'third_party.jquery-datatable', + 'position' => CClientScript::POS_BEGIN, 'css' => array( 'datatables.min.css' ), diff --git a/application/controllers/admin/assessments.php b/application/controllers/admin/assessments.php index d21362561a6..e4935adbeab 100644 --- a/application/controllers/admin/assessments.php +++ b/application/controllers/admin/assessments.php @@ -96,9 +96,11 @@ protected function _renderWrappedTemplate($sAction = 'assessments', $aViewUrls = private function _showAssessments($iSurveyID, $action) { $oSurvey = Survey::model()->findByPk($iSurveyID); - $oCriteria = new CDbCriteria(array('order' => 'id ASC')); - $oAssessments = Assessment::model()->findAllByAttributes(array('sid' => $iSurveyID), $oCriteria); + $oAssessments = Assessment::model(); + $oAssessments->sid = $iSurveyID; $aData = $this->_collectGroupData($iSurveyID); + $aData['model'] = $oAssessments; + $aData['pageSizeAsessements'] = Yii::app()->user->getState('pageSizeAsessements', Yii::app()->params['defaultPageSize']); $aHeadings = array(gT("Scope"), gT("Question group"), gT("Minimum"), gT("Maximum")); $aData['actiontitle'] = gT("Add"); $aData['actionvalue'] = "assessmentadd"; @@ -119,8 +121,6 @@ private function _showAssessments($iSurveyID, $action) Yii::app()->loadHelper('admin/htmleditor'); - // FIXME this must be in VIEWS! - $aData['asessementNotActivated'] = false; if ($oSurvey->assessments != 'Y') { $aData['asessementNotActivated'] = array( @@ -133,6 +133,7 @@ private function _showAssessments($iSurveyID, $action) 'class'=> 'warningheader col-sm-12 col-md-6 col-md-offset-3'); } $urls['assessments_view'][] = $aData; + $this->_renderWrappedTemplate('', $urls, $aData); } diff --git a/application/models/Assessment.php b/application/models/Assessment.php index d02f6e79ff9..60c32e1028b 100644 --- a/application/models/Assessment.php +++ b/application/models/Assessment.php @@ -61,6 +61,115 @@ public function primaryKey() return array('id', 'language'); } + /** + * @return array customized attribute labels (name=>label) + */ + public function attributeLabels() + { + return array( + 'id' => 'ID', + 'scope' => gT("Scope"), + 'name' => gT("Name"), + 'minimum' => gT("Minimum"), + 'maximum' => gT("Maximum"), + 'message' => gT("Message"), + 'language' => gT("Language"), + ); + } + + public function getButtons() + { + $buttons = "
"; + $raw_button_template = "" + . ""; + + if (Permission::model()->hasGlobalPermission('assessements', 'update')) { + $editData = array( + 'action_assessements_editModal', + 'text-danger', + gT("Edit this assessement rule"), + 'edit' + ); + $deleteData = array( + 'action_assessements_deleteModal', + 'text-danger', + gT("Delete this assessement rule"), + 'trash text-danger' + ); + + $buttons .= vsprintf($raw_button_template, $deleteData); + $buttons .= vsprintf($raw_button_template, $editData); + } + + $buttons .= '
'; + + return $buttons; + } + + public function getColumns(){ + return array( + array( + 'name' => 'id', + 'filter' => false + ), + array( + "name" => 'buttons', + "type" => 'raw', + "header" => gT("Action"), + "filter" => false + ), + array( + 'name' => 'scope', + 'value' => '$data->scope == "G" ? eT("Global") : eT("Total")', + 'htmlOptions' => ['class' => 'col-sm-1'], + 'filter' => TbHtml::dropDownList('Assessement["scope"]', 'scope', [ '' => gT('All'), 'T' => gT('Total'), 'G' => gT("Global")]) + ), + array( + 'name' => 'name', + 'htmlOptions' => ['class' => 'col-sm-2'] + ), + array( + 'name' => 'minimum', + 'htmlOptions' => ['class' => 'col-sm-1'] + ), + array( + 'name' => 'maximum', + 'htmlOptions' => ['class' => 'col-sm-1'] + ), + array( + 'name' => 'message', + 'htmlOptions' => ['class' => 'col-sm-5'] + ), + array( + 'name' => 'language', + 'value' => 'getLanguageNameFromCode($data->language, false)', + 'htmlOptions' => ['class' => 'col-sm-1'] + ), + ); + } + + public function search(){ +// @todo Please modify the following code to remove attributes that should not be searched. + + $criteria = new CDbCriteria; + + $criteria->compare('id', $this->id); + $criteria->compare('sid', $this->sid); + $criteria->compare('gid', $this->gid); + $criteria->compare('scope', $this->scope); + $criteria->compare('name', $this->name, true); + $criteria->compare('minimum', $this->minimum); + $criteria->compare('maximum', $this->maximum); + $criteria->compare('message', $this->message, true); + $criteria->compare('language', $this->language); + + return new CActiveDataProvider($this, array( + 'criteria'=>$criteria, + )); + } + /** * @param array $data * @return Assessment diff --git a/application/models/Surveymenu.php b/application/models/Surveymenu.php index 80fd46138e3..79d62d517e6 100644 --- a/application/models/Surveymenu.php +++ b/application/models/Surveymenu.php @@ -195,6 +195,7 @@ public function attributeLabels() 'created_by' => gT('Created by'), ); } + public function getButtons() { $buttons = "
"; diff --git a/application/views/admin/assessments_view.php b/application/views/admin/assessments_view.php index 4c9fe1e4773..b858706bc6e 100644 --- a/application/views/admin/assessments_view.php +++ b/application/views/admin/assessments_view.php @@ -24,10 +24,43 @@

-
+
+ widget('bootstrap.widgets.TbGridView', array( + 'dataProvider' => $model->search(), + // Number of row per page selection + 'id' => 'assessements-grid', + 'columns' => $model->getColumns(), + 'filter' => $model, + 'emptyText'=>gT('No customizable entries found.'), + 'summaryText'=>gT('Displaying {start}-{end} of {count} result(s).').' '. sprintf(gT('%s rows per page'), + CHtml::dropDownList( + 'pageSizeAsessements', + $pageSizeAsessements, + Yii::app()->params['pageSizeOptions'], + array('class'=>'changePageSize form-control', 'style'=>'display: inline; width: auto') + ) + ), + 'rowHtmlOptionsExpression' => '["data-assessement-id" => $data->id]', + 'htmlOptions' => array('class'=> 'table-responsive'), + 'itemsCssClass' => 'table table-responsive table-striped', + 'htmlOptions'=>array('style'=>'cursor: pointer;', 'class'=>'hoverAction grid-view'), + 'ajaxType' => 'POST', + 'ajaxUpdate' => 'assessements-grid', + 'template' => "{items}\n
{pager}
{summary}
", + 'afterAjaxUpdate'=>'bindAction', + )); + ?> +
+
+
+
+ +
+
+ - +
@@ -142,22 +175,22 @@ class="btn btn-default btn-xs"
- +*/ ?> hasSurveyPermission($surveyid, 'assessments','update') && $actionvalue=="assessmentupdate") || (Permission::model()->hasSurveyPermission($surveyid, 'assessments','create')&& $actionvalue=="assessmentadd")): ?>