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.
wx.sstbc.com/app/Models/CourseContentEvaluationAsk.php

51 lines
1.2 KiB

9 months ago
<?php
namespace App\Models;
class CourseContentEvaluationAsk extends SoftDeletesModel
{
3 months ago
protected $casts = [
'select_item' => 'json'
];
9 months ago
7 months ago
public function courseContent()
{
7 months ago
return $this->hasOne(CourseContent::class, 'id', 'course_content_id');
7 months ago
}
3 months ago
/**
* 判断是否为多维度题目
* @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;
}
9 months ago
}