<?php
class ModelToolEntegrasyonApi extends Model {
    public function addEntegrasyonApi($code,$api) {

        $query=$this->db->query("select * from database_entegrasyon de left join `entegrasyon` e ON(de.entegrasyon_id=e.entegrasyon_id)  where e.code='".$code."' and de.database_id='".$this->user->getDbId()."'  ");
        if(!$query->num_rows){
            $this->db->query("INSERT INTO database_entegrasyon SET database_id='".$this->user->getDbId()."', api='".serialize($api)."',status=1, entegrasyon_id=(select entegrasyon_id from entegrasyon where code='".$code."') ");
        }else {

            $this->db->query("UPDATE database_entegrasyon SET api='".serialize($api)."' where  entegrasyon_id=(select entegrasyon_id from entegrasyon where code='".$code."') and database_id='".$this->user->getDbId()."'  ");

        }

        return true;

    }

    public function getEntegrasyonApi($code,$db_id,$entegrasyon_group_id=1)
    {

        try {
            $query=$this->db->query("select * from database_entegrasyon de left join `entegrasyon` e ON(de.entegrasyon_id=e.entegrasyon_id)  where e.code='".$code."' and de.database_id='".$db_id."'  and entegrasyon_group_id='".$entegrasyon_group_id."' ");

            return $query->row;
        }catch (Exception $exception){

            echo  $exception->getMessage();
        }

    }

    public function getEntegrasyonApiInfo($code,$db_id)
    {


        $api=$this->getEntegrasyonApi($code,$db_id);
        return unserialize($api['api']);
    }






}