marhab request

This commit is contained in:
Muammer Top 2021-02-05 19:13:39 +03:00
parent 0b410bf31f
commit bb3fd15a76
2 changed files with 37 additions and 0 deletions

View File

@ -1,6 +1,7 @@
<?php namespace Visiosoft\CatsModule\Category; <?php namespace Visiosoft\CatsModule\Category;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel; use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
use Illuminate\Support\Facades\DB;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface; use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository; use Anomaly\Streams\Platform\Entry\EntryRepository;
@ -108,4 +109,38 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
$this->model->deleteSubCategories($id); $this->model->deleteSubCategories($id);
} }
} }
public function getMainAndSubCats()
{
$dBName = 'default_cats_category';
$dBNamet = $dBName . '_translations';
$catsDB = DB::table((DB::raw($dBName . ' c1')))
->select(
DB::raw('c1.id'),
DB::raw('c1.slug'),
DB::raw('c1.parent_category_id'),
DB::raw('t1.name'),
DB::raw('c2.id as c2_id'),
DB::raw('c2.slug as c2_slug'),
DB::raw('c2.parent_category_id as c2_parent_category_id'),
DB::raw('t2.name as c2_name')
)
->leftJoin((DB::raw($dBName . ' c2')), DB::raw('c2.parent_category_id'), '=', DB::raw('c1.id'))
->leftJoin((DB::raw($dBNamet . ' t1')), DB::raw('c1.id'), '=', DB::raw('t1.entry_id'))
->leftJoin((DB::raw($dBNamet . ' t2')), DB::raw('c2.id'), '=', DB::raw('t2.entry_id'))
->where(DB::raw('t1.locale'), Request()->session()->get('_locale', setting_value('streams::default_locale')))
->where(DB::raw('t2.locale'), Request()->session()->get('_locale', setting_value('streams::default_locale')))
->where(DB::raw("c1.deleted_at"), NULL)
->where(DB::raw("c2.deleted_at"), NULL)
->whereNull(DB::raw("c1.parent_category_id"))
->orderBy(DB::raw("c1.sort_order"))
->orderBy(DB::raw("c2.sort_order"))
->get();
$cats = collect([]);
$cats->subcats = $catsDB;
$cats->maincats = $catsDB->unique('id');
return $cats;
}
} }

View File

@ -21,4 +21,6 @@ interface CategoryRepositoryInterface extends EntryRepositoryInterface
public function getCategories(); public function getCategories();
public function DeleteCategories($id); public function DeleteCategories($id);
public function getMainAndSubCats();
} }