<?php
/*
Author : Nikolius
Email : n1colius.lau@gmail.com
Date : 10-Jul-2015 09:59 AM
*/
require_once $cfg->mValue['docroot'] . "module/sia_setting/business/sia_setting.class.php";
class Agama extends SiaSetting {

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

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

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

      //update data terlebih dahulu
      for ($i=0; $i < count($dataList); $i++) {
         $p = array(
            $dataList[$i]['id_agama'],
            $dataList[$i]['nm_agama'],
            $dataList[$i]['nm_agama']
         );
         $proses = $this->ExecuteUpdateQuery($this->mSqlQueries['syncDataAgama'], $p);
         if($proses == FALSE) $prosesInsertUpdate = FALSE;
      }

      //cari datanya di tabel agama_ref dan update gt_id nya
      for ($i=0; $i < count($dataList); $i++) {
         $dataAgamaId = $this->GetAllDataAsArray($this->mSqlQueries['getDataAgamaId'], array($dataList[$i]['nm_agama']));
         $gt_id = $dataAgamaId[0]['agmrId'];

         $proses = $this->ExecuteUpdateQuery($this->mSqlQueries['updateFeederAgamaGtId'], array($gt_id,$dataList[$i]['id_agama']));
         if($proses == FALSE) $prosesInsertUpdate = FALSE;
      }

      $this->CompleteTransaction($prosesInsertUpdate);

      return $prosesInsertUpdate;
   }
}

?>