コード例 #1
0
 //var_dump($students);
 try {
     $today = new DateTime();
     $lec_date = new DateTime($_POST['date']);
     $st_date = new DateTime($students['metadata']['start_date']);
     $end_date = new DateTime($students['metadata']['end_date']);
 } catch (\Exception $e) {
     attd_error(HTTP_Status::BAD_REQUEST, "Invalid lecture date format.");
 }
 if ($lec_date < $st_date || $lec_date > $today) {
     attd_error(HTTP_Status::BAD_REQUEST, "Lecture date must be within " . $st_date->format("d-m-Y") . " to " . $today->format("d-m-Y") . ".");
 }
 $lec_date = $lec_date->format("Y-m-d");
 try {
     $db = new MyDbCon();
     $db->beginTransaction();
     $obj = new Lectures(array('lec_date' => $lec_date, 'attd_mst_id' => $queries['mst']));
     $db->insert($obj);
     $db->prepare();
     $db->execute();
     $lec_id = $db->getLastGeneratedValue();
     $db->setInsert(new Attendance());
     $abs_objs = array();
     foreach ($students['data'] as $stud) {
         //$ids[]=$stud['stud_id'];
         $presence = 1;
         if (in_array($stud['stud_id'], $abs_ids)) {
             $presence = 0;
         }
         $abs_objs[] = new Attendance(array('lec_id' => $lec_id, 'stud_id' => $stud['stud_id'], 'presence' => $presence));
     }