src/Biz/Testpaper/Dao/Impl/TestpaperItemResultDaoImpl.php

(开头部分) 1KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

<?php

namespace Biz\Testpaper\Dao\Impl;

use Biz\Testpaper\Dao\TestpaperItemResultDao;
use Codeages\Biz\Framework\Dao\GeneralDaoImpl;

class TestpaperItemResultDaoImpl extends GeneralDaoImpl implements TestpaperItemResultDao
{
    protected $table = 'testpaper_item_result_v8';

    public function findItemResultsByResultId($resultId, $type)
    {
        return $this->findByFields(array('resultId' => $resultId, 'type' => $type));
    }

    public function addItemAnswers($testPaperResultId, $answers, $testPaperId, $userId)
    {
        if (empty($answers)) {
            return array();
        }

        $answers = array_map(function ($answer) {
            return json_encode($answer);
        }, $answers);

        $mark = '('.str_repeat('?,', 4).'? )';
        $marks = str_repeat($mark.',', count($answers) - 1).$mark;
        $answersForSQL = array();

        foreach ($answers as $key => $value) {
            array_push($answersForSQL, (int) $testPaperId, (int) $testPaperResultId, (int) $userId, (int) $key, $value);
        }

        $sql = "INSERT INTO {$this->table} (`testId`, `resultId`, `userId`, `questionId`, `answer`) VALUES {$marks};";

        return $this->db()->executeUpdate($sql, $answersForSQL);
    }

    //要不要给这三个字段加上索引呢
    public function updateItemAnswers($testPaperResultId, $answers)
    {
        if (empty($answers)) {
            return array();
        }

        $answers = array_map(function ($answer) {
            return json_encode($answer);
        }, $answers);

        $sql = '';
        $answersForSQL = array();

        $this->db()->beginTransaction();
        try {
            foreach ($answers as $key => $value) {
                $sql = "UPDATE {$this->table} set `answer` = ? WHERE `questionId` = ? AND `resultId` = ?;";
                $answersForSQL = array($value, (int) $key, (int) $testPaperResultId);
                $this->db()->executeQuery($sql, $answersForSQL);
            }

24 小时内免费解锁 3 个项目,之后 1 算力/个。 规则说明

AI 解读 AI

登录后可用,每次 10 算力,解读结果公开显示在下面。

还没有人解读过这个文件。