Merge pull request #111 from openclassify/vedat1

Vedat1
This commit is contained in:
Fatih Alp 2019-10-18 11:44:28 +03:00 committed by GitHub
commit dce9c2585d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 18 deletions

View File

@ -14,32 +14,34 @@ class AjaxController extends PublicController
public function locations(Request $request)
{
$datas = [];
if($request->level == 1){
if ($request->level == 1) {
$datas = CityModel::where('parent_country_id', $request->cat)->get();
}else if($request->level == 2){
} else if ($request->level == 2) {
$datas = DistrictModel::where('parent_city_id', $request->cat)->get();
}else if($request->level == 3){
} else if ($request->level == 3) {
$datas = NeighborhoodModel::where('parent_district_id', $request->cat)->get();
}else if($request->level == 4){
} else if ($request->level == 4) {
$datas = VillageModel::where('parent_neighborhood_id', $request->cat)->get();
}
return response()->json($datas);
}
public function categories(Request $request)
{
$datas = [];
if($request->level == 0){
if ($request->level == 0) {
$datas = CategoryModel::whereNull('parent_category_id')->get();
}else{
} else {
$datas = CategoryModel::where('parent_category_id', $request->cat)->get();
}
return response()->json($datas);
}
public function keySearch(Request $request)
{
$datas = [];
$catModel = new CategoryModel();
$datas['category'] = $catModel->searchKeyword($request->q);
$datas['category'] = $catModel->searchKeyword($request->q, $request->selected);
return response()->json($datas);
}

View File

@ -12,7 +12,7 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
return CategoryModel::query()->where('cats_category.id', $id)->first();
}
public function getParentCats($id, $type = null, $subCatDeepCount = 5)
public function getParentCats($id, $type = null, $subCatDeepCount = 7)
{
$cat = $this->getCat($id);
$catNames = array();
@ -21,9 +21,9 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
$cat_ids[] = $cat->id;
$subCat = $cat->parent_category_id;
if ($subCat != null) {
for ($i = 0; $i < $subCatDeepCount; $i++) {
for ($i = 0; $i < 7; $i++) {
$parCat = $this->getCat($subCat);
if ($parCat == null) {
if ($parCat->parent_category_id == "") {
break;
}
$catNames[] = $parCat->name;
@ -77,16 +77,26 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
return true;
}
public function searchKeyword($keyword)
public function searchKeyword($keyword, $selected = null)
{
$data = [];
$cats = DB::table('cats_category_translations')
->select('cats_category.id', 'cats_category_translations.name', 'cats_category.parent_category_id')
->where('name', 'like', $keyword . '%')
->join('cats_category', 'cats_category_translations.entry_id', '=', 'cats_category.id')
->orderBy('cats_category_translations.id', 'DESC')
->get();
$cats = DB::table('cats_category');
if ($selected != null) {
if (strpos($selected, "-") !== false) {
$selected = explode('-', $selected);
$cats = $cats->whereNotIn('cats_category.id', $selected);
} else {
$cats = $cats->where('cats_category.id', '!=', $selected);
}
}
$cats = $cats->where('name', 'like', $keyword . '%');
$cats = $cats->leftJoin('cats_category_translations', function ($join) {
$join->on('cats_category.id', '=', 'cats_category_translations.entry_id');
$join->where('cats_category_translations.locale', '=', Request()->session()->get('_locale'));
});
$cats = $cats->orderBy('cats_category_translations.id', 'DESC')
->get();
foreach ($cats as $cat) {
$link = '';
$parents = $this->getParentCats($cat->id, null, 2);
@ -101,6 +111,7 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
$data[] = array(
'id' => $cat->id,
'name' => $cat->name,
'locale' => $cat->locale,
'parents' => $link
);
}

View File

@ -23,12 +23,14 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
{
$this->model = $model;
}
public function findById($id)
{
return $this->model->orderBy('created_at', 'DESC')->where('cats_category.id', $id)->first();
}
public function mainCats(){
public function mainCats()
{
return $this->model->where('parent_category_id', null)->where('deleted_at', null)->get();
}
@ -51,8 +53,14 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
{
return CatsCategoryEntryModel::query()->where('cats_category.id', $id)->first();
}
public function findBySlug($slug)
{
return $this->model->orderBy('created_at', 'DESC')->where('slug', $slug)->first();
}
public function getCategories()
{
return $this->model->get();
}
}

View File

@ -17,4 +17,6 @@ interface CategoryRepositoryInterface extends EntryRepositoryInterface
public function getSingleCat($id);
public function findBySlug($slug);
public function getCategories();
}