public function updatetestAction() { $this->response->setHeader("Content-Type", "text/plain; charset=utf-8"); if ($this->request->isPost()) { $test_id = $this->request->getPost("test_id", "int"); $sn = $this->request->getPost("date", "string"); $date = explode(" - ", $sn); // $people = $this->request->getPost("people", "int"); $people = 0; $description = $this->request->getPost("description", "string"); $parts = $this->request->getPost("part"); $test = Test::findFirst(array("t_id=:t_id:", "bind" => array("t_id" => $test_id))); $test->people = $people; $pcount = count($parts); $manager = $this->session->get("Manager"); $test->school_id = $manager["school_id"]; $test->begin_time = date("Y-m-d H:i", strtotime($date[0])); $test->end_time = date("Y-m-d H:i", strtotime($date[1])); $test->exam_num = $pcount; $test->description = $description; $this->db->begin(); try { if ($test->save()) { $tprls = Tprel::find(array("test_id=:test_id:", "bind" => array("test_id" => $test->t_id))); foreach ($tprls as $tp) { $tp->delete(); } foreach ($parts as $part) { $tprel = new Tprel(); $tprel->test_id = $test->t_id; $tprel->part_id = $part; $tprel->save(); } $this->db->commit(); echo "true"; } else { throw new PDOException(); } } catch (PDOException $ex) { $this->db->rollback(); echo $ex->getMessage(); echo "保存失败"; } } else { echo "请求数据无效"; } $this->view->disable(); }
public function addTest($school) { $test = new Test(); $test->people = 2; $test->school_id = $school->school_id; $test->begin_time = '2014-12-5 00:00:00'; $test->end_time = '2014-12-15 23:59:59'; $parts = Part::find(); $test->exam_num = $parts->Count(); $test->description = '2014心理健康测评'; if (!$test->save()) { foreach ($school->getMessages() as $message) { throw new PDOException($message); } } foreach ($parts as $part) { $tprel = new Tprel(); $tprel->test_id = $test->t_id; $tprel->part_id = $part->p_id; $tprel->save(); } return $test; }