mirror of
https://github.com/openclassify/openclassify.git
synced 2026-02-09 23:06:08 -06:00
Merge branch 'master' of https://github.com/openclassify/openclassify into basetheme
This commit is contained in:
commit
26f9457a10
@ -5,6 +5,6 @@ return [
|
|||||||
'title' => 'Category',
|
'title' => 'Category',
|
||||||
],
|
],
|
||||||
'placeholderforsearch' => [
|
'placeholderforsearch' => [
|
||||||
'title' => 'Placeholderforsearch',
|
'title' => 'Placeholder',
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|||||||
@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
return [
|
||||||
|
'clean_subcategories' => 'Clean Subcategories',
|
||||||
|
];
|
||||||
@ -9,7 +9,10 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
|||||||
|
|
||||||
public function getCat($id)
|
public function getCat($id)
|
||||||
{
|
{
|
||||||
return CategoryModel::query()->where('cats_category.id', $id)->first();
|
return CategoryModel::query()
|
||||||
|
->where('cats_category.id', $id)
|
||||||
|
->whereRaw('deleted_at IS NULL')
|
||||||
|
->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getParentCats($id, $type = null)
|
public function getParentCats($id, $type = null)
|
||||||
@ -34,7 +37,11 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($type == 'category_ids') {
|
if ($type == 'category_ids') {
|
||||||
return CategoryModel::query()->whereIn('cats_category.id', $cat_ids)->orderBy('cats_category.id', 'asc')->get();
|
return CategoryModel::query()
|
||||||
|
->whereIn('cats_category.id', $cat_ids)
|
||||||
|
->whereRaw('deleted_at IS NULL')
|
||||||
|
->orderBy('cats_category.id', 'asc')
|
||||||
|
->get();
|
||||||
}
|
}
|
||||||
if ($type == "parent_id") {
|
if ($type == "parent_id") {
|
||||||
$cat_ids = array_reverse($cat_ids);
|
$cat_ids = array_reverse($cat_ids);
|
||||||
@ -92,7 +99,8 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
|||||||
$cats = $cats->where('cats_category.id', '!=', $selected);
|
$cats = $cats->where('cats_category.id', '!=', $selected);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$cats = $cats->where('name', 'like', $keyword . '%');
|
$cats = $cats->where('name', 'like', $keyword . '%')
|
||||||
|
->whereRaw('deleted_at IS NULL');
|
||||||
|
|
||||||
$cats = $cats->leftJoin('cats_category_translations', function ($join) {
|
$cats = $cats->leftJoin('cats_category_translations', function ($join) {
|
||||||
$join->on('cats_category.id', '=', 'cats_category_translations.entry_id');
|
$join->on('cats_category.id', '=', 'cats_category_translations.entry_id');
|
||||||
|
|||||||
@ -10,7 +10,13 @@ class CategoryTableBuilder extends TableBuilder
|
|||||||
*
|
*
|
||||||
* @var array|string
|
* @var array|string
|
||||||
*/
|
*/
|
||||||
protected $views = [];
|
protected $views = [
|
||||||
|
'all',
|
||||||
|
'trash',
|
||||||
|
'clean_subcategories' => [
|
||||||
|
'href' => '/admin/cats/clean_subcats',
|
||||||
|
],
|
||||||
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The table filters.
|
* The table filters.
|
||||||
|
|||||||
@ -50,6 +50,7 @@ class CatsModuleServiceProvider extends AddonServiceProvider
|
|||||||
* @type array|null
|
* @type array|null
|
||||||
*/
|
*/
|
||||||
protected $routes = [
|
protected $routes = [
|
||||||
|
'admin/cats/clean_subcats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@cleanSubcats',
|
||||||
'admin/cats/placeholderforsearch' => 'Visiosoft\CatsModule\Http\Controller\Admin\PlaceholderforsearchController@index',
|
'admin/cats/placeholderforsearch' => 'Visiosoft\CatsModule\Http\Controller\Admin\PlaceholderforsearchController@index',
|
||||||
'admin/cats/placeholderforsearch/create' => 'Visiosoft\CatsModule\Http\Controller\Admin\PlaceholderforsearchController@create',
|
'admin/cats/placeholderforsearch/create' => 'Visiosoft\CatsModule\Http\Controller\Admin\PlaceholderforsearchController@create',
|
||||||
'admin/cats/placeholderforsearch/edit/{id}' => 'Visiosoft\CatsModule\Http\Controller\Admin\PlaceholderforsearchController@edit',
|
'admin/cats/placeholderforsearch/edit/{id}' => 'Visiosoft\CatsModule\Http\Controller\Admin\PlaceholderforsearchController@edit',
|
||||||
|
|||||||
@ -1,10 +1,8 @@
|
|||||||
<?php namespace Visiosoft\CatsModule\Http\Controller\Admin;
|
<?php namespace Visiosoft\CatsModule\Http\Controller\Admin;
|
||||||
|
|
||||||
use Anomaly\Streams\Platform\Image\Command\MakeImageInstance;
|
use Anomaly\Streams\Platform\Image\Command\MakeImageInstance;
|
||||||
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
|
|
||||||
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryTranslationsModel;
|
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryTranslationsModel;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Str;
|
use Illuminate\Support\Str;
|
||||||
use Sunra\PhpSimple\HtmlDomParser;
|
use Sunra\PhpSimple\HtmlDomParser;
|
||||||
use Visiosoft\CatsModule\Category\CategoryModel;
|
use Visiosoft\CatsModule\Category\CategoryModel;
|
||||||
@ -25,10 +23,10 @@ class CategoryController extends AdminController
|
|||||||
Str $str
|
Str $str
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
|
||||||
$this->categoryRepository = $categoryRepository;
|
$this->categoryRepository = $categoryRepository;
|
||||||
$this->categoryEntryTranslationsModel = $categoryEntryTranslationsModel;
|
$this->categoryEntryTranslationsModel = $categoryEntryTranslationsModel;
|
||||||
$this->str = $str;
|
$this->str = $str;
|
||||||
|
parent::__construct();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function index(CategoryTableBuilder $table, Request $request)
|
public function index(CategoryTableBuilder $table, Request $request)
|
||||||
@ -73,20 +71,21 @@ class CategoryController extends AdminController
|
|||||||
return $this->redirect->back();
|
return $this->redirect->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
$locale = DB::table('cats_category_translations')->select('locale')->distinct()->get()->toArray();
|
$locale = $this->getRequestLang($all);
|
||||||
|
|
||||||
$translatable = array();
|
$translatable = array();
|
||||||
foreach ($all as $key => $value) {
|
foreach ($all as $key => $value) {
|
||||||
foreach ($locale as $lang) {
|
foreach ($locale as $lang) {
|
||||||
if ($this->endsWith($key, "_$lang->locale") && !in_array(substr($key, 0, -3), $translatable)) {
|
if ($this->endsWith($key, "_$lang") && !in_array(substr($key, 0, -3), $translatable)) {
|
||||||
$translatable[] = substr($key, 0, -3);
|
$translatable[] = substr($key, 0, -3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$translatableEntries = array();
|
$translatableEntries = array();
|
||||||
foreach ($locale as $lang) {
|
foreach ($locale as $lang) {
|
||||||
$translatableEntries[$lang->locale] = array();
|
$translatableEntries[$lang] = array();
|
||||||
foreach ($translatable as $translatableEntry) {
|
foreach ($translatable as $translatableEntry) {
|
||||||
$translatableEntries[$lang->locale][$translatableEntry] = $all[$translatableEntry . '_' . $lang->locale];
|
$translatableEntries[$lang][$translatableEntry] = $all[$translatableEntry . '_' . $lang];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -99,7 +98,7 @@ class CategoryController extends AdminController
|
|||||||
foreach ($multiCat as $cat) {
|
foreach ($multiCat as $cat) {
|
||||||
$secondArray = array();
|
$secondArray = array();
|
||||||
foreach ($locale as $lang) {
|
foreach ($locale as $lang) {
|
||||||
if ($key === $lang->locale) {
|
if ($key === $lang) {
|
||||||
$secondArray[$key]['name'] = trim($cat);
|
$secondArray[$key]['name'] = trim($cat);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -109,7 +108,7 @@ class CategoryController extends AdminController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($isMultiCat)) {
|
if (empty($isMultiCat)) {
|
||||||
$this->categoryRepository->create(array_merge($translatableEntries, [
|
$this->categoryRepository->create(array_merge($translatableEntries, [
|
||||||
'slug' => $all['slug'],
|
'slug' => $all['slug'],
|
||||||
'parent_category' => $all['parent_category'] === "" ? null : $all['parent_category'],
|
'parent_category' => $all['parent_category'] === "" ? null : $all['parent_category'],
|
||||||
'icon' => $all['icon'],
|
'icon' => $all['icon'],
|
||||||
@ -172,6 +171,30 @@ class CategoryController extends AdminController
|
|||||||
return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
|
return substr_compare($string, $test, $strlen - $testlen, $testlen) === 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRequestLang($request) {
|
||||||
|
$locale = array();
|
||||||
|
foreach ($request as $key => $field) {
|
||||||
|
$locale[] = substr($key, 0, -2);
|
||||||
|
}
|
||||||
|
$notTrans = array();
|
||||||
|
$trans = array();
|
||||||
|
foreach ($locale as $translatable) {
|
||||||
|
if (!in_array($translatable, $notTrans)) {
|
||||||
|
$notTrans[] = $translatable;
|
||||||
|
} else {
|
||||||
|
$trans[] = $translatable;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$locale = array();
|
||||||
|
foreach ($request as $key => $field) {
|
||||||
|
foreach (array_unique($trans) as $entry) {
|
||||||
|
if (strpos($key, $entry) === 0) {
|
||||||
|
$locale[] = substr($key, -2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $locale;
|
||||||
|
}
|
||||||
|
|
||||||
public function edit(CategoryFormBuilder $form, Request $request, $id)
|
public function edit(CategoryFormBuilder $form, Request $request, $id)
|
||||||
{
|
{
|
||||||
@ -220,5 +243,21 @@ class CategoryController extends AdminController
|
|||||||
return redirect('admin/cats?cat=' . $request->parent)->with('success', ['Category and related sub-categories deleted successfully.']);
|
return redirect('admin/cats?cat=' . $request->parent)->with('success', ['Category and related sub-categories deleted successfully.']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function cleanSubcats()
|
||||||
|
{
|
||||||
|
$cats = $this->categoryRepository->all();
|
||||||
|
$deletedCatsCount = 0;
|
||||||
|
foreach ($cats as $cat) {
|
||||||
|
$parentCatId = $cat->parent_category_id;
|
||||||
|
$parentCat = $this->categoryRepository->find($parentCatId);
|
||||||
|
if (is_null($parentCat) && !is_null($parentCatId)) {
|
||||||
|
$this->categoryEntryTranslationsModel->where('entry_id', $cat->id)->delete();
|
||||||
|
$this->categoryRepository->DeleteCategories($cat->id);
|
||||||
|
$deletedCatsCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return redirect('admin/cats')->with('success', [$deletedCatsCount . ' categories has been deleted.']);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user