You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
|
|
class CourseContentEvaluationAsk extends SoftDeletesModel
|
|
|
|
|
|
{
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
|
'select_item' => 'json'
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
public function courseContent()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->hasOne(CourseContent::class, 'id', 'course_content_id');
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 判断是否为多维度题目
|
|
|
|
|
|
* @return bool
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function isMultiDimension()
|
|
|
|
|
|
{
|
|
|
|
|
|
return $this->edit_input === 'multi_dimension';
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 获取维度数据(访问器)
|
|
|
|
|
|
* 当题目为多维度题目时返回维度数据,否则返回空数组
|
|
|
|
|
|
* 注意:访问器会覆盖cast,所以需要手动处理JSON解码
|
|
|
|
|
|
* @return array
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function getDimensionsAttribute($value)
|
|
|
|
|
|
{
|
|
|
|
|
|
if ($this->isMultiDimension() && !empty($value)) {
|
|
|
|
|
|
// 手动处理JSON解码
|
|
|
|
|
|
return is_string($value) ? json_decode($value, true) : $value;
|
|
|
|
|
|
}
|
|
|
|
|
|
return [];
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 设置维度数据(修改器)
|
|
|
|
|
|
* 将数组转换为JSON字符串存储
|
|
|
|
|
|
* @param mixed $value
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function setDimensionsAttribute($value)
|
|
|
|
|
|
{
|
|
|
|
|
|
$this->attributes['dimensions'] = is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|