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

   function GetDataMatakuliahKurForAdd(){
      $dataListParam = $this->GetProperty("DataProceed");

      //prep data for query
      $arrTemp = array();
      for ($i=0; $i < count($dataListParam); $i++) {
         $arrTemp[$i] = $dataListParam[$i]['id_kurikulum_sp'].'@'.$dataListParam[$i]['id_mk'];
      }
      $stringHavingNotIn = implode("','",$arrTemp);
      $this->mSqlQueries['GetDataMatakuliahKurForAdd'] = str_replace('[STRINGHAVINGNOTIN]', $stringHavingNotIn, $this->mSqlQueries['GetDataMatakuliahKurForAdd']);
      return $this->GetAllDataAsArray($this->mSqlQueries['GetDataMatakuliahKurForAdd'], array());
   }

   function insertFeederMatakuliahKur(){
      $dataList = $this->GetProperty("DataProceed");

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

      for ($i=0; $i < count($dataList); $i++) {
         //cek apakah dilakukan insert or update
         $p = array(
            $dataList[$i]['id_kurikulum_sp'],
            $dataList[$i]['id_mk']
         );
         $cekDataExist = $this->ExecuteInsertQuery($this->mSqlQueries['cekDataExist'], $p);
         if($cekDataExist[0]['BANYAK'] > 0){
            //update
            $p = array(
               $dataList[$i]['smt'],
               $dataList[$i]['sks_mk'],
               $dataList[$i]['sks_tm'],
               $dataList[$i]['sks_prak'],
               $dataList[$i]['sks_prak_lap'],
               $dataList[$i]['sks_sim'],
               $dataList[$i]['a_wajib'],
               $dataList[$i]['id_kurikulum_sp'],
               $dataList[$i]['id_mk']
            );
            $proses = $this->ExecuteUpdateQuery($this->mSqlQueries['updateFeederMatakuliahKur'], $p);
         }else{
            //insert
            $p = array(
               $dataList[$i]['id_kurikulum_sp'],
               $dataList[$i]['id_mk'],
               $dataList[$i]['smt'],
               $dataList[$i]['sks_mk'],
               $dataList[$i]['sks_tm'],
               $dataList[$i]['sks_prak'],
               $dataList[$i]['sks_prak_lap'],
               $dataList[$i]['sks_sim'],
               $dataList[$i]['a_wajib']
            );
            $proses = $this->ExecuteInsertQuery($this->mSqlQueries['insertFeederMatakuliahKur'], $p);
         }
         if($proses == FALSE) $prosesInsertUpdate = FALSE;
      }

      $this->CompleteTransaction($prosesInsertUpdate);
      return $prosesInsertUpdate;
   }
}
?>