コード例 #1
0
ファイル: StudentController.php プロジェクト: nguyenvanvu/slu
 public function actionImportData()
 {
     // if $_REQUEST info is set, process it and insert into database
     // then exit
     if (isset($_POST['action'])) {
         $data = $_POST['info'];
         $success = 0;
         $fail = 0;
         foreach ($data as $line => $record) {
             $line = (int) $line + 2;
             $criteria = new CDbCriteria();
             foreach ($record as $key => $value) {
                 $criteria->addCondition($key . "='" . $value . "'");
             }
             $count = RsStudentPassed::model()->count($criteria);
             if ($count == 0) {
                 $student_pass = new RsStudentPassed();
                 $student_pass->student_code = $record['student_code'];
                 $student_pass->school_reg_code = $record['school_reg_code'];
                 $student_pass->staff_code = $record['staff_code'];
                 if ($student_pass->save()) {
                     $success++;
                 } else {
                     $fail++;
                 }
             } else {
                 $fail++;
             }
         }
         echo "合格者情報の取り込みは完了しました。<br>成功: " . $success . "件<br>失敗: " . $fail . "件";
         exit;
     }
     // else render the page instead
     $this->render('importData');
 }