mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
commit
d9c3d34118
@ -76,10 +76,12 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
|
||||
return $this->model->orderBy('sort_order')->get();
|
||||
}
|
||||
|
||||
public function removeCatFromAds($id)
|
||||
public function removeCatFromAds($category)
|
||||
{
|
||||
$category = $this->find($id);
|
||||
$catLevelNum = is_null($category->parent_category_id) ? 1 : $this->model->getCatLevel($category->id);
|
||||
$catLevelNum = 1;
|
||||
if (!is_null($category->parent_category_id)) {
|
||||
$catLevelNum = $this->model->getCatLevel($category->id);
|
||||
}
|
||||
$catLevelText = "cat" . $catLevelNum;
|
||||
|
||||
$advs = $this->advRepository->newQuery()->where($catLevelText, $category->id)->get();
|
||||
@ -94,13 +96,15 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
|
||||
|
||||
public function DeleteCategories($id)
|
||||
{
|
||||
// Remove deleted category from ads
|
||||
$this->removeCatFromAds($id);
|
||||
if (!is_null($category = $this->find($id))) {
|
||||
// Remove deleted category from ads
|
||||
$this->removeCatFromAds($category);
|
||||
|
||||
// Delete the category
|
||||
$this->model->find($id)->delete();
|
||||
// Delete the category
|
||||
$this->model->find($id)->delete();
|
||||
|
||||
// Delete the subcategories
|
||||
$this->model->deleteSubCategories($id);
|
||||
// Delete the subcategories
|
||||
$this->model->deleteSubCategories($id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -47,8 +47,7 @@ class CategoryController extends AdminController
|
||||
$this->messages->error('Selected category has no sub-categories.');
|
||||
return back();
|
||||
}
|
||||
if($request->view != "trash")
|
||||
{
|
||||
if ($request->view != "trash") {
|
||||
$table->setTableEntries($categories);
|
||||
}
|
||||
|
||||
@ -157,7 +156,8 @@ class CategoryController extends AdminController
|
||||
return $this->view->make('visiosoft.module.cats::cats/admin-cat');
|
||||
}
|
||||
|
||||
public function endsWith($string, $test) {
|
||||
public function endsWith($string, $test)
|
||||
{
|
||||
$strlen = strlen($string);
|
||||
$testlen = strlen($test);
|
||||
if ($testlen > $strlen) return false;
|
||||
@ -185,12 +185,13 @@ class CategoryController extends AdminController
|
||||
public function delete(CategoryRepositoryInterface $categoryRepository, Request $request, CategoryModel $categoryModel, $id)
|
||||
{
|
||||
$categoryRepository->DeleteCategories($id);
|
||||
$subCats = $categoryRepository->getSubCatById($request->parent);
|
||||
if (count($subCats)) {
|
||||
return redirect('admin/cats?cat=' . $request->parent)->with('success', ['Category and related sub-categories deleted successfully.']);
|
||||
} else {
|
||||
return redirect('admin/cats')->with('success', ['Category and related sub-categories deleted successfully.']);
|
||||
if ($request->parent != "") {
|
||||
$subCats = $categoryRepository->getSubCatById($request->parent);
|
||||
if (count($subCats)) {
|
||||
return redirect('admin/cats?cat=' . $request->parent)->with('success', ['Category and related sub-categories deleted successfully.']);
|
||||
}
|
||||
}
|
||||
return redirect('admin/cats')->with('success', ['Category and related sub-categories deleted successfully.']);
|
||||
}
|
||||
|
||||
public function cleanSubcats()
|
||||
|
||||
Loading…
Reference in New Issue
Block a user