diff --git a/application/extensions/admin/survey/ListSurveysWidget/views/listSurveys.php b/application/extensions/admin/survey/ListSurveysWidget/views/listSurveys.php index e1463106c..5c8d41a7a 100644 --- a/application/extensions/admin/survey/ListSurveysWidget/views/listSurveys.php +++ b/application/extensions/admin/survey/ListSurveysWidget/views/listSurveys.php @@ -127,6 +127,14 @@ ), array( + 'header' => gT('Response Rate'), + 'name' => 'response_rate', + 'type' => 'raw', + 'value'=>'CHtml::link($data->responseRate . "%", Yii::app()->createUrl("admin/survey/sa/view/",array("surveyid"=>$data->sid)))', + 'htmlOptions' => array('class' => 'has-link'), + ), + + array( 'header' => '', 'name' => 'actions', 'value'=>'$data->buttons', diff --git a/application/models/Survey.php b/application/models/Survey.php index 75fe90480..8b98b8397 100644 --- a/application/models/Survey.php +++ b/application/models/Survey.php @@ -106,6 +106,7 @@ class Survey extends LSActiveRecord private $fac; private $pac; + private $responseRate; /** * init to set default @@ -1323,4 +1324,36 @@ class Survey extends LSActiveRecord $criteria->addNotInCondition('title', CHtml::listData($validSubQuestion,'title','title')); Question::model()->deleteAll($criteria);// Must log count of deleted ? } + + public function getResponseRate() + { + if ($this->responseRate!=null) + { + return $this->responseRate; + } + else { + $table = '{{tokens_' . $this->sid . '}}'; + if (tableExists("$table")) + { + $tokencount = Yii::app()->db->createCommand('SELECT count(tid) FROM ' . $table )->queryScalar(); + //get the number of COMLETED tokens for each survey + $tokencompleted = $this->getCountTotalAnswers(); + + if($tokencompleted != 0 && $tokencount != 0) + { + $tokenpercentage = round(($tokencompleted / $tokencount) * 100, 1); + } + else + { + $tokenpercentage = 0; + } + } + else + { + $tokenpercentage = 0; + } + $this->responseRate = $tokenpercentage; + return $tokenpercentage; + } + } }