<?php
/*
Author : Nikolius
Email : n1colius.lau@gmail.com
Date : 20-Jul-2015 01:33 PM
*/
require_once $cfg->mValue['docroot'] . "module/sia_setting/business/sia_setting.class.php";
class Bobot_nilai extends SiaSetting {

   function Bobot_nilai(&$configObject, $dataProceed) {
      SiaSetting::SiaSetting($configObject, $dataProceed);
      $this->AppendSqlQueries("module/bobot_nilai/business/bobot_nilai.sql.php");
   }

   function GetDataListForInsertSync(){
      //get all data nilai dari aplikasi SIA
      $dataNilai = $this->GetAllDataAsArray($this->mSqlQueries['getDataNilai'], array());

      //ambil data program studi dari feeder
      $dataProdi = $this->GetAllDataAsArray($this->mSqlQueries['getDataProdiFeeder'], array());

      //cek satu2 untuk setiap nilai di setiap prodinya.. jika belum ada di insertkan..jika sudah ada dilewatkan saja
      $paramReturn = array();
      $increData = 0;
      for ($i=0; $i < count($dataProdi); $i++) {
         for ($j=0; $j < count($dataNilai); $j++) {
            $p = array(
               $dataProdi[$i]['id_sms'],
               $dataNilai[$j]['kodeNilai']
            );
            $cekNilai = $this->GetAllDataAsArray($this->mSqlQueries['cekNilaiFeeder'], $p);

            if($cekNilai[0]['kode_bobot_nilai'] == ""){
               //masukkan param untuk insert
               $paramReturn[$increData]['kode_bobot_nilai'] = '';
               $paramReturn[$increData]['id_sms'] = $dataProdi[$i]['id_sms'];
               $paramReturn[$increData]['nilai_huruf'] = $dataNilai[$j]['kodeNilai'];
               $paramReturn[$increData]['bobot_nilai_min'] = '0';
               $paramReturn[$increData]['bobot_nilai_maks'] = '100';
               $paramReturn[$increData]['nilai_indeks'] = $dataNilai[$j]['bobotIndeks'];
               $paramReturn[$increData]['tgl_mulai_efektif'] = '1970-01-01';
               $paramReturn[$increData]['tgl_akhir_efektif'] = '1970-01-01';
               $increData++;
               /*
               if($dataProdi[$i]['id_sms'] == "4c8a1945-163e-44f9-a1c2-19653c36fc92" AND $dataNilai[$j]['kodeNilai'] == "B+"){
                  echo '<pre>'; print_r($paramReturn); exit;
               }
               */
            }
         }
      }
      return $paramReturn;
   }

   function SyncData(){
      $paramList = $this->GetProperty("DataProceed");
      //echo '<pre>'; print_r($param); exit;

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

      //update data terlebih dahulu
      for ($i=0; $i < count($paramList); $i++) {
         $p = array(
            $paramList[$i]['kode_bobot_nilai'],
            $paramList[$i]['id_sms'],
            $paramList[$i]['nilai_huruf'],
            $paramList[$i]['bobot_nilai_min'],
            $paramList[$i]['bobot_nilai_maks'],
            $paramList[$i]['nilai_indeks'],
            $paramList[$i]['tgl_mulai_efektif'],
            $paramList[$i]['tgl_akhir_efektif'],
            $paramList[$i]['id_sms'], //update
            $paramList[$i]['nilai_huruf'],
            $paramList[$i]['bobot_nilai_min'],
            $paramList[$i]['bobot_nilai_maks'],
            $paramList[$i]['nilai_indeks'],
            $paramList[$i]['tgl_mulai_efektif'],
            $paramList[$i]['tgl_akhir_efektif']
         );
         $proses = $this->ExecuteUpdateQuery($this->mSqlQueries['syncData'], $p);
         if($proses == FALSE) $prosesInsertUpdate = FALSE;
      }

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