Merge pull request #433 from openclassify/vedat

get Locations and Cities
This commit is contained in:
Fatih Alp 2020-03-19 17:56:14 +03:00 committed by GitHub
commit 545af807ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,34 @@
<?php namespace Visiosoft\LocationModule\City\Command;
use Visiosoft\LocationModule\City\CityModel;
class GetCities
{
/**
* @var $country
*/
protected $country;
/**
* GetProduct constructor.
* @param $country
*/
public function __construct($country)
{
$this->country = $country;
}
/**
* @param CityModel $groups
* @return |null
*/
public function handle(CityModel $groups)
{
if ($this->country) {
return $groups->where('parent_country_id', $this->country)->get();
}
return $groups::query()->get();
}
}

View File

@ -0,0 +1,12 @@
<?php namespace Visiosoft\LocationModule\Country\Command;
use Visiosoft\LocationModule\Country\CountryModel;
class GetCountries
{
public function handle(CountryModel $groups)
{
return $groups::query()->get();
}
}

View File

@ -1,7 +1,9 @@
<?php namespace Visiosoft\LocationModule;
use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
use Visiosoft\LocationModule\City\Command\GetCities;
use Visiosoft\LocationModule\City\Command\GetCity;
use Visiosoft\LocationModule\Country\Command\GetCountries;
use Visiosoft\LocationModule\Country\Command\GetCountry;
use Visiosoft\LocationModule\District\Command\GetDistrict;
use Visiosoft\LocationModule\Neighborhood\Command\GetNeighborhood;
@ -49,6 +51,17 @@ class LocationModulePlugin extends Plugin
return $ad;
}
),
new \Twig_SimpleFunction(
'getCities',
function ($country = null) {
if (!$ad = $this->dispatch(new GetCities($country))) {
return null;
}
return $ad;
}
),
new \Twig_SimpleFunction(
'getCountry',
function ($id) {
@ -60,6 +73,16 @@ class LocationModulePlugin extends Plugin
return $ad;
}
),
new \Twig_SimpleFunction(
'getCountries',
function () {
if (!$ad = $this->dispatch(new GetCountries())) {
return null;
}
return $ad;
}
),
new \Twig_SimpleFunction(
'getVillage',
function ($id) {