Referensi.php 2.88 KB
<?php

/**
 * @Author: irul
 * @Date:   2019-09-20 23:05:52
 * @Last Modified by:   irul
 * @Last Modified time: 2019-10-01 23:43:20
 */

namespace Integrasi\Reklame\Base;

use \Illuminate\Database\Eloquent\ModelNotFoundException;

/**
 * Daftar method (global) yang digunakan untuk semua daerah.
 * Pengelompokan berdasarkan data pendukung.
 */
class Referensi extends AbstractClass
{
	public static function getKecamatan()
	{
		// return Models\Kecamatan::all()->toJson();
		// $data = Models\Kecamatan::where('enabled', 1)->get();
		// $data = Models\Kecamatan::whereEnabled(1)->get();
		$data = call_user_func(self::getParentNamespace() . '\Models\Kecamatan::whereEnabled', 1)
			->get();
		if (!count($data)) {
			throw new ModelNotFoundException(MSG_NOT_FOUND);
		}
		return $data;
	}

	public static function getKecamatanById($id)
	{
		// $data = Models\Kecamatan::whereEnabled(1)->find($id);
		$data = call_user_func(self::getParentNamespace() . '\Models\Kecamatan::whereEnabled', 1)
			->find($id);
		if (!$data) {
			throw new ModelNotFoundException(MSG_NOT_FOUND);
		}
		return $data;
	}

	public static function getKelurahan()
	{
		// $data = Models\Kelurahan::whereEnabled(1)->get();
		$data = call_user_func(self::getParentNamespace() . '\Models\Kelurahan::whereEnabled', 1)
			->get();
		if (!count($data)) {
			throw new ModelNotFoundException(MSG_NOT_FOUND);
		}
		return $data;
	}

	public static function getKelurahanById($id)
	{
		// $data = Models\Kelurahan::whereEnabled(1)->find($id);
		$data = call_user_func(self::getParentNamespace() . '\Models\Kelurahan::whereEnabled', 1)
			->find($id);
		if (!$data) {
			throw new ModelNotFoundException(MSG_NOT_FOUND);
		}
		return $data;
	}

	public static function getKelurahanByKecamatanId($kecamatan_id)
	{
		// $data = Models\Kelurahan::whereRaw('enabled = 1 and kecamatan_id = ?', array($kecamatan_id))->get();
		// $data = Models\Kelurahan::whereEnabled(1)->whereKecamatan_id($kecamatan_id)->get();
		$data = call_user_func(self::getParentNamespace() . '\Models\Kelurahan::whereEnabled', 1)
			->whereKecamatan_id($kecamatan_id)
			->get();
		if (!count($data)) {
			throw new ModelNotFoundException(MSG_NOT_FOUND);
		}
		return $data;
	}

	public static function getPajakReklame()
	{
		// $data = Models\Pajak::whereEnabled(1)->whereUsahaId(DEFAULT_USAHA_ID)->get();
		$data = call_user_func(self::getParentNamespace() . '\Models\Pajak::whereEnabled', 1)
			->whereUsahaId(DEFAULT_USAHA_ID)
			->get();
		if (!count($data)) {
			throw new ModelNotFoundException(MSG_NOT_FOUND);
		}
		return $data;
	}

	public static function getPajakReklameById($id)
	{
		// $data = Models\Pajak::whereEnabled(1)->whereUsahaId(DEFAULT_USAHA_ID)->find($id);
		$data = call_user_func(self::getParentNamespace() . '\Models\Pajak::whereEnabled', 1)
			->whereUsahaId(DEFAULT_USAHA_ID)
			->find($id);
		if (!$data) {
			throw new ModelNotFoundException(MSG_NOT_FOUND);
		}
		return $data;
	}
}