public function exam() { $exam = new \Hnust\Analyse\Exam($this->sid, $this->passwd); $this->data = $exam->getExam(); if ($exam->error) { $this->msg = $exam->error; } elseif (empty($this->data)) { $this->code = Config::RETURN_ERROR; $this->msg = '未查询到相关考试安排'; } $this->info = array('sid' => $this->sid, 'type' => $type); }
protected function hasExam($sid, $name, $score, $term, $case = 1) { //尝试获取考试安排 try { $examClass = new \Hnust\Analyse\Exam($sid); $exam = $examClass->getExam('com'); } catch (\Exception $e) { if ($e->getCode() === Config::RETURN_NEED_PASSWORD || $case > 3) { $this->record("获取【{$name}】的最新考试安排失败:" . $e->getMessage()); return false; } return $this->hasExam($sid, $name, $score, $term, $case + 1); } //成绩获取错误 if ($examClass->error) { $this->record("获取【{$name}】的最新考试安排失败:" . $examClass->error); } //判断最近是否存在考试 for ($i = 0; $i < count($exam); $i++) { //判断考试是否已经开始 if (strtotime($exam[$i]['end']) >= time()) { continue; } //是否公布该科成绩 $score[$term] = isset($score[$term]) ? $score[$term] : array(); for ($j = 0; $j < count($score[$term]); $j++) { if ($exam[$i]['course'] === $score[$term][$j]['course']) { break; } } if ($j < count($score[$term])) { continue; } return true; } return false; }
public function exam() { $exam = new \Hnust\Analyse\Exam($this->sid, $this->passwd); $data = $exam->getExam(); if (empty($data)) { $this->code = Config::RETURN_ERROR; $this->msg = '未查询到相关考试安排'; return false; } //拼接考试安排字符串 $content = ''; $templet = "{course}\n开始:{begin}\n结束:{end}\n地点:{room}\n\n"; foreach ($data as $item) { $content .= \Hnust\templet($templet, $item); } //回复 if ($exam->error) { $content .= $exam->error; } $this->data = trim($content); }