function GetProportionByUserIDPaperID($userID, $paperID)
{
    include_once '../DAL/testResultDal.php';
    include_once '../DAL/selectResultDal.php';
    include_once '../DAL/questionDal.php';
    /*根据用户ID和试卷ID找出选择的结果 存入userSelection变量中*/
    $userSelection = FindSelectResultByUserPaper($userID, $paperID);
    $proportionArray = array();
    foreach ($userSelection as $single) {
        $resultID = $single[0];
        //找到主键
        $questionID = $single[3];
        $selectInfo = $single[4];
        //因为FindQuestionNumInPaperByQuestionID返回的是一个二维数组  我们需要的数组下标为[0][0]
        $questionNum = FindQuestionNumInPaperByQuestionID($questionID)[0][0];
        //初始的时候四个选项选择的数目次数均为0 如果是判断题 只有前俩位有效
        $proportionArray[questionNum - 1] = [0, 0, 0, 0];
        if ($selectInfo == 'A' || $selectInfo == '0') {
            $proportionArray[questionNum - 1][0]++;
        } else {
            if ($selectInfo == 'B' || $selectInfo == '1') {
                $proportionArray[questionNum - 1][1]++;
            } else {
                if ($selectInfo == 'C') {
                    $proportionArray[questionNum - 1][2]++;
                } else {
                    if ($selectInfo == 'D') {
                        $proportionArray[questionNum - 1][3]++;
                    }
                }
            }
        }
    }
    return $proportionArray;
}
function CalculTestScore($userID, $paperID)
{
    include_once '../DAL/selectResultDal.php';
    include_once '../DAL/paperDal.php';
    include_once '../DAL/testResultDal.php';
    $isPaperScore = 0;
    $sumSocre = 0;
    $ScoreInfo = NULL;
    //在这里重新查询一边,因为之前把单项的得分写入了
    $userSelection = FindSelectResultByUserPaper($userID, $paperID);
    foreach ($userSelection as $single) {
        $sumSocre += $single[5];
    }
    /*判断该试卷是否有评分标准*/
    $paperResult = FindPaperByPaperID($paperID);
    foreach ($paperResult as $single) {
        $isPaperScore = $single[4];
    }
    //如果有
    if ($isPaperScore) {
        $ScoreInfo = GetScoreInfo($paperID, $sumSocre);
        //如果能正确返回结果,进行插入
        if ($ScoreInfo) {
            InsertTestResult($userID, $paperID, $sumSocre, $ScoreInfo);
        }
    }
}
function ExportSelectResultByUserIDPaperID($userID, $paperID)
{
    $letter = array('A', 'B', 'C', 'D', 'E', 'F', 'F', 'G');
    $tableheader = array('选则结果编号', '用户编号', '试卷编号', '试题编号', '用户选项', '该题得分');
    for ($i = 0; $i < count($tableheader); $i++) {
        $GLOBALS['excel']->getActiveSheet()->setCellValue("{$letter[$i]}1", "{$tableheader[$i]}");
    }
    $datas = FindSelectResultByUserPaper($userID, $paperID);
    /*填充表格内部的信息 因为第一行被表头占用了 所以数据都从第二行开始  */
    for ($i = 2; $i <= count($datas) + 1; $i++) {
        $j = 0;
        foreach ($datas[$i - 2] as $data) {
            $GLOBALS['excel']->getActiveSheet()->setCellValue("{$letter[$j]}{$i}", "{$data}");
            $j++;
        }
    }
    //创建Excel输入对象
    CreateExcel();
}