add answer, time, status helpers
This commit is contained in:
@ -2,8 +2,8 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\ActiveQuery;
|
||||
use yii\db\Expression;
|
||||
|
||||
/**
|
||||
@ -78,9 +78,9 @@ class Answer extends \yii\db\ActiveRecord
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \yii\db\ActiveQuery
|
||||
* @return ActiveQuery
|
||||
*/
|
||||
public function getQuestion()
|
||||
public function getQuestion(): ActiveQuery
|
||||
{
|
||||
return $this->hasOne(Question::className(), ['id' => 'question_id']);
|
||||
}
|
||||
@ -91,32 +91,6 @@ class Answer extends \yii\db\ActiveRecord
|
||||
return $this->getQuestion()->one()->question_body;
|
||||
}
|
||||
|
||||
public function getStatuses()
|
||||
{
|
||||
return [
|
||||
self::STATUS_ACTIVE => 'Активен',
|
||||
self::STATUS_PASSIVE => 'Не используется'
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatusText()
|
||||
{
|
||||
return $this->statuses[$this->status];
|
||||
}
|
||||
|
||||
public function getFlags()
|
||||
{
|
||||
return [
|
||||
self::FLAG_TRUE => 'Правильный',
|
||||
self::FLAG_FALSE => 'Ошибочный',
|
||||
];
|
||||
}
|
||||
|
||||
public function getFlagText()
|
||||
{
|
||||
return $this->flags[$this->status];
|
||||
}
|
||||
|
||||
static function getCorrectAnswersNum($question_id)
|
||||
{
|
||||
return Answer::find()
|
||||
@ -126,7 +100,7 @@ class Answer extends \yii\db\ActiveRecord
|
||||
->count();
|
||||
}
|
||||
|
||||
public static function getActiveAnswers($question_id)
|
||||
public static function getActiveAnswers($question_id): array
|
||||
{
|
||||
return self::find()->where(['question_id' => $question_id])
|
||||
->andWhere(['status' => '1'])
|
||||
|
@ -2,8 +2,6 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use phpDocumentor\Reflection\Types\This;
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\Expression;
|
||||
use yii\helpers\ArrayHelper;
|
||||
@ -112,38 +110,15 @@ class Questionnaire extends \yii\db\ActiveRecord
|
||||
return $this->hasMany(UserQuestionnaire::className(), ['questionnaire_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getStatuses()
|
||||
{
|
||||
return [
|
||||
self::STATUS_ACTIVE => 'Активна',
|
||||
self::STATUS_PASSIVE => 'Не используется'
|
||||
];
|
||||
}
|
||||
|
||||
public function getStatusText()
|
||||
{
|
||||
return $this->statuses[$this->status];
|
||||
}
|
||||
|
||||
public function getCategoryTitle()
|
||||
{
|
||||
return $this->getCategory()->one()->title;
|
||||
}
|
||||
|
||||
public function getLimitTime()
|
||||
{
|
||||
if ($this->time_limit === null)
|
||||
{
|
||||
return 'Не ограничено';
|
||||
}
|
||||
|
||||
return date("H:i:s", mktime(null, null, $this->time_limit));
|
||||
}
|
||||
|
||||
public static function getQuestionnaireByCategory($category_id)
|
||||
{
|
||||
$categories = self::find()->where(['category_id' => $category_id, 'status' => '1'])->all();
|
||||
$catArr = \yii\helpers\ArrayHelper::map($categories, 'id', 'title');
|
||||
$catArr = ArrayHelper::map($categories, 'id', 'title');
|
||||
|
||||
$formattedCatArr = array();
|
||||
foreach ($catArr as $key => $value){
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
namespace common\models;
|
||||
|
||||
use Yii;
|
||||
use yii\behaviors\TimestampBehavior;
|
||||
use yii\db\Expression;
|
||||
use yii\helpers\ArrayHelper;
|
||||
@ -79,22 +78,6 @@ class QuestionnaireCategory extends \yii\db\ActiveRecord
|
||||
return $this->hasMany(Questionnaire::className(), ['category_id' => 'id']);
|
||||
}
|
||||
|
||||
public function getStatuses()
|
||||
{
|
||||
return [
|
||||
self::STATUS_PASSIVE => 'Не используется',
|
||||
self::STATUS_ACTIVE => 'Активна'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string status text label
|
||||
*/
|
||||
public function getStatusText()
|
||||
{
|
||||
return $this->statuses[$this->status];
|
||||
}
|
||||
|
||||
public function getIdTitlesArr()
|
||||
{
|
||||
$categories = self::find()->select(['id', 'title'])->where(['status' => '1'])->all();
|
||||
|
Reference in New Issue
Block a user