コード例 #1
0
 public function save_dt($id_don_vi, $nam, $deTais, $thanhViens)
 {
     $tableDT = Khcn_Api::_()->getDbTable('de_tai', 'default');
     $tableGV = Khcn_Api::_()->getDbTable('giang_vien', 'default');
     $don_vi = $this->don_vi->getDonVi($id_don_vi);
     $ma_don_vi = $don_vi['ma'];
     $str = '';
     $dts = array();
     $tong_so_gv = 0;
     $gv_sai_ma_don_vi = array();
     $gv_sai_ma_hoc_vi = array();
     $session = new Zend_Session_Namespace('imported_dt');
     $session->ma_don_vi = $id_don_vi;
     $session->nam = $nam;
     $db = $tableDT->getAdapter();
     $db->beginTransaction();
     try {
         for ($i = 0; $i < count($deTais); $i++) {
             //tao ma cho de tai
             //linh vuc
             $ma_loai_lv = 'CS';
             $linh_vuc = $this->linh_vuc->getLVByMa($deTais[$i]['linh_vuc']);
             $loai_lv = $this->loai_lv->getLoaiLV($linh_vuc['ma_loai']);
             if ($loai_lv) {
                 $ma_loai_lv = $loai_lv['ma'];
             }
             $id_linh_vuc = $linh_vuc['id'];
             $cap_quan_ly = $deTais[$i]['cap_quan_ly'];
             $ma = '';
             if ($cap_quan_ly != 'cap-khoa') {
                 $count_m_t = 1;
                 while ($ma == '') {
                     if ($count_m_t < 10) {
                         $temp_m = $ma_loai_lv . $nam . '-0' . $count_m_t++;
                     } else {
                         $temp_m = $ma_loai_lv . $nam . '-' . $count_m_t++;
                     }
                     if (!$this->de_tai->kiem_tra_ma($temp_m)) {
                         $ma = $temp_m;
                     }
                 }
             }
             //dinh dang ngay thang
             $sperator = array('/', ' ');
             $tgbd = '01-' . str_replace($sperator, '-', $deTais[$i]['thoi_gian_bat_dau']);
             $tght = '01-' . str_replace($sperator, '-', $deTais[$i]['thoi_gian_hoan_thanh']);
             $thoi_gian_bat_dau = date('Y-m-d', strtotime($tgbd));
             $thoi_gian_hoan_thanh = date('Y-m-d', strtotime($tght));
             //cap quan ly
             if ($cap_quan_ly == 'cap-khoa') {
                 $cap_quan_ly = 1;
             } else {
                 $cap_quan_ly = 2;
             }
             $kinh_phi = 0;
             if (!empty($deTais[$i]['kinh_phi']) && is_numeric($deTais[$i]['kinh_phi'])) {
                 $kinh_phi = $deTais[$i]['kinh_phi'];
             }
             try {
                 //them de tai
                 $de_tai = $tableDT->createRow();
                 $de_tai->ma = $ma;
                 $de_tai->ten = $deTais[$i]['ten'];
                 $de_tai->thoi_gian_bat_dau = $thoi_gian_bat_dau;
                 $de_tai->thoi_gian_hoan_thanh = $thoi_gian_hoan_thanh;
                 $de_tai->tinh_trang = 1;
                 $de_tai->kinh_phi = $kinh_phi;
                 $de_tai->cap_quan_ly = $cap_quan_ly;
                 $de_tai->ma_linh_vuc = $id_linh_vuc;
                 $de_tai->ma_don_vi = $id_don_vi;
                 $de_tai->nam = $nam;
                 $kq = $de_tai->save();
             } catch (Zend_Db_Exception $e) {
                 $str .= $deTais[$i]['ten'] . ', ';
                 continue;
             }
             $dt_id = $de_tai->id;
             $dts[$dt_id] = $dt_id;
             //them thanh vien
             $tvs = $thanhViens[$i];
             foreach ($tvs as $thanh_vien) {
                 $tong_so_gv++;
                 $tv_id = null;
                 $sai_ma_hv = false;
                 $sai_ma_dv = false;
                 //kiem tra neu co nhap ma giang vien
                 $ho_ten = Default_Model_Functions::tach_ho_ten($thanh_vien['ho_ten']);
                 // Get ID Hoc Vi
                 $id_hv = $this->hoc_vi->getIdByMa($thanh_vien['hoc_vi']);
                 if ($id_hv == null) {
                     $sai_ma_hv = true;
                     //set hoc vi la chua xac dinh
                     $id_hv = 9;
                 }
                 // Get ID Don Vi
                 if (!empty($thanh_vien['ghi_chu'])) {
                     //kiem tra neu nhap sai ma don vi,thi dua vao danh sach gv chua xac dinh don vi
                     $id_dv = $this->don_vi->getIdByMa($thanh_vien['ghi_chu']);
                     if ($id_dv == null) {
                         $sai_ma_dv = true;
                         $id_dv = $id_don_vi;
                     }
                 } else {
                     $id_dv = $id_don_vi;
                 }
                 if (!empty($thanh_vien['ma_giang_vien'])) {
                     //kiem tra ton tai ma giang vien
                     $giang_vien = $tableGV->getGVByMa($thanh_vien['ma_giang_vien']);
                     if ($giang_vien) {
                         $tv_id = $giang_vien->id;
                     }
                 }
                 // Get GV By ho_ten, dv, hv
                 if ($tv_id == null) {
                     $giang_vien = $tableGV->checkExistImport($thanh_vien['ho_ten'], $id_dv, $id_hv);
                     if ($giang_vien == null) {
                         $giang_vien = $tableGV->createRow();
                         $giang_vien->ho = $ho_ten['ho'];
                         $giang_vien->ten = $ho_ten['ten'];
                         $giang_vien->ma_hoc_vi = $id_hv;
                         $giang_vien->ma_don_vi = $id_dv;
                         $giang_vien->trang_thai = 1;
                         $giang_vien->save();
                     }
                     $tv_id = $giang_vien->id;
                 }
                 //neu co nhap email - so dien thoai thi cap nhat lai
                 if (!empty($thanh_vien['email'])) {
                     $giang_vien->email = $thanh_vien['email'];
                 }
                 if (!empty($thanh_vien['so_dien_thoai'])) {
                     $giang_vien->so_dien_thoai = $thanh_vien['so_dien_thoai'];
                 }
                 $giang_vien->save();
                 // Them dang ky
                 $dang_ky = new Default_Model_DangKy();
                 $dang_ky->setMaDeTai($dt_id)->setMaGiangVien($tv_id)->setNhiemVu($thanh_vien['nhiem_vu']);
                 $dang_ky->them();
                 if ($sai_ma_dv) {
                     $gv_sai_ma_don_vi[$tv_id] = $thanh_vien['ho_ten'];
                 }
                 if ($sai_ma_hv) {
                     $gv_sai_ma_hoc_vi[$tv_id] = $thanh_vien['ho_ten'];
                 }
             }
         }
         $db->commit();
         if ($str != '') {
             $_SESSION['msg'] = "Lỗi. Các đề tài sau đây không import được : " . $str;
             $_SESSION['type_msg'] = "error";
         } else {
             $_SESSION['msg'] = "Thành công! Dữ liệu đã được lưu trữ.";
             $_SESSION['type_msg'] = "success";
         }
         $session->deTais = $dts;
         $session->tong_so_gv = $tong_so_gv;
         $session->gv_sai_ma_hoc_vi = $gv_sai_ma_hoc_vi;
         $session->gv_sai_ma_don_vi = $gv_sai_ma_don_vi;
     } catch (Exception $e) {
         $db->rollBack();
         throw $e;
     }
 }
コード例 #2
0
ファイル: DangKy.php プロジェクト: nhochong/qlkh-sgu
 public function sua_thanh_vien($ma_de_tai, $arr)
 {
     $this->dang_ky->xoa_tv_by_mdt($ma_de_tai);
     foreach ($arr as $data) {
         $dang_ky = new Default_Model_DangKy();
         $dang_ky->setMaDeTai($ma_de_tai)->setMaGiangVien($data['ma_giang_vien'])->setNhiemVu('0');
         $dang_ky->them();
     }
 }