diff --git a/addons/default/visiosoft/location-module/src/City/CityRepository.php b/addons/default/visiosoft/location-module/src/City/CityRepository.php index 02350097f..9a1fd8147 100644 --- a/addons/default/visiosoft/location-module/src/City/CityRepository.php +++ b/addons/default/visiosoft/location-module/src/City/CityRepository.php @@ -1,5 +1,6 @@ model = $model; + $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) + { + return $this->citiesEntryTranslationsModel->newQuery() + ->select('entry_id as id', 'name') + ->whereIn('locale', [ + Request()->session()->get('_locale'), + setting_value('streams::default_locale'), + 'en' + ]) + ->whereIn('entry_id', $entryIDs) + ->orderBy($orderBy) + ->get(); + } } diff --git a/addons/default/visiosoft/location-module/src/City/Contract/CityRepositoryInterface.php b/addons/default/visiosoft/location-module/src/City/Contract/CityRepositoryInterface.php index 78f8e25c6..7b4f3520d 100644 --- a/addons/default/visiosoft/location-module/src/City/Contract/CityRepositoryInterface.php +++ b/addons/default/visiosoft/location-module/src/City/Contract/CityRepositoryInterface.php @@ -5,4 +5,6 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface; interface CityRepositoryInterface extends EntryRepositoryInterface { public function findById($id); + + public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy); } diff --git a/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php b/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php index 89f057d97..ceedd10b7 100644 --- a/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php +++ b/addons/default/visiosoft/location-module/src/Http/Controller/AjaxController.php @@ -3,6 +3,7 @@ use Anomaly\Streams\Platform\Http\Controller\PublicController; use Anomaly\Streams\Platform\Model\Location\LocationCitiesEntryTranslationsModel; use Visiosoft\LocationModule\City\CityModel; +use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface; use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\LocationModule\District\DistrictModel; use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel; @@ -11,56 +12,34 @@ use Illuminate\Support\Str; class AjaxController extends PublicController { - /** - * @var CountryModel - */ private $country_model; - /** - * @var CityModel - */ private $city_model; - /** - * @var DistrictModel - */ private $district_model; - /** - * @var NeighborhoodModel - */ private $neighborhood_model; - /** - * @var VillageModel - */ private $village_model; - /** - * @var LocationCitiesEntryTranslationsModel - */ private $citiesEntryTranslationsModel; + private $cityRepository; - /** - * AjaxController constructor. - * @param CountryModel $countryModel - */ public function __construct( CountryModel $countryModel, CityModel $cityModel, DistrictModel $districtModel, NeighborhoodModel $neighborhoodModel, VillageModel $villageModel, - LocationCitiesEntryTranslationsModel $citiesEntryTranslationsModel + LocationCitiesEntryTranslationsModel $citiesEntryTranslationsModel, + CityRepositoryInterface $cityRepository ) { + parent::__construct(); $this->country_model = $countryModel; $this->city_model = $cityModel; $this->district_model = $districtModel; $this->neighborhood_model = $neighborhoodModel; $this->village_model = $villageModel; - parent::__construct(); $this->citiesEntryTranslationsModel = $citiesEntryTranslationsModel; + $this->cityRepository = $cityRepository; } - /** - * @return mixed - */ public function getCountries() { if ($this->request->id) @@ -71,9 +50,6 @@ class AjaxController extends PublicController } } - /** - * @return mixed - */ public function getCities() { if ($this->request->id) { @@ -81,16 +57,10 @@ class AjaxController extends PublicController $query = $this->city_model->whereIn('parent_country_id', $id); if (request()->order_by && $this->city_model->isTranslatedAttribute(request()->order_by)) { - return $this->citiesEntryTranslationsModel->newQuery() - ->select('entry_id as id', 'name') - ->whereIn('locale', [ - Request()->session()->get('_locale'), - setting_value('streams::default_locale'), - 'en' - ]) - ->whereIn('entry_id', $query->pluck('id')->all()) - ->orderBy(request()->order_by) - ->get(); + return $this->cityRepository->getByEntryIDsAndOrderByTransCol( + $query->pluck('id')->all(), + request()->order_by + ); } elseif ($orderBy = request()->order_by) { return $this->queryOrder($query, $orderBy); } @@ -99,9 +69,6 @@ class AjaxController extends PublicController } } - /** - * @return mixed - */ public function getDistricts() { if ($this->request->id) { @@ -113,9 +80,6 @@ class AjaxController extends PublicController } } - /** - * @return mixed - */ public function getNeighborhoods() { if ($this->request->id) { @@ -127,9 +91,6 @@ class AjaxController extends PublicController } } - /** - * @return mixed - */ public function getVillage() { if ($this->request->id) { @@ -141,9 +102,6 @@ class AjaxController extends PublicController } } - /** - * @return mixed - */ public function getCity() { if ($this->request->name) {