mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
fixed category calculate
This commit is contained in:
parent
61a7bbcad6
commit
994c32fdeb
@ -24,6 +24,7 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
|
||||
->orderBy('sort_order')
|
||||
->get();
|
||||
}
|
||||
|
||||
public function getSubCatById($id)
|
||||
{
|
||||
$cats = $this->model->newQuery()
|
||||
@ -108,7 +109,8 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
|
||||
|
||||
public function getLevelById($id)
|
||||
{
|
||||
return count($this->getParentCategoryById($id));
|
||||
$parents = $this->getParentCategoryById($id);
|
||||
return (is_array($parents)) ? count($parents) : null;
|
||||
}
|
||||
|
||||
public function getCategoriesByName($keyword)
|
||||
@ -133,45 +135,45 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
|
||||
return $this->model->withTrashed()->newQuery()->whereNotNull('deleted_at')->get();
|
||||
}
|
||||
|
||||
public function getMainAndSubCats()
|
||||
{
|
||||
$dBName = 'cats_category';
|
||||
$dBNamet = $dBName . '_translations';
|
||||
public function getMainAndSubCats()
|
||||
{
|
||||
$dBName = 'cats_category';
|
||||
$dBNamet = $dBName . '_translations';
|
||||
|
||||
$catsDB = DB::table($dBName . ' as c1')
|
||||
->select(
|
||||
'c1.id',
|
||||
'c1.slug',
|
||||
'c1.parent_category_id',
|
||||
'c1.icon_id',
|
||||
't1.name',
|
||||
'c2.id as c2_id',
|
||||
'c2.slug as c2_slug',
|
||||
'c2.parent_category_id as c2_parent_category_id',
|
||||
't2.name as c2_name',
|
||||
'file.id as file_id'
|
||||
)
|
||||
->leftJoin($dBName . ' as c2', function ($join) {
|
||||
$join->on('c2.parent_category_id', '=', 'c1.id')
|
||||
$catsDB = DB::table($dBName . ' as c1')
|
||||
->select(
|
||||
'c1.id',
|
||||
'c1.slug',
|
||||
'c1.parent_category_id',
|
||||
'c1.icon_id',
|
||||
't1.name',
|
||||
'c2.id as c2_id',
|
||||
'c2.slug as c2_slug',
|
||||
'c2.parent_category_id as c2_parent_category_id',
|
||||
't2.name as c2_name',
|
||||
'file.id as file_id'
|
||||
)
|
||||
->leftJoin($dBName . ' as c2', function ($join) {
|
||||
$join->on('c2.parent_category_id', '=', 'c1.id')
|
||||
->whereNull('c2.deleted_at');
|
||||
})
|
||||
->leftJoin($dBNamet . ' as t1', function ($join) use ($dBNamet) {
|
||||
$join->on('c1.id', '=', 't1.entry_id')
|
||||
->leftJoin($dBNamet . ' as t1', function ($join) use ($dBNamet) {
|
||||
$join->on('c1.id', '=', 't1.entry_id')
|
||||
->where('t1.locale', Request()->session()->get('_locale', setting_value('streams::default_locale')));
|
||||
})
|
||||
->leftJoin($dBNamet . ' as t2', function ($join) use ($dBNamet) {
|
||||
$join->on('c2.id', '=', 't2.entry_id')
|
||||
->leftJoin($dBNamet . ' as t2', function ($join) use ($dBNamet) {
|
||||
$join->on('c2.id', '=', 't2.entry_id')
|
||||
->where('t2.locale', Request()->session()->get('_locale', setting_value('streams::default_locale')));
|
||||
})
|
||||
->leftJoin('files_files as file', 'c1.icon_id', 'file.id')
|
||||
->whereNull('c1.deleted_at')
|
||||
->whereNull('c1.parent_category_id')
|
||||
->orderBy('c1.sort_order')
|
||||
->orderBy('c2.sort_order')
|
||||
->get();
|
||||
$cats = collect([]);
|
||||
$cats->subcats = $catsDB;
|
||||
$cats->maincats = $catsDB->unique('id');
|
||||
return $cats;
|
||||
}
|
||||
->leftJoin('files_files as file', 'c1.icon_id', 'file.id')
|
||||
->whereNull('c1.deleted_at')
|
||||
->whereNull('c1.parent_category_id')
|
||||
->orderBy('c1.sort_order')
|
||||
->orderBy('c2.sort_order')
|
||||
->get();
|
||||
$cats = collect([]);
|
||||
$cats->subcats = $catsDB;
|
||||
$cats->maincats = $catsDB->unique('id');
|
||||
return $cats;
|
||||
}
|
||||
}
|
||||
@ -44,10 +44,13 @@ class CalculateCategoryLevel
|
||||
|
||||
$level = $categoryRepository->getLevelById($category_id);
|
||||
|
||||
DB::table('cats_category')->where('id', $category_id)
|
||||
->update(array(
|
||||
'level' => $level,
|
||||
'level_at' => now(),
|
||||
));
|
||||
if($level)
|
||||
{
|
||||
DB::table('cats_category')->where('id', $category_id)
|
||||
->update(array(
|
||||
'level' => $level,
|
||||
'level_at' => now(),
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user