<?php namespace App\Http\Controllers;

		use Session;
		use Request;
		use DB;
		use CRUDBooster;

		class ApiListPropemperdaController extends \crocodicstudio\crudbooster\controllers\ApiController {

		    function __construct() {    
				$this->table       = "propemperda";        
				$this->permalink   = "list_propemperda";    
				$this->method_type = "get";    
		    }
		

		    public function hook_before(&$postdata) {
		        //This method will be execute before run the main process

		    }

		    public function hook_query(&$query) {
		        //This method is to customize the sql query

		    }

		    public function hook_after($postdata,&$result) {
		        if($result['api_status']==1){
		            foreach($result['data'] as $data){
    	                $data->timeline = DB::table('propemperda_timeline')->where('propemperda_id',$data->id)->orderBy('tanggal','desc')->get();
    	                $warna = ['#41516C','#FBCA3E','#E24A68','#1B5F8C'];
    	                $no=0;
    	                foreach($data->timeline as $timeline){
    	                    $timeline->warna = $warna[$no];
    	                    $no++;
    	                    if($no>=4){
    	                        $no=0;
    	                    }
    	                    $timeline->media = DB::table('propemperda_timeline_media')->where('propemperda_timeline_id',$timeline->id)->get();
    	                    foreach($timeline->media as $media){
    	                        $mainpath = str_replace("https://siapkk.banjarbarukota.go.id/","",$media->file);
    	                        $mainpath = str_replace("http://siapkk.banjarbarukota.go.id/","",$mainpath);
    	                        $media->file =  'https://siapkk.banjarbarukota.go.id/' .$mainpath;
    	                    }
    	                }
		            }
		        }

		    }

		}