<?php
/*
Author : Nikolius
Email : n1colius.lau@gmail.com
Date : 08-Jul-2015 04:52 AM
*/
require_once $cfg->mValue['docroot'] . "module/sia_setting/business/sia_setting.class.php";
class Matakuliah extends SiaSetting {
   function Matakuliah(&$configObject, $dataProceed) {
      SiaSetting::SiaSetting($configObject, $dataProceed);
      $this->AppendSqlQueries("module/matakuliah/business/matakuliah.sql.php");
   }

   function GetDataMatakuliahForAdd(){
      $dataListParam = $this->GetProperty("DataProceed");
      //prep data for query
      $arrTemp = array();
      for ($i=0; $i < count($dataListParam); $i++) {
         $arrTemp[$i] = $dataListParam[$i]['id_sms'].'@'.$dataListParam[$i]['kode_mk'].'@'.$dataListParam[$i]['nm_mk'];
      }
      $stringHavingNotIn = implode("','",$arrTemp);
      $this->mSqlQueries['GetDataMatakuliahForAdd'] = str_replace('[STRINGHAVINGNOTIN]', $stringHavingNotIn, $this->mSqlQueries['GetDataMatakuliahForAdd']);
      return $this->GetAllDataAsArray($this->mSqlQueries['GetDataMatakuliahForAdd'], array());
   }

   function insertFeederMatakuliah(){
      $dataList = $this->GetProperty("DataProceed");
      //echo '<pre>'; print_r($dataListParam); exit;

      $this->StartTransaction();
      $prosesInsert = TRUE;

      for ($i=0; $i < count($dataList); $i++) {
         //get gt_id nya (mkkurId)
         $p = array(
            $dataList[$i]['id_sms'],
            $dataList[$i]['kode_mk'],
            $dataList[$i]['nm_mk']
         );
         $dataMkkurId = $this->GetAllDataAsArray($this->mSqlQueries['getMkkurId'], $p);
         $dataList[$i]['gt_id'] = $dataMkkurId[0]['mkkurId'];

         $p = array(
            $dataList[$i]['id_mk'],
            $dataList[$i]['id_sms'],
            $dataList[$i]['id_jenj_didik'],
            $dataList[$i]['kode_mk'],
            $dataList[$i]['nm_mk'],
            $dataList[$i]['jns_mk'],
            $dataList[$i]['kel_mk'],
            $dataList[$i]['sks_mk'],
            $dataList[$i]['sks_tm'],
            $dataList[$i]['sks_prak'],
            $dataList[$i]['sks_prak_lap'],
            $dataList[$i]['sks_sim'],
            $dataList[$i]['metode_pelaksanaan_kuliah'],
            $dataList[$i]['a_sap'],
            $dataList[$i]['a_silabus'],
            $dataList[$i]['a_bahan_ajar'],
            $dataList[$i]['acara_prak'],
            $dataList[$i]['a_diktat'],
            $dataList[$i]['tgl_mulai_efektif'],
            $dataList[$i]['tgl_akhir_efektif'],
            $dataList[$i]['gt_id'],
            $dataList[$i]['id_sms'], //on dup update
            $dataList[$i]['id_jenj_didik'],
            $dataList[$i]['kode_mk'],
            $dataList[$i]['nm_mk'],
            $dataList[$i]['jns_mk'],
            $dataList[$i]['kel_mk'],
            $dataList[$i]['sks_mk'],
            $dataList[$i]['sks_tm'],
            $dataList[$i]['sks_prak'],
            $dataList[$i]['sks_prak_lap'],
            $dataList[$i]['sks_sim'],
            $dataList[$i]['metode_pelaksanaan_kuliah'],
            $dataList[$i]['a_sap'],
            $dataList[$i]['a_silabus'],
            $dataList[$i]['a_bahan_ajar'],
            $dataList[$i]['acara_prak'],
            $dataList[$i]['a_diktat'],
            $dataList[$i]['tgl_mulai_efektif'],
            $dataList[$i]['tgl_akhir_efektif'],
            $dataList[$i]['gt_id']
         );
         $proses = $this->ExecuteInsertQuery($this->mSqlQueries['insertFeederMatakuliah'], $p);
         if($proses == FALSE) $prosesInsert = FALSE;
      }

      $this->CompleteTransaction($prosesInsert);
      return $prosesInsert;
   }
}

?>