예제 #1
0
 public function indexAction($school_id = 0, $error = null)
 {
     if (!isset($error)) {
         $this->session->set("school_id", $school_id);
         $this->view->setVar("error", false);
     } else {
         $this->view->setVar("error", $error);
     }
     $school = School::findFirst(array("school_id=:school_id:", "bind" => array("school_id" => $this->session->get("school_id"))));
     if ($school != null) {
         $this->view->setVar("school_name", $school->name);
     } else {
         $this->view->setVar("school_name", "");
         $this->flash->error("对不起,您访问的学校不存在");
     }
     $this->view->setVar("type", "student");
     $this->view->setVar("target", "/stulogin/check");
 }
예제 #2
0
 public function exportAction()
 {
     $this->view->disable();
     if ($this->request->isGet()) {
         $this->response->setHeader("Content-Type", "application/force-download");
         $this->response->setHeader("Content-Transfer-Encoding", "binary");
         $this->response->setHeader("Pragma", "no-cache");
         $this->response->setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
         $base_row = 5;
         $excel = new PHPExcel();
         $sheet = $excel->getSheet(0);
         $sheet->setTitle("sheet0");
         $filename = $this->create_uuid() . ".xls";
         $manager = $this->session->get("manager");
         $test_id = $this->request->get("test_id");
         $school_id = $manager["school_id"];
         $test = Test::findFirst($test_id);
         $school = School::findFirst($school_id);
         $sheet->setCellValue("A1", "学校");
         $sheet->setCellValue("B1", $school->name);
         $sheet->setCellValue("A2", "地区");
         $sheet->setCellValue("B2", $school->district);
         $sheet->setCellValue("A3", "测试名称");
         $sheet->setCellValue("B3", $test->description);
         $sheet->setCellValue("A4", "姓名");
         $sheet->setCellValue("B4", "学号");
         $sheet->setCellValue("C4", "性别");
         $sheet->setCellValue("D4", "出生日期");
         $sheet->setCellValue("E4", "民族");
         $sheet->setCellValue("F4", "是否独生子女");
         $sheet->setCellValue("G4", "生源地");
         $sheet->setCellValue("H4", "院系");
         $sheet->setCellValue("I4", "专业");
         $sheet->setCellValue("J4", "年级");
         $sheet->setCellValue("K4", "班级");
         $base_col = "L";
         foreach ($test->Part as $part) {
             $sheet->setCellValue($base_col . "4", $part->name);
             $base_col++;
         }
         foreach ($test->Student as $student) {
             $sheet->setCellValue("A" . $base_row, $student->name);
             $sheet->setCellValue("B" . $base_row, $student->stu_no);
             $sex = $student->sex == 0 ? "女" : "男";
             $sheet->setCellValue("C" . $base_row, $sex);
             $sheet->setCellValue("D" . $base_row, $student->birthday);
             $sheet->setCellValue("E" . $base_row, $student->nation);
             $singleton = $student->singleton == 0 ? "否" : "是";
             $sheet->setCellValue("F" . $base_row, $singleton);
             $nativeplace = $student->nativeplace == 0 ? "农村" : "城镇";
             $sheet->setCellValue("G" . $base_row, $nativeplace);
             $sheet->setCellValue("H" . $base_row, $student->college);
             $sheet->setCellValue("I" . $base_row, $student->major);
             $sheet->setCellValue("J" . $base_row, $student->grade);
             $sheet->setCellValue("K" . $base_row, $student->class);
             $base_col = "L";
             foreach ($student->Total as $total) {
                 $sheet->setCellValue("{$base_col}" . "{$base_row}", $total->answers);
                 $base_col++;
             }
             $base_row++;
         }
         $writer = PHPExcel_IOFactory::createWriter($excel, "Excel5");
         $writer->save("../cache/temp/{$filename}");
         $excel->disconnectWorksheets();
         $this->response->setFileToSend("../cache/temp/{$filename}", $test->description . "学生资料.xls");
         $this->response->send();
         //return $response;
     }
 }
예제 #3
0
 public function addStudent($filename)
 {
     $this->db->begin();
     $school = School::findFirst(array('name = :filename:', 'bind' => array('filename' => substr($filename, 0, strlen($filename) - 4))));
     try {
         $test = $this->addTest($school);
         $this->addstudents($filename, $test->t_id, $school->school_id);
     } catch (PDOException $ex) {
         $this->db->rollback();
         return $ex->getMessage();
     }
     $this->db->commit();
 }