<?php namespace App\Http\Controllers;

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

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

		    function __construct() {    
				$this->table       = "grup";        
				$this->permalink   = "grup_detail";    
				$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) {
		        //This method will be execute after run the main process
		         $eksis = DB::table('member')
		        ->where('username',$postdata['username'])
		        ->where('grup_id',$postdata['id'])
		        ->first();
		        
		        $anggota = DB::table('member')
		        ->where('member.grup_id',$postdata['id'])
		        ->join('cms_users','cms_users.nik','member.username')
		        ->get();
		        
		        $result['anggota'] = $anggota;
		        
		        if($eksis){
		            $result['eksis'] = 1;
		            $result['admin'] = $eksis->admin;
		        }else{
		            $result['eksis'] = 0;
		        }
		        
		        if($result['jenis_grup']==1){
		            $result['jenis_grup'] = 'terbuka';
		        }else{
		            $result['jenis_grup'] = 'tertutup';
		        }
		    }

		}