mirror of
https://github.com/openclassify/openclassify.git
synced 2026-03-03 22:05:23 -06:00
location module refactor
This commit is contained in:
parent
5473dd7006
commit
9ab2c30e4d
@ -10,7 +10,7 @@ use Visiosoft\AdvsModule\Adv\Contract\AdvInterface;
|
||||
use Anomaly\Streams\Platform\View\ViewTemplate;
|
||||
use Visiosoft\CatsModule\Category\Contract\CategoryInterface;
|
||||
use Visiosoft\LocationModule\City\Contract\CityInterface;
|
||||
use Visiosoft\LocationModule\Country\Contract\CountryInterface;
|
||||
use Visiosoft\LocationModule\Country\Contract\CountryRepositoryInterface;
|
||||
|
||||
class AdvLoader {
|
||||
|
||||
@ -21,8 +21,8 @@ class AdvLoader {
|
||||
$this->template = $template;
|
||||
}
|
||||
|
||||
public function load(AdvInterface $adv, CategoryInterface $cats, CityInterface $city, CountryInterface $country) {
|
||||
public function load(AdvInterface $adv, CategoryInterface $cats, CityInterface $city, CountryRepositoryInterface $country) {
|
||||
$this->template->set('adv', $adv);
|
||||
$this->template->set('country', $country->getCountry($adv->country_id));
|
||||
$this->template->set('country', $country->find($adv->country_id));
|
||||
}
|
||||
}
|
||||
@ -31,11 +31,6 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
|
||||
$this->folderRepository = $folderRepository;
|
||||
}
|
||||
|
||||
public function findById($id)
|
||||
{
|
||||
return $this->model->orderBy('created_at', 'DESC')->where('advs_advs.id', $id)->first();
|
||||
}
|
||||
|
||||
public function searchAdvs(
|
||||
$type, $param = null, $customParameters = [],
|
||||
$limit = null, $category = null, $city = null, $paginate = true
|
||||
|
||||
@ -16,6 +16,6 @@ class AdvResolver {
|
||||
}
|
||||
|
||||
public function resolve() {
|
||||
return $this->adv->findById($this->route->parameter('id'));
|
||||
return $this->adv->find($this->route->parameter('id'));
|
||||
}
|
||||
}
|
||||
@ -27,7 +27,7 @@ class GetAd
|
||||
public function handle(AdvRepositoryInterface $groups)
|
||||
{
|
||||
if ($this->id) {
|
||||
return $groups->findById($this->id);
|
||||
return $groups->find($this->id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -4,8 +4,6 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
|
||||
|
||||
interface AdvRepositoryInterface extends EntryRepositoryInterface
|
||||
{
|
||||
public function findById($id);
|
||||
|
||||
public function searchAdvs(
|
||||
$type, $param = null, $customParameters = null,
|
||||
$limit = null, $category = null, $city = null, $paginate = true
|
||||
|
||||
@ -145,7 +145,7 @@ class AdvsController extends PublicController
|
||||
|
||||
$param = $this->requestHttp->toArray();
|
||||
|
||||
$countries = $this->country_repository->viewAll();
|
||||
$countries = $this->country_repository->newQuery()->get();
|
||||
|
||||
$isActiveDopings = $this->adv_model->is_enabled('dopings');
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ class OptionConfigurationTableColumns
|
||||
'value' => function (EntryModel $entry,
|
||||
AdvRepositoryInterface $advRepository) {
|
||||
|
||||
$adv = $advRepository->findById($entry->parent_adv_id);
|
||||
$adv = $advRepository->find($entry->parent_adv_id);
|
||||
return "<span><a href='" . route('adv_detail', [$entry->parent_adv_id]) . "'>$adv->name</a></span>";
|
||||
}
|
||||
],
|
||||
|
||||
@ -124,5 +124,5 @@
|
||||
|
||||
<script>
|
||||
var null_msg = "{{ trans('visiosoft.module.location::message.null_msg') }}!"
|
||||
var defaultCountry = {{ defaultCountry }}
|
||||
var defaultCountry = "{{ defaultCountry }}";
|
||||
</script>
|
||||
|
||||
@ -1,10 +1,12 @@
|
||||
<?php namespace Visiosoft\LocationModule\City;
|
||||
|
||||
use Anomaly\Streams\Platform\Entry\EntryCriteria;
|
||||
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||
|
||||
class CityCriteria extends EntryCriteria
|
||||
{
|
||||
public function getSubCities($city) {
|
||||
return $this->query->where('parent_country_id', $city)->get();
|
||||
public function getCitiesByCountryId($country_id) {
|
||||
$city_repository = app(CityRepositoryInterface::class);
|
||||
return $city_repository->getCitiesByCountryId($country_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,30 +2,8 @@
|
||||
|
||||
use Visiosoft\LocationModule\City\Contract\CityInterface;
|
||||
use Anomaly\Streams\Platform\Model\Location\LocationCitiesEntryModel;
|
||||
use Visiosoft\LocationModule\District\DistrictModel;
|
||||
|
||||
class CityModel extends LocationCitiesEntryModel implements CityInterface
|
||||
{
|
||||
public function getCities($id = null) {
|
||||
if($id != null)
|
||||
{
|
||||
return CityModel::query()->where('location_cities.id', $id)->first();
|
||||
}
|
||||
return CityModel::all();
|
||||
}
|
||||
|
||||
public function getSubCities($country) {
|
||||
return $this->query()->where('parent_country_id', $country)->orderBy('order','ASC')->get();
|
||||
}
|
||||
|
||||
public function deleteCitiesByCountry($id) {
|
||||
$districts = new DistrictModel();
|
||||
$city = $this->where('parent_country_id',$id);
|
||||
$city_id = $city->orderBy('id','DESC')->get();
|
||||
foreach ($city_id as $item)
|
||||
{
|
||||
$districts->deleteDistrictByCity($item->id);
|
||||
}
|
||||
return $city->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,11 +30,6 @@ class CityRepository extends EntryRepository implements CityRepositoryInterface
|
||||
$this->citiesEntryTranslationsModel = $citiesEntryTranslationsModel;
|
||||
}
|
||||
|
||||
public function findById($id)
|
||||
{
|
||||
return $this->model->orderBy('created_at', 'DESC')->where('location_cities.id', $id)->first();
|
||||
}
|
||||
|
||||
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc')
|
||||
{
|
||||
return $this->citiesEntryTranslationsModel->newQuery()
|
||||
@ -48,4 +43,11 @@ class CityRepository extends EntryRepository implements CityRepositoryInterface
|
||||
->orderBy($orderBy, $direction)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getCitiesByCountryId($country_id) {
|
||||
return $this->newQuery()
|
||||
->where('parent_country_id', $country_id)
|
||||
->orderBy('order','ASC')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,5 +4,5 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
|
||||
|
||||
interface CityInterface extends EntryInterface
|
||||
{
|
||||
public function getCities();
|
||||
|
||||
}
|
||||
|
||||
@ -4,7 +4,7 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
|
||||
|
||||
interface CityRepositoryInterface extends EntryRepositoryInterface
|
||||
{
|
||||
public function findById($id);
|
||||
|
||||
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc');
|
||||
|
||||
public function getCitiesByCountryId($country_id);
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
<?php namespace Visiosoft\LocationModule\City\Events;
|
||||
|
||||
class DeletedCities
|
||||
{
|
||||
private $cities;
|
||||
|
||||
public function __construct($cities)
|
||||
{
|
||||
$this->cities = $cities;
|
||||
}
|
||||
|
||||
public function getCities()
|
||||
{
|
||||
return $this->cities;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
<?php namespace Visiosoft\LocationModule\City\Listeners;
|
||||
|
||||
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||
use Visiosoft\LocationModule\City\Events\DeletedCities;
|
||||
|
||||
class DeletedCountry
|
||||
{
|
||||
public $cityRepository;
|
||||
|
||||
public function __construct(CityRepositoryInterface $cityRepository)
|
||||
{
|
||||
$this->cityRepository = $cityRepository;
|
||||
}
|
||||
|
||||
public function handle(\Visiosoft\LocationModule\Country\Events\DeletedCountry $event)
|
||||
{
|
||||
$country = $event->getCountry();
|
||||
|
||||
$query = $this->cityRepository->newQuery()
|
||||
->where('parent_country_id', $country->id);
|
||||
|
||||
if (count($cities = $query->get())) {
|
||||
$query->delete();
|
||||
|
||||
event(new DeletedCities($cities));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
<?php namespace Visiosoft\LocationModule\City\Table;
|
||||
|
||||
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
|
||||
use Visiosoft\LocationModule\City\Table\Handler\Delete;
|
||||
|
||||
class CityTableBuilder extends TableBuilder
|
||||
{
|
||||
@ -60,7 +61,9 @@ class CityTableBuilder extends TableBuilder
|
||||
* @var array|string
|
||||
*/
|
||||
protected $actions = [
|
||||
'delete'
|
||||
'delete' => [
|
||||
'handler' => Delete::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
<?php namespace Visiosoft\LocationModule\City\Table\Handler;
|
||||
|
||||
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
|
||||
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||
use Visiosoft\LocationModule\City\Events\DeletedCities;
|
||||
|
||||
|
||||
class Delete extends ActionHandler
|
||||
{
|
||||
public function handle(CityRepositoryInterface $repository, array $selected)
|
||||
{
|
||||
$query = $repository->newQuery()->whereIn('location_cities.id', $selected);
|
||||
|
||||
if ($count = count($cities = $query->get())) {
|
||||
$query->delete();
|
||||
|
||||
event(new DeletedCities($cities));
|
||||
}
|
||||
|
||||
if ($selected && $count > 0) {
|
||||
$this->messages->success(trans('streams::message.delete_success', compact('count')));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -4,5 +4,5 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
|
||||
|
||||
interface CountryInterface extends EntryInterface
|
||||
{
|
||||
public function getCountry($id);
|
||||
|
||||
}
|
||||
|
||||
@ -4,9 +4,5 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
|
||||
|
||||
interface CountryRepositoryInterface extends EntryRepositoryInterface
|
||||
{
|
||||
public function findById($id);
|
||||
|
||||
public function viewAll();
|
||||
|
||||
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc');
|
||||
}
|
||||
|
||||
@ -5,8 +5,5 @@ use Anomaly\Streams\Platform\Model\Location\LocationCountriesEntryModel;
|
||||
|
||||
class CountryModel extends LocationCountriesEntryModel implements CountryInterface
|
||||
{
|
||||
public function getCountry($id)
|
||||
{
|
||||
return CountryModel::query()->where('location_countries.id', $id)->first();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -32,14 +32,6 @@ class CountryRepository extends EntryRepository implements CountryRepositoryInte
|
||||
$this->model = $model;
|
||||
$this->countriesEntryTranslationsModel = $countriesEntryTranslationsModel;
|
||||
}
|
||||
public function findById($id)
|
||||
{
|
||||
return $this->model->orderBy('created_at', 'DESC')->where('location_countries.id', $id)->first();
|
||||
}
|
||||
|
||||
public function viewAll(){
|
||||
return $this->model->get();
|
||||
}
|
||||
|
||||
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc')
|
||||
{
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
<?php namespace Visiosoft\LocationModule\Country\Events;
|
||||
|
||||
class DeletedCountry
|
||||
{
|
||||
private $country;
|
||||
|
||||
public function __construct($country)
|
||||
{
|
||||
$this->country = $country;
|
||||
}
|
||||
|
||||
public function getCountry()
|
||||
{
|
||||
return $this->country;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
<?php namespace Visiosoft\LocationModule\Country\Table;
|
||||
|
||||
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
|
||||
use Visiosoft\LocationModule\Country\Table\Handler\Delete;
|
||||
|
||||
class CountryTableBuilder extends TableBuilder
|
||||
{
|
||||
@ -60,7 +61,9 @@ class CountryTableBuilder extends TableBuilder
|
||||
* @var array|string
|
||||
*/
|
||||
protected $actions = [
|
||||
'delete'
|
||||
'delete' => [
|
||||
'handler' => Delete::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,49 @@
|
||||
<?php namespace Visiosoft\LocationModule\Country\Table\Handler;
|
||||
|
||||
use Anomaly\Streams\Platform\Model\EloquentModel;
|
||||
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
|
||||
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
|
||||
use Visiosoft\LocationModule\Country\Events\DeletedCountry;
|
||||
|
||||
|
||||
class Delete extends ActionHandler
|
||||
{
|
||||
public function handle(TableBuilder $builder, array $selected)
|
||||
{
|
||||
$count = 0;
|
||||
|
||||
$model = $builder->getTableModel();
|
||||
|
||||
/* @var EloquentModel $entry */
|
||||
foreach ($selected as $id) {
|
||||
|
||||
$entry = $model->find($id);
|
||||
|
||||
$deletable = true;
|
||||
|
||||
if ($entry instanceof EloquentModel) {
|
||||
$deletable = $entry->isDeletable();
|
||||
}
|
||||
|
||||
if ($entry && $deletable && $entry->delete()) {
|
||||
$builder->fire('row_deleted', compact('builder', 'model', 'entry'));
|
||||
|
||||
event(new DeletedCountry($entry));
|
||||
|
||||
$count++;
|
||||
}
|
||||
}
|
||||
|
||||
if ($count) {
|
||||
$builder->fire('rows_deleted', compact('count', 'builder', 'model'));
|
||||
}
|
||||
|
||||
if ($selected && $count > 0) {
|
||||
$this->messages->success(trans('streams::message.delete_success', compact('count')));
|
||||
}
|
||||
|
||||
if ($selected && $count === 0) {
|
||||
$this->messages->warning(trans('streams::message.delete_success', compact('count')));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,4 +5,6 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
|
||||
interface DistrictRepositoryInterface extends EntryRepositoryInterface
|
||||
{
|
||||
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc');
|
||||
|
||||
public function getDistrictByCityId($city);
|
||||
}
|
||||
|
||||
@ -2,26 +2,8 @@
|
||||
|
||||
use Visiosoft\LocationModule\District\Contract\DistrictInterface;
|
||||
use Anomaly\Streams\Platform\Model\Location\LocationDistrictsEntryModel;
|
||||
use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel;
|
||||
|
||||
class DistrictModel extends LocationDistrictsEntryModel implements DistrictInterface
|
||||
{
|
||||
public function getDistricts() {
|
||||
return DistrictModel::all();
|
||||
}
|
||||
|
||||
public function getSubDistricts($city) {
|
||||
return $this->query()->where('parent_city_id', $city)->orderBy('order','ASC')->get();
|
||||
}
|
||||
|
||||
public function deleteDistrictByCity($id) {
|
||||
$neighborhood = new NeighborhoodModel();
|
||||
$districts = $this->where('parent_city_id',$id);
|
||||
$districts_id = $districts->orderBy('id','DESC')->get();
|
||||
foreach ($districts_id as $item)
|
||||
{
|
||||
$neighborhood->deleteNeighborhoodByDistrict($item->id);
|
||||
}
|
||||
return $districts->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,4 +46,11 @@ class DistrictRepository extends EntryRepository implements DistrictRepositoryIn
|
||||
->orderBy($orderBy, $direction)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getDistrictByCityId($city) {
|
||||
return $this->newQuery()
|
||||
->where('parent_city_id', $city)
|
||||
->orderBy('order','ASC')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
<?php namespace Visiosoft\LocationModule\District\Events;
|
||||
|
||||
class DeletedDistricts
|
||||
{
|
||||
private $districts;
|
||||
|
||||
public function __construct($districts)
|
||||
{
|
||||
$this->districts = $districts;
|
||||
}
|
||||
|
||||
public function getDistricts()
|
||||
{
|
||||
return $this->districts;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
<?php namespace Visiosoft\LocationModule\District\Listeners;
|
||||
|
||||
use Visiosoft\LocationModule\District\Contract\DistrictRepositoryInterface;
|
||||
use Visiosoft\LocationModule\District\Events\DeletedDistricts;
|
||||
|
||||
class DeletedCities
|
||||
{
|
||||
public $districtRepository;
|
||||
|
||||
public function __construct(DistrictRepositoryInterface $districtRepository)
|
||||
{
|
||||
$this->districtRepository = $districtRepository;
|
||||
}
|
||||
|
||||
public function handle(\Visiosoft\LocationModule\City\Events\DeletedCities $event)
|
||||
{
|
||||
$cities = $event->getCities();
|
||||
|
||||
$cities = $cities->pluck('id')->all();
|
||||
|
||||
$query = $this->districtRepository->newQuery()
|
||||
->whereIn('parent_city_id', $cities);
|
||||
|
||||
if (count($districts = $query->get())) {
|
||||
$query->delete();
|
||||
|
||||
event(new DeletedDistricts($districts));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
<?php namespace Visiosoft\LocationModule\District\Table;
|
||||
|
||||
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
|
||||
use Visiosoft\LocationModule\District\Table\Handler\Delete;
|
||||
|
||||
class DistrictTableBuilder extends TableBuilder
|
||||
{
|
||||
@ -60,7 +61,9 @@ class DistrictTableBuilder extends TableBuilder
|
||||
* @var array|string
|
||||
*/
|
||||
protected $actions = [
|
||||
'delete'
|
||||
'delete' => [
|
||||
'handler' => Delete::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
<?php namespace Visiosoft\LocationModule\District\Table\Handler;
|
||||
|
||||
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
|
||||
use Visiosoft\LocationModule\District\Contract\DistrictRepositoryInterface;
|
||||
use Visiosoft\LocationModule\District\Events\DeletedDistricts;
|
||||
|
||||
|
||||
class Delete extends ActionHandler
|
||||
{
|
||||
public function handle(DistrictRepositoryInterface $repository, array $selected)
|
||||
{
|
||||
$query = $repository->newQuery()->whereIn('location_districts.id', $selected);
|
||||
|
||||
if ($count = count($cities = $query->get())) {
|
||||
$query->delete();
|
||||
|
||||
event(new DeletedDistricts($cities));
|
||||
}
|
||||
|
||||
if ($selected && $count > 0) {
|
||||
$this->messages->success(trans('streams::message.delete_success', compact('count')));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,28 +1,21 @@
|
||||
<?php namespace Visiosoft\LocationModule\Http\Controller\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Visiosoft\LocationModule\City\CityModel;
|
||||
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||
use Visiosoft\LocationModule\City\Form\CityFormBuilder;
|
||||
use Visiosoft\LocationModule\City\Table\CityTableBuilder;
|
||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
use Visiosoft\LocationModule\District\DistrictModel;
|
||||
|
||||
class CitiesController extends AdminController
|
||||
{
|
||||
public function index(CityTableBuilder $table, Request $request)
|
||||
{
|
||||
if($this->request->action == "delete") {
|
||||
$disticts = new DistrictModel();
|
||||
foreach ($this->request->id as $item)
|
||||
{
|
||||
$disticts->deleteDistrictByCity($item);
|
||||
}
|
||||
}
|
||||
$cities = new CityModel();
|
||||
$cities = app(CityRepositoryInterface::class);
|
||||
|
||||
if(!isset($request->country) || $request->country==""){
|
||||
return $table->render();
|
||||
} else {
|
||||
$cities = $cities->getSubCities($request->country);
|
||||
$cities = $cities->getCitiesByCountryId($request->country);
|
||||
if (count($cities) == 0) {
|
||||
$this->messages->error('Selected country has no related city.');
|
||||
return redirect('/admin/location/countries');
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
<?php namespace Visiosoft\LocationModule\Http\Controller\Admin;
|
||||
|
||||
use Visiosoft\LocationModule\City\CityModel;
|
||||
use Visiosoft\LocationModule\Country\Form\CountryFormBuilder;
|
||||
use Visiosoft\LocationModule\Country\Table\CountryTableBuilder;
|
||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
@ -16,13 +15,6 @@ class CountriesController extends AdminController
|
||||
*/
|
||||
public function index(CountryTableBuilder $table)
|
||||
{
|
||||
if($this->request->action == "delete") {
|
||||
$city = new CityModel();
|
||||
foreach ($this->request->id as $item)
|
||||
{
|
||||
$city->deleteCitiesByCountry($item);
|
||||
}
|
||||
}
|
||||
return $table->render();
|
||||
}
|
||||
|
||||
|
||||
@ -1,28 +1,20 @@
|
||||
<?php namespace Visiosoft\LocationModule\Http\Controller\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Visiosoft\LocationModule\District\DistrictModel;
|
||||
use Visiosoft\LocationModule\District\Contract\DistrictRepositoryInterface;
|
||||
use Visiosoft\LocationModule\District\Form\DistrictFormBuilder;
|
||||
use Visiosoft\LocationModule\District\Table\DistrictTableBuilder;
|
||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel;
|
||||
|
||||
class DistrictsController extends AdminController
|
||||
{
|
||||
public function index(DistrictTableBuilder $table, Request $request)
|
||||
{
|
||||
if($this->request->action == "delete") {
|
||||
$neighborhoods = new NeighborhoodModel();
|
||||
foreach ($this->request->id as $item)
|
||||
{
|
||||
$neighborhoods->deleteNeighborhoodByDistrict($item);
|
||||
}
|
||||
}
|
||||
$districts = new DistrictModel();
|
||||
$districts = app(DistrictRepositoryInterface::class);
|
||||
if(!isset($request->city) || $request->city==""){
|
||||
return $table->render();
|
||||
}else{
|
||||
$districts = $districts->getSubDistricts($request->city);
|
||||
$districts = $districts->getDistrictByCityId($request->city);
|
||||
if (count($districts) == 0) {
|
||||
$this->messages->error('Selected city has no related district.');
|
||||
return redirect('/admin/location/cities');
|
||||
|
||||
@ -1,28 +1,20 @@
|
||||
<?php namespace Visiosoft\LocationModule\Http\Controller\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Visiosoft\LocationModule\Neighborhood\Contract\NeighborhoodRepositoryInterface;
|
||||
use Visiosoft\LocationModule\Neighborhood\Form\NeighborhoodFormBuilder;
|
||||
use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel;
|
||||
use Visiosoft\LocationModule\Neighborhood\Table\NeighborhoodTableBuilder;
|
||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
use Visiosoft\LocationModule\Village\VillageModel;
|
||||
|
||||
class NeighborhoodsController extends AdminController
|
||||
{
|
||||
public function index(NeighborhoodTableBuilder $table, Request $request)
|
||||
{
|
||||
if($this->request->action == "delete") {
|
||||
$village = new VillageModel();
|
||||
foreach ($this->request->id as $item)
|
||||
{
|
||||
$village->deleteVillageByNeighborhood($item);
|
||||
}
|
||||
}
|
||||
$neighborhoods = new NeighborhoodModel();
|
||||
$neighborhoods = app(NeighborhoodRepositoryInterface::class);
|
||||
if(!isset($request->district) || $request->district==""){
|
||||
return $table->render();
|
||||
}else{
|
||||
$neighborhoods = $neighborhoods->getSubNeighborhoods($request->district);
|
||||
$neighborhoods = $neighborhoods->getNeighborhoodsByDistrictId($request->district);
|
||||
if (count($neighborhoods) == 0) {
|
||||
$this->messages->error('Selected district has no related neighborhood.');
|
||||
return redirect('/admin/location/districts');
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
<?php namespace Visiosoft\LocationModule\Http\Controller\Admin;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface;
|
||||
use Visiosoft\LocationModule\Village\Form\VillageFormBuilder;
|
||||
use Visiosoft\LocationModule\Village\Table\VillageTableBuilder;
|
||||
use Anomaly\Streams\Platform\Http\Controller\AdminController;
|
||||
use Visiosoft\LocationModule\Village\VillageModel;
|
||||
|
||||
class VillageController extends AdminController
|
||||
{
|
||||
public function index(VillageTableBuilder $table, Request $request)
|
||||
{
|
||||
$villages = new VillageModel();
|
||||
$villages = app(VillageRepositoryInterface::class);
|
||||
|
||||
if(!isset($request->neighborhood) || $request->neighborhood==""){
|
||||
return $table->render();
|
||||
}else{
|
||||
$villages = $villages->getSubVillages($request->neighborhood);
|
||||
$villages = $villages->getVillagesByNeighborhoodId($request->neighborhood);
|
||||
if (count($villages) == 0) {
|
||||
$this->messages->error('Selected neighborhood has no related village.');
|
||||
return back();
|
||||
|
||||
@ -8,10 +8,14 @@ use Anomaly\Streams\Platform\Model\Location\LocationVillageEntryModel;
|
||||
use Visiosoft\LocationModule\City\CityModel;
|
||||
use Visiosoft\LocationModule\City\CityRepository;
|
||||
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
|
||||
use Visiosoft\LocationModule\City\Events\DeletedCities;
|
||||
use Visiosoft\LocationModule\Country\Events\DeletedCountry;
|
||||
use Visiosoft\LocationModule\District\Contract\DistrictRepositoryInterface;
|
||||
use Visiosoft\LocationModule\District\DistrictModel;
|
||||
use Visiosoft\LocationModule\District\DistrictRepository;
|
||||
use Visiosoft\LocationModule\District\Events\DeletedDistricts;
|
||||
use Visiosoft\LocationModule\Neighborhood\Contract\NeighborhoodRepositoryInterface;
|
||||
use Visiosoft\LocationModule\Neighborhood\Events\DeletedNeighborhoods;
|
||||
use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel;
|
||||
use Visiosoft\LocationModule\Neighborhood\NeighborhoodRepository;
|
||||
use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface;
|
||||
@ -85,4 +89,19 @@ class LocationModuleServiceProvider extends AddonServiceProvider
|
||||
VillageRepositoryInterface::class => VillageRepository::class,
|
||||
CountryRepositoryInterface::class => CountryRepository::class,
|
||||
];
|
||||
|
||||
protected $listeners = [
|
||||
DeletedCountry::class => [
|
||||
\Visiosoft\LocationModule\City\Listeners\DeletedCountry::class,
|
||||
],
|
||||
DeletedCities::class => [
|
||||
\Visiosoft\LocationModule\District\Listeners\DeletedCities::class,
|
||||
],
|
||||
DeletedDistricts::class => [
|
||||
\Visiosoft\LocationModule\Neighborhood\Listeners\DeletedDistricts::class,
|
||||
],
|
||||
DeletedNeighborhoods::class => [
|
||||
\Visiosoft\LocationModule\Village\Listeners\DeletedNeighborhoods::class
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@ -5,4 +5,6 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
|
||||
interface NeighborhoodRepositoryInterface extends EntryRepositoryInterface
|
||||
{
|
||||
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc');
|
||||
|
||||
public function getNeighborhoodsByDistrictId($district);
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
<?php namespace Visiosoft\LocationModule\Neighborhood\Events;
|
||||
|
||||
class DeletedNeighborhoods
|
||||
{
|
||||
private $neighborhood;
|
||||
|
||||
public function __construct($neighborhood)
|
||||
{
|
||||
$this->neighborhood = $neighborhood;
|
||||
}
|
||||
|
||||
public function getNeighborhoods()
|
||||
{
|
||||
return $this->neighborhood;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
<?php namespace Visiosoft\LocationModule\Neighborhood\Listeners;
|
||||
|
||||
|
||||
use Visiosoft\LocationModule\Neighborhood\Contract\NeighborhoodRepositoryInterface;
|
||||
use Visiosoft\LocationModule\Neighborhood\Events\DeletedNeighborhoods;
|
||||
|
||||
class DeletedDistricts
|
||||
{
|
||||
public $neighborhoodRepository;
|
||||
|
||||
public function __construct(NeighborhoodRepositoryInterface $neighborhoodRepository)
|
||||
{
|
||||
$this->neighborhoodRepository = $neighborhoodRepository;
|
||||
}
|
||||
|
||||
public function handle(\Visiosoft\LocationModule\District\Events\DeletedDistricts $event)
|
||||
{
|
||||
$districts = $event->getDistricts();
|
||||
|
||||
$districts = $districts->pluck('id')->all();
|
||||
|
||||
$query = $this->neighborhoodRepository->newQuery()
|
||||
->whereIn('parent_district_id', $districts);
|
||||
|
||||
if (count($neighborhoods = $query->get())) {
|
||||
$query->delete();
|
||||
|
||||
event(new DeletedNeighborhoods($neighborhoods));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,26 +2,8 @@
|
||||
|
||||
use Visiosoft\LocationModule\Neighborhood\Contract\NeighborhoodInterface;
|
||||
use Anomaly\Streams\Platform\Model\Location\LocationNeighborhoodsEntryModel;
|
||||
use Visiosoft\LocationModule\Village\VillageModel;
|
||||
|
||||
class NeighborhoodModel extends LocationNeighborhoodsEntryModel implements NeighborhoodInterface
|
||||
{
|
||||
public function getNeighborhoods() {
|
||||
return NeighborhoodModel::all();
|
||||
}
|
||||
|
||||
public function getSubNeighborhoods($district) {
|
||||
return $this->query()->where('parent_district_id', $district)->orderBy('order','ASC')->get();
|
||||
}
|
||||
|
||||
public function deleteNeighborhoodByDistrict($id) {
|
||||
$village = new VillageModel();
|
||||
$neighborhood = $this->where('parent_district_id',$id);
|
||||
$neighborhoods_id = $neighborhood->orderBy('id','DESC')->get();
|
||||
foreach ($neighborhoods_id as $item)
|
||||
{
|
||||
$village->deleteVillageByNeighborhood($item->id);
|
||||
}
|
||||
return $neighborhood->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,4 +46,12 @@ class NeighborhoodRepository extends EntryRepository implements NeighborhoodRepo
|
||||
->orderBy($orderBy, $direction)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getNeighborhoodsByDistrictId($district)
|
||||
{
|
||||
return $this->newQuery()
|
||||
->where('parent_district_id', $district)
|
||||
->orderBy('order', 'ASC')
|
||||
->get();
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
<?php namespace Visiosoft\LocationModule\Neighborhood\Table\Handler;
|
||||
|
||||
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
|
||||
use Visiosoft\LocationModule\Neighborhood\Contract\NeighborhoodRepositoryInterface;
|
||||
use Visiosoft\LocationModule\Neighborhood\Events\DeletedNeighborhoods;
|
||||
|
||||
|
||||
class Delete extends ActionHandler
|
||||
{
|
||||
public function handle(NeighborhoodRepositoryInterface $repository, array $selected)
|
||||
{
|
||||
$query = $repository->newQuery()->whereIn('location_neighborhoods.id', $selected);
|
||||
|
||||
if ($count = count($cities = $query->get())) {
|
||||
$query->delete();
|
||||
|
||||
event(new DeletedNeighborhoods($cities));
|
||||
}
|
||||
|
||||
if ($selected && $count > 0) {
|
||||
$this->messages->success(trans('streams::message.delete_success', compact('count')));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,6 +1,7 @@
|
||||
<?php namespace Visiosoft\LocationModule\Neighborhood\Table;
|
||||
|
||||
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
|
||||
use Visiosoft\LocationModule\Neighborhood\Table\Handler\Delete;
|
||||
|
||||
class NeighborhoodTableBuilder extends TableBuilder
|
||||
{
|
||||
@ -60,7 +61,9 @@ class NeighborhoodTableBuilder extends TableBuilder
|
||||
* @var array|string
|
||||
*/
|
||||
protected $actions = [
|
||||
'delete'
|
||||
'delete' => [
|
||||
'handler' => Delete::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -5,4 +5,6 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
|
||||
interface VillageRepositoryInterface extends EntryRepositoryInterface
|
||||
{
|
||||
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc');
|
||||
|
||||
public function getVillagesByNeighborhoodId($neighborhood);
|
||||
}
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
<?php namespace Visiosoft\LocationModule\Village\Listeners;
|
||||
|
||||
use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface;
|
||||
|
||||
class DeletedNeighborhoods
|
||||
{
|
||||
public $villageRepository;
|
||||
|
||||
public function __construct(VillageRepositoryInterface $villageRepository)
|
||||
{
|
||||
$this->villageRepository = $villageRepository;
|
||||
}
|
||||
|
||||
public function handle(\Visiosoft\LocationModule\Neighborhood\Events\DeletedNeighborhoods $event)
|
||||
{
|
||||
$neighborhoods = $event->getNeighborhoods();
|
||||
|
||||
$neighborhoods = $neighborhoods->pluck('id')->all();
|
||||
|
||||
$query = $this->villageRepository->newQuery()
|
||||
->whereIn('parent_neighborhood_id', $neighborhoods);
|
||||
|
||||
if (count($villages = $query->get())) {
|
||||
$query->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -5,15 +5,5 @@ use Anomaly\Streams\Platform\Model\Location\LocationVillageEntryModel;
|
||||
|
||||
class VillageModel extends LocationVillageEntryModel implements VillageInterface
|
||||
{
|
||||
public function getVillages() {
|
||||
return VillageModel::all();
|
||||
}
|
||||
|
||||
public function getSubVillages($neighborhood) {
|
||||
return $this->query()->where('parent_neighborhood_id', $neighborhood)->orderBy('order','ASC')->get();
|
||||
}
|
||||
|
||||
public function deleteVillageByNeighborhood($id) {
|
||||
$this->where('parent_neighborhood_id',$id)->orderBy('id','DESC')->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,4 +46,9 @@ class VillageRepository extends EntryRepository implements VillageRepositoryInte
|
||||
->orderBy($orderBy, $direction)
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getVillagesByNeighborhoodId($neighborhood)
|
||||
{
|
||||
return $this->newQuery()->where('parent_neighborhood_id', $neighborhood)->orderBy('order','ASC')->get();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user