点击回首页
我的浏览记录 | | 帮助?
当前位置:
首页>> 行业软件>> 在线考试系统>> 源文件浏览
[免费版 Free] WebForm,下载次数:254 次 | 关键字: 考试 办公 高校 竞赛 企事业单位

源码截图

源码目录树

;
当前路径:app/common/model/exam/Knowledge.php
<?php

declare(strict_types=1);

namespace app\common\model\exam;

use mb\helper\Collection;
use think\facade\Db;
use Exception;
use think\facade\Log;

/**
 * Class Knowledge
 * @package app\common\model\exam
 */
class Knowledge
{
    public const EXPORT_FIELDS = [
        '' => '',
        'knowledgeTitle' => '知识点',
        'subjectTitle' => '科目',
        'num' => '试题数量',
        'score' => '试题总分',
        'point' => '得分率'
    ];
    /**
     * title
     * subjectId
     * @param array $filter
     * @param int $pIndex
     * @param int $pSize
     * @param int $total
     * @return array
     */
    public static function search(array $filter, int $pIndex = 1, int $pSize = 10, &$total = 0)
    {
        $where = [];
        if (!empty($filter['subjectId'])) {
            $where[] = ['subject_id', '=', $filter['subjectId']];
        }
        if (!empty($filter['title'])) {
            $where[] = ['title', 'like', "%{$filter['title']}%"];
        }
        if (!empty($filter['subjectIds'])) {
            $where[] = ['subject_id', 'in', "{$filter['subjectIds']}"];
        }
        try {
            $total = Db::table('exam_knowledge')->where($where)->count();
            $query = Db::table('exam_knowledge')->where($where);
            if (!empty($pIndex)) {
                $query->page($pIndex, $pSize);
            }
            $dataSet = $query->select()->toArray();
            if (!empty($dataSet)) {
                $dataSet = array_map(
                    function ($val) {
                        return Collection::keyStyle($val, Collection::NAME_STYLE_JAVA);
                    },
                    $dataSet
                );
                return $dataSet;
            } else {
                return [];
            }
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return [];
    }

    /**
     * subjectId
     * title
     * @param array $data
     * @return int|string
     */
    public static function add(array $data)
    {
        $newData = Collection::keyStyle($data, Collection::NAME_STYLE_C);
        $newData = Collection::elements(['subject_id', 'title'], $newData);
        try {
            return Db::table('exam_knowledge')->insertGetId($newData);
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return 0;
    }

    /**
     * @param array $where
     * @param array $data
     * @return bool
     */
    public static function update(array $where, array $data)
    {
        $newData = Collection::keyStyle($data, Collection::NAME_STYLE_C);
        $newData = Collection::elements(['subject_id', 'title'], $newData);
        try {
            $offect = Db::table('exam_knowledge')
                ->where($where)->update($newData);
            if ($offect === 1) {
                return true;
            } else {
                return false;
            }
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return false;
    }

    /**
     * @param string $type
     * @param string $ids
     * @return bool
     */
    public static function delete(string $type, string $ids)
    {
        if ($type == 'single') {
            $where[] = ['id', '=', $ids];
        } else {
            $where[] = ['id', 'in', "{$ids}"];
        }
        try {
            Db::table('exam_knowledge')
                ->where($where)->delete();
            return true;
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return false;
    }

    /**
     * @param $id
     * @return array
     */
    public static function fetch($id)
    {
        $where = [];
        if (is_array($id)) {
            if (!empty($id['title'])) {
                $where[] = ['title', '=', $id['title']];
            }
        } else {
            $where[] = ['id', '=', $id];
        }
        try {
            $userInfo = Db::table('exam_knowledge')
                ->where($where)
                ->find();
            if (!empty($userInfo)) {
                return Collection::keyStyle($userInfo, Collection::NAME_STYLE_JAVA);
            }
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return [];
    }

    /**
     * @param string $title
     * @param int $id
     * @return bool
     */
    public static function check(string $title, int $id = 0)
    {
        try {
            $res = Db::table('exam_knowledge')->where(['title' => $title])->find();
            if ((empty($id) && !empty($res)) || (!empty($id) && !empty($res) && ($res['id'] != $id))) {
                return false;
            }
            return true;
        } catch (Exception $e) {
            Log::channel('myError')->write($e->getMessage(), \think\Log::ERROR);
        }
        return false;
    }
}
关于我们 | 顾问团队 | 发展历程 | 联系我们 | 源码上传
联系电话(Tel):4008-010-151(免长途)
地址:北京市海淀区大恒科技大厦五层 邮编:100080
Floor 5th,Daheng Building,Zhongguancun,Beijing,China,100080
51Aspx.com 版权所有 CopyRight © 2006-2022. 京ICP备09089570号 | 京公网安备11010702000869号