refactoring cats module

This commit is contained in:
vedatakd 2020-09-12 17:33:01 +03:00
parent 8851bae78f
commit dcb03ef9be
43 changed files with 301 additions and 982 deletions

View File

@ -12,7 +12,7 @@
</a> </a>
</li> </li>
{{ addBlock('ads-list/partials/breadcrumb',{'mainCats': mainCats, 'category': categoryId})|raw }} {{ addBlock('ads-list/partials/breadcrumb',{'mainCats': mainCats, 'category': category})|raw }}
</ol> </ol>
</nav> </nav>

View File

@ -39,7 +39,7 @@
'neighborhoods':neighborhoods, 'neighborhoods':neighborhoods,
'villages':villages, 'villages':villages,
'param':param, 'param':param,
'categoryId':categoryId, 'category':category,
'cityId':cityId, 'cityId':cityId,
'_ORDER_':['visiosoft.module.cats', 'visiosoft.module.location'] '_ORDER_':['visiosoft.module.cats', 'visiosoft.module.location']
})|raw }} })|raw }}

View File

@ -10,7 +10,7 @@ use Intervention\Image\Facades\Image;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository; use Anomaly\Streams\Platform\Entry\EntryRepository;
use Visiosoft\CatsModule\Category\CategoryModel; use Visiosoft\CatsModule\Category\CategoryModel;
use Visiosoft\AdvsModule\Category\Contract\CategoryRepositoryInterface; use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\LocationModule\Country\CountryModel;
@ -34,6 +34,9 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
*/ */
private $folderRepository; private $folderRepository;
public $categoryRepository;
/** /**
* Create a new AdvRepository instance. * Create a new AdvRepository instance.
* *
@ -43,13 +46,15 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
AdvModel $model, AdvModel $model,
SettingRepositoryInterface $settings, SettingRepositoryInterface $settings,
FileRepositoryInterface $fileRepository, FileRepositoryInterface $fileRepository,
FolderRepositoryInterface $folderRepository FolderRepositoryInterface $folderRepository,
CategoryRepositoryInterface $categoryRepository
) )
{ {
$this->model = $model; $this->model = $model;
$this->settings = $settings; $this->settings = $settings;
$this->fileRepository = $fileRepository; $this->fileRepository = $fileRepository;
$this->folderRepository = $folderRepository; $this->folderRepository = $folderRepository;
$this->categoryRepository = $categoryRepository;
} }
/** /**
@ -112,16 +117,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
} }
} }
if ($category) { if ($category) {
$cat = new CategoryModel(); $query = $this->categoryRepository->setQuerySearchingAds($query, $category);
if ($category) {
if ($category->parent_category_id == null) {
$catLevel = 1;
} else {
$catLevel = $cat->getCatLevel($category->id);
}
$catLevel = "cat" . $catLevel;
$query = $query->where($catLevel, $category->id);
}
} }
if (!empty($param['user'])) { if (!empty($param['user'])) {
$query = $query->where('advs_advs.created_by_id', $param['user']); $query = $query->where('advs_advs.created_by_id', $param['user']);
@ -265,20 +261,11 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
public function getCatNames($adv) public function getCatNames($adv)
{ {
$cat1 = CategoryModel::query()->where('cats_category.id', $adv->cat1)->first(); $cat1 = $this->categoryRepository->find($adv->cat1);
$cat2 = CategoryModel::query()->where('cats_category.id', $adv->cat2)->first(); $cat2 = $this->categoryRepository->find($adv->cat2);
if (!is_null($cat1))
$adv->setAttribute('cat1_name', $cat1->name);
else
$adv->setAttribute('cat1_name', "");
if (!is_null($cat2))
$adv->setAttribute('cat2_name', $cat2->name);
else
$adv->setAttribute('cat2_name', "");
$adv->setAttribute('cat1_name', ($cat1) ? $cat1->name : "");
$adv->setAttribute('cat2_name', ($cat2) ? $cat2->name : "");
return $adv; return $adv;
} }
@ -301,9 +288,9 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
public function addAttributes($advs) public function addAttributes($advs)
{ {
foreach ($advs as $adv) { foreach ($advs as $key => $adv) {
$adv = $this->getLocationNames($adv); $advs[$key] = $this->getLocationNames($adv);
$adv = $this->getCatNames($adv); $advs[$key] = $this->getCatNames($adv);
} }
return $advs; return $advs;

View File

@ -0,0 +1,32 @@
<?php namespace Visiosoft\AdvsModule\Adv\Listener;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\CatsModule\Category\Events\DeletedCategory;
class CategoryDeleted
{
public $advRepository;
public function __construct(AdvRepositoryInterface $advRepository)
{
$this->advRepository = $advRepository;
}
public function handle(DeletedCategory $event)
{
$category = $event->getCategory();
$catLevelNum = ($category->parent_category_id) ? count($event->getParents()) : 1;
$catLevelText = "cat" . $catLevelNum;
$advs = $this->advRepository->newQuery()->where($catLevelText, $category->id)->get();
foreach ($advs as $adv) {
$nullableCats = array();
for ($i = $catLevelNum; $i <= 10; $i++) {
$nullableCats['cat' . $i] = null;
}
$adv->update($nullableCats);
}
}
}

View File

@ -10,11 +10,13 @@ use Visiosoft\AdvsModule\Adv\AdvRepository;
use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel; use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel;
use Visiosoft\AdvsModule\Adv\AdvModel; use Visiosoft\AdvsModule\Adv\AdvModel;
use Visiosoft\AdvsModule\Adv\Form\AdvFormBuilder; use Visiosoft\AdvsModule\Adv\Form\AdvFormBuilder;
use Visiosoft\AdvsModule\Adv\Listener\CategoryDeleted;
use Visiosoft\AdvsModule\Http\Middleware\redirectDiffrentLang; use Visiosoft\AdvsModule\Http\Middleware\redirectDiffrentLang;
use Visiosoft\AdvsModule\Http\Middleware\SetLang; use Visiosoft\AdvsModule\Http\Middleware\SetLang;
use Visiosoft\AdvsModule\Listener\AddAdvsSettingsScript; use Visiosoft\AdvsModule\Listener\AddAdvsSettingsScript;
use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface; use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface;
use Visiosoft\AdvsModule\Option\OptionRepository; use Visiosoft\AdvsModule\Option\OptionRepository;
use Visiosoft\CatsModule\Category\Events\DeletedCategory;
use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface; use Visiosoft\LocationModule\Village\Contract\VillageRepositoryInterface;
use Visiosoft\LocationModule\Village\VillageRepository; use Visiosoft\LocationModule\Village\VillageRepository;
use Visiosoft\LocationModule\Village\VillageModel; use Visiosoft\LocationModule\Village\VillageModel;
@ -178,6 +180,9 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
TableIsQuerying::class => [ TableIsQuerying::class => [
AddAdvsSettingsScript::class, AddAdvsSettingsScript::class,
], ],
DeletedCategory::class => [
CategoryDeleted::class
],
]; ];
/** /**

View File

@ -19,6 +19,7 @@ use Visiosoft\AdvsModule\Adv\Table\AdvTableBuilder;
use Anomaly\Streams\Platform\Http\Controller\AdminController; use Anomaly\Streams\Platform\Http\Controller\AdminController;
use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface; use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface;
use Visiosoft\CatsModule\Category\CategoryModel; use Visiosoft\CatsModule\Category\CategoryModel;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\AlgoliaModule\Search\SearchModel; use Visiosoft\AlgoliaModule\Search\SearchModel;
@ -134,9 +135,9 @@ class AdvsController extends AdminController
'value' => 'entry.created_by.name' 'value' => 'entry.created_by.name'
], ],
'category' => [ 'category' => [
'value' => function (EntryInterface $entry, CategoryModel $categoryModel) { 'value' => function (EntryInterface $entry, CategoryRepositoryInterface $categoryRepository) {
$category = $categoryModel->getCat($entry->cat1); $category = $categoryRepository->find($entry->cat1);
if (!is_null($category)) if ($category)
return $category->name; return $category->name;
} }
], ],

View File

@ -5,6 +5,7 @@ use Anomaly\UsersModule\User\UserModel;
use Visiosoft\AdvsModule\Adv\AdvModel; use Visiosoft\AdvsModule\Adv\AdvModel;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\LocationModule\District\DistrictModel; use Visiosoft\LocationModule\District\DistrictModel;
use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel; use Visiosoft\LocationModule\Neighborhood\NeighborhoodModel;
@ -50,12 +51,12 @@ class AjaxController extends PublicController
return response()->json($datas); return response()->json($datas);
} }
public function keySearch(Request $request) public function keySearch(Request $request, CategoryRepositoryInterface $categoryRepository)
{ {
$datas = []; $response = [
$catModel = new CategoryModel(); 'category' => $categoryRepository->searchKeyword($request->q, $request->selected)
$datas['category'] = $catModel->searchKeyword($request->q, $request->selected); ];
return response()->json($datas); return response()->json($response);
} }
public function viewed(AdvModel $advModel, $id) public function viewed(AdvModel $advModel, $id)
@ -75,7 +76,7 @@ class AjaxController extends PublicController
$my_advs = $my_advs->myAdvsByUser(); $my_advs = $my_advs->myAdvsByUser();
} }
$my_advs = $my_advs->select(['id', 'cover_photo', 'slug', 'price', 'currency', 'city', 'country_id', 'cat1', 'cat2', 'status']) $my_advs = $my_advs->select(['id', 'cover_photo', 'slug', 'price', 'currency', 'city', 'country_id', 'cat1', 'cat2', 'status'])
->orderByDesc('id'); ->orderByDesc('id');
$my_advs = $advRepository->addAttributes($my_advs->get()); $my_advs = $advRepository->addAttributes($my_advs->get());
foreach ($my_advs as $index => $ad) { foreach ($my_advs as $index => $ad) {

View File

@ -135,10 +135,9 @@ class AdvsController extends PublicController
$isActiveDopings = $this->adv_model->is_enabled('dopings'); $isActiveDopings = $this->adv_model->is_enabled('dopings');
// Search by category slug // Search by category slug
$categoryId = null;
if ($category) { // Slug if ($category) { // Slug
$categoryId = $this->category_repository->findBy('slug', $category); $category = $this->category_repository->findBy('slug', $category);
if (!$categoryId) { if (!$category) {
$this->messages->error(trans('visiosoft.module.advs::message.category_not_exist')); $this->messages->error(trans('visiosoft.module.advs::message.category_not_exist'));
return redirect('/'); return redirect('/');
} }
@ -146,20 +145,20 @@ class AdvsController extends PublicController
unset($param['cat']); unset($param['cat']);
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug]), route('adv_list_seo', [$category->slug]),
array() array()
)); ));
} }
} elseif (isset($param['cat']) && !empty($param['cat'])) { // Only Param } elseif (isset($param['cat']) && !empty($param['cat'])) { // Only Param
$categoryId = $this->category_repository->find($param['cat']); $category = $this->category_repository->find($param['cat']);
if (!$categoryId) { if (!$category) {
$this->messages->error(trans('visiosoft.module.advs::message.category_not_exist')); $this->messages->error(trans('visiosoft.module.advs::message.category_not_exist'));
return redirect('/'); return redirect('/');
} }
unset($param['cat']); unset($param['cat']);
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug]), route('adv_list_seo', [$category->slug]),
array() array()
)); ));
} }
@ -179,7 +178,7 @@ class AdvsController extends PublicController
unset($param['city']); unset($param['city']);
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug, $cityId->slug]), route('adv_list_seo', [$category->slug, $cityId->slug]),
array() array()
)); ));
} elseif ($isOneCity) { // Param and slug } elseif ($isOneCity) { // Param and slug
@ -188,14 +187,14 @@ class AdvsController extends PublicController
unset($param['city']); unset($param['city']);
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug, $cityId->slug]), route('adv_list_seo', [$category->slug, $cityId->slug]),
array() array()
)); ));
} }
} elseif ($city && $isMultipleCity) { // Slug and multiple param cities } elseif ($city && $isMultipleCity) { // Slug and multiple param cities
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug]), route('adv_list_seo', [$category->slug]),
array() array()
)); ));
} elseif ($city) { } elseif ($city) {
@ -203,7 +202,7 @@ class AdvsController extends PublicController
unset($param['city']); unset($param['city']);
return redirect($this->fullLink( return redirect($this->fullLink(
$param, $param,
route('adv_list_seo', [$categoryId->slug]), route('adv_list_seo', [$category->slug]),
array() array()
)); ));
} else { // Only slug } else { // Only slug
@ -213,7 +212,7 @@ class AdvsController extends PublicController
} }
$isActiveCustomFields = $this->adv_model->is_enabled('customfields'); $isActiveCustomFields = $this->adv_model->is_enabled('customfields');
$advs = $this->adv_repository->searchAdvs('list', $param, $customParameters, null, $categoryId, $cityId); $advs = $this->adv_repository->searchAdvs('list', $param, $customParameters, null, $category, $cityId);
$advs = $this->adv_repository->addAttributes($advs); $advs = $this->adv_repository->addAttributes($advs);
if ($isActiveDopings and $param != null) { if ($isActiveDopings and $param != null) {
@ -233,27 +232,22 @@ class AdvsController extends PublicController
} }
if ($categoryId) { if ($category) {
$seo_keywords = $this->category_model->getMeta_keywords($categoryId->id); $this->template->set('og_description', $category->seo_description);
$seo_description = $this->category_model->getMeta_description($categoryId->id); $this->template->set('meta_description', $category->seo_description);
$seo_title = $this->category_model->getMeta_title($categoryId->id); $this->template->set('meta_title', $category->name);
$this->template->set('meta_keywords', implode(', ', $category->seo_keyword));
$this->template->set('og_description', $seo_description); $mainCats = $this->category_repository->getParents($category->id);
$this->template->set('meta_description', $seo_description);
$this->template->set('meta_title', $seo_title);
$this->template->set('meta_keywords', implode(', ', $seo_keywords));
$mainCats = $this->category_model->getMains($categoryId->id); $subCats = $this->category_repository->getSubCategories($category->id);
$current_cat = $this->category_model->getCat($categoryId->id);
$mainCats[] = [
'id' => $current_cat->id,
'val' => $current_cat->name,
'slug' => $current_cat->slug,
];
$subCats = $this->category_repository->getSubCatById($categoryId->id);
} else { } else {
$mainCats = $this->category_repository->mainCats(); $mainCats = $this->category_repository->getMainCategories();
$allCats = true;
$meta_title = $this->category_repository->getCategoryTextSeo($mainCats);
$this->template->set('showTitle', false);
$this->template->set('meta_title', $meta_title);
} }
if ($isActiveCustomFields) { if ($isActiveCustomFields) {
@ -271,21 +265,6 @@ class AdvsController extends PublicController
$viewType = $this->requestHttp->cookie('viewType'); $viewType = $this->requestHttp->cookie('viewType');
if (!isset($allCats)) {
if (count($mainCats) == 1 || count($mainCats) == 2) {
$catText = end($mainCats)['val'];
} elseif (count($mainCats) > 2) {
$catArray = array_slice($mainCats, 2);
$catText = '';
$loop = 0;
foreach ($catArray as $cat) {
$catText = !$loop ? $catText . $cat['val'] : $catText . ' ' . $cat['val'];
$loop++;
}
}
$this->template->set('showTitle', false);
$this->template->set('meta_title', $catText);
}
if (!empty($param['user'])) { if (!empty($param['user'])) {
$user = $this->userRepository->find($param['user']); $user = $this->userRepository->find($param['user']);
@ -295,7 +274,7 @@ class AdvsController extends PublicController
$compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'request', 'param', $compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'request', 'param',
'user', 'featured_advs', 'viewType', 'topfields', 'selectDropdown', 'selectRange', 'selectImage', 'ranges', 'user', 'featured_advs', 'viewType', 'topfields', 'selectDropdown', 'selectRange', 'selectImage', 'ranges',
'seenList', 'searchedCountry', 'radio', 'categoryId', 'cityId', 'allCats', 'catText'); 'seenList', 'searchedCountry', 'radio', 'category', 'cityId', 'allCats', 'catText');
return $this->viewTypeBasedRedirect($viewType, $compact); return $this->viewTypeBasedRedirect($viewType, $compact);
} }
@ -351,7 +330,7 @@ class AdvsController extends PublicController
for ($i = 1; $i <= 10; $i++) { for ($i = 1; $i <= 10; $i++) {
$cat = "cat" . $i; $cat = "cat" . $i;
if ($adv->$cat != null) { if ($adv->$cat != null) {
$item = $this->category_repository->getItem($adv->$cat); $item = $this->category_repository->find($adv->$cat);
if (!is_null($item)) { if (!is_null($item)) {
$categories['cat' . $i] = [ $categories['cat' . $i] = [
'name' => $item->name, 'name' => $item->name,
@ -427,7 +406,7 @@ class AdvsController extends PublicController
for ($i = 1; $i <= 10; $i++) { for ($i = 1; $i <= 10; $i++) {
$cat = "cat" . $i; $cat = "cat" . $i;
if ($adv->$cat != null) { if ($adv->$cat != null) {
$item = $this->category_repository->getItem($adv->$cat); $item = $this->category_repository->find($adv->$cat);
if (!is_null($item)) { if (!is_null($item)) {
$categories['cat' . $i] = [ $categories['cat' . $i] = [
'name' => $item->name, 'name' => $item->name,
@ -467,12 +446,18 @@ class AdvsController extends PublicController
return back(); return back();
} }
public function getCats($id)
{
return $this->category_repository->getSubCatById($id);
}
public function getCatsForNewAd($id) public function getCatsForNewAd($id)
{ {
if ($this->adv_model->is_enabled('packages')) { if ($this->adv_model->is_enabled('packages')) {
$cats = app('Visiosoft\PackagesModule\Http\Controller\PackageFEController')->AdLimitForCategorySelection($id); $cats = app('Visiosoft\PackagesModule\Http\Controller\PackageFEController')->AdLimitForCategorySelection($id);
} else { } else {
$cats = $this->category_repository->getSubCatById($id); $cats = $this->getCats($id);
if (empty($cats->toArray())) { if (empty($cats->toArray())) {
$cats = trans('visiosoft.module.advs::message.create_ad_with_post_cat'); $cats = trans('visiosoft.module.advs::message.create_ad_with_post_cat');
@ -499,7 +484,7 @@ class AdvsController extends PublicController
for ($i = 0; $i < $end; $i++) { for ($i = 0; $i < $end; $i++) {
$plus1 = $i + 1; $plus1 = $i + 1;
$cat = $repository->getSingleCat($cats['cat' . $plus1]); $cat = $repository->find($cats['cat' . $plus1]);
$cats_d['cat' . $plus1] = $cat->name; $cats_d['cat' . $plus1] = $cat->name;
} }
if ($isActive->is_enabled('customfields')) { if ($isActive->is_enabled('customfields')) {
@ -619,7 +604,7 @@ class AdvsController extends PublicController
foreach ($cats as $para => $value) { foreach ($cats as $para => $value) {
if (substr($para, 0, 3) === "cat") { if (substr($para, 0, 3) === "cat") {
$id = $cats[$para]; $id = $cats[$para];
$cat = $this->category_repository->getSingleCat($id); $cat = $categoryRepository->find($id);
if ($cat != null) { if ($cat != null) {
$cats_d[$para] = $cat->name; $cats_d[$para] = $cat->name;
} }
@ -659,7 +644,7 @@ class AdvsController extends PublicController
for ($i = 1; $i <= 10; $i++) { for ($i = 1; $i <= 10; $i++) {
if ($adv[$cat . $i]) { if ($adv[$cat . $i]) {
$name = $this->category_repository->getSingleCat($adv[$cat . $i]); $name = $this->category_repository->find($adv[$cat . $i]);
if ($name) { if ($name) {
$cats_d['cat' . $i] = $name->name; $cats_d['cat' . $i] = $name->name;
$cats['cat' . $i] = $name->id; $cats['cat' . $i] = $name->id;
@ -740,7 +725,7 @@ class AdvsController extends PublicController
{ {
$mainCats = $this->category_repository->mainCats(); $mainCats = $this->category_repository->mainCats();
return $this->view->make('visiosoft.module.advs::new-ad/post-cat', compact('mainCats')); return $this->view->make('visiosoft.module.advs::new-ad/post-cat', compact('main_cats'));
} }
public function editCategoryForAd($id) public function editCategoryForAd($id)

View File

@ -37,7 +37,6 @@ class VisiosoftModuleCatsCreateCatsFields extends Migration
], ],
'seo_keyword' => 'anomaly.field_type.tags', 'seo_keyword' => 'anomaly.field_type.tags',
'seo_description' => 'anomaly.field_type.text', 'seo_description' => 'anomaly.field_type.text',
]; ];
} }

View File

@ -1,35 +0,0 @@
<?php
use Anomaly\Streams\Platform\Database\Migration\Migration;
class VisiosoftModuleCatsCreatePlaceholderforsearchStream extends Migration
{
/**
* The stream definition.
*
* @var array
*/
protected $stream = [
'slug' => 'placeholderforsearch',
'title_column' => 'name',
'translatable' => true,
'versionable' => false,
'trashable' => false,
'searchable' => false,
'sortable' => false,
];
/**
* The stream assignments.
*
* @var array
*/
protected $assignments = [
'name' => [
'translatable' => true,
'required' => true,
],
];
}

View File

@ -1,8 +1,8 @@
{% if params.category %} {% if params.category %}
{% for category_breadcrumbs in params.mainCats %} {% for category_breadcrumbs in params.mainCats %}
<li class="breadcrumb-item"> <li class="breadcrumb-item">
<a href="{{ url_route('adv_list_seo', [category_breadcrumbs['slug']]) }}" <a href="{{ url_route('adv_list_seo', [category_breadcrumbs.slug]) }}"
class="text-dark font-weight-bold">{{ category_breadcrumbs['val'] }} class="text-dark font-weight-bold">{{ category_breadcrumbs.name }}
</a> </a>
</li> </li>
{% endfor %} {% endfor %}

View File

@ -10,45 +10,40 @@
</div> </div>
<div id="category" class="collapse show overflow-auto" aria-labelledby="categoryHeading" style="max-height: 300px;"> <div id="category" class="collapse show overflow-auto" aria-labelledby="categoryHeading" style="max-height: 300px;">
<div class="list-group"> <div class="list-group">
{% for maincat in params.mainCats %} {% for maincat in params.mainCats|reverse %}
{% set name = maincat['val'] %}
{% set id = maincat['id'] %}
{% set parent_category = true %}
{% if app.request.get('cat') is null or app.request.get('cat') == "" %}
{% if params.categoryId is null %}
{% set name = maincat.name %}
{% set id = maincat.id %}
{% set parent_category = false %}
{% endif %}
{% endif %}
{% set catId = entries('cats', 'category').find(id) %}
{% set citySlug = null %} {% set citySlug = null %}
{% set pathInfo = app.request.pathinfo|split('/') %} {% set pathInfo = app.request.pathinfo|split('/') %}
{% if pathInfo|length is same as(4) %} {% if pathInfo|length is same as(4) %}
{% set citySlug = pathInfo[3] %} {% set citySlug = pathInfo[3] %}
{% endif %} {% endif %}
<a href="{% if(viewType != "map") %}
{{ appendRequestURL(request_query(),url_route('adv_list_seo', [catId.slug, citySlug]),{},['page']) }} {% set url = appendRequestURL(request_query(),url_route('adv_list_seo', [maincat.slug, citySlug]),{},['page']) %}
{% else %}
{{ appendRequestURL(request_query(),url_route('adv_list_seo'),{'cat':id},['page']) }} {% if viewType == "map" %}
{% endif %}" class="list-group-item list-group-item-action text-truncate"> {% set url = appendRequestURL(request_query(),url_route('adv_list_seo'),{'cat':maincat.id},['page']) %}
{% endif %}
<a href="{{ url }}" class="list-group-item list-group-item-action text-truncate">
<i class="fas fa-dot-circle"></i> <i class="fas fa-dot-circle"></i>
{{ name }} {{ maincat.name }}
</a> </a>
{% for subcat in params.subCats %} {% if maincat.id == params.category.id %}
<div class="list-group pl-3 bg-light"> {% for subcat in params.subCats %}
{% if subcat.parent_category_id == maincat['id'] %} <div class="list-group pl-3 bg-light">
{% set subCatId = entries('cats', 'category').find(subcat.id) %}
<a href="{% if(viewType != "map") %} {% set url = appendRequestURL(request_query(),url_route('adv_list_seo', [subcat.slug, citySlug]),{},['page']) %}
{{ appendRequestURL(request_query(),url_route('adv_list_seo', [subCatId.slug, citySlug]),{},['page']) }}
{% else %} {% if viewType == "map" %}
{{ appendRequestURL(request_query(),url_route('adv_list_seo'),{'cat':subcat.id},['page']) }} {% set url = appendRequestURL(request_query(),url_route('adv_list_seo'),{'cat':subcat.id},['page']) %}
{% endif %}" class="list-group-item list-group-item-action text-truncate"> {% endif %}
<a href="{{ url }}" class="list-group-item list-group-item-action text-truncate">
{{ subcat.name }} {{ subcat.name }}
</a> </a>
{% endif %} </div>
</div> {% endfor %}
{% endfor %} {% endif %}
{% endfor %} {% endfor %}
</div> </div>
</div> </div>

View File

@ -8,15 +8,15 @@
{{ asset_add("scripts.js", "streams::js/table/sortable.js") }} {{ asset_add("scripts.js", "streams::js/table/sortable.js") }}
{% endif %} {% endif %}
{% if app.request.get('cat') != null %} {% if app.request.get('cat') != null %}
{% set parent = category_detail(app.request.get('cat')) %} {% set parent = findCategory(app.request.get('cat')) %}
{% if parent.parent_category is null %} {% if parent.parent_category is null %}
{% set parent_url = url('admin/cats') %} {% set parent_url = url('admin/cats') %}
{% else %} {% else %}
{% set parent_url = url('admin/cats?cat='~parent.parent_category_id) %} {% set parent_url = url('admin/cats?cat='~parent.parent_category_id) %}
{% endif %} {% endif %}
<ol class="breadcrumb"> <ol class="breadcrumb">
{% for parnt in category_parents_name(app.request.get('cat'))|reverse %} {% for parent in getParents(app.request.get('cat'))|reverse %}
<li class="breadcrumb-item"><a><b>{{ parnt }}</b></a></li> <li class="breadcrumb-item"><a><b>{{ parent.name }}</b></a></li>
{% endfor %} {% endfor %}
</ol> </ol>
<div class="container-fluid"> <div class="container-fluid">

View File

@ -20,7 +20,7 @@ class CategoryCriteria extends EntryCriteria
} }
public function getMainCats() { public function getMainCats() {
$mainCats = $this->categoryRepository->mainCats(); $mainCats = $this->categoryRepository->getMainCategories();
foreach ($mainCats as $cat) { foreach ($mainCats as $cat) {
$subCount = $this->categoryRepository->newQuery()->where('parent_category_id', $cat->id)->count(); $subCount = $this->categoryRepository->newQuery()->where('parent_category_id', $cat->id)->count();

View File

@ -1,191 +1,8 @@
<?php namespace Visiosoft\CatsModule\Category; <?php namespace Visiosoft\CatsModule\Category;
use Illuminate\Support\Facades\DB;
use Visiosoft\CatsModule\Category\Contract\CategoryInterface; use Visiosoft\CatsModule\Category\Contract\CategoryInterface;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel; use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
{ {
public function getCat($id)
{
return CategoryModel::query()
->where('cats_category.id', $id)
->whereRaw('deleted_at IS NULL')
->first();
}
public function getParentCats($id, $type = null)
{
$cat = $this->getCat($id);
$catNames = array();
$cat_ids = array();
$catNames[] = $cat->name;
$cat_ids[] = $cat->id;
$subCat = $cat->parent_category_id;
if ($subCat != null) {
for ($i = 0; $i < 10; $i++) {
$parCat = $this->getCat($subCat);
if (isset($parCat)) {
if ($parCat->parent_category_id == "") {
if ($type == "add_main")
$catNames[] = $parCat->name;
break;
}
$catNames[] = $parCat->name;
$cat_ids[] = $parCat->id;
$subCat = $parCat->parent_category_id;
}
}
}
if ($type == 'category_ids') {
return CategoryModel::query()
->whereIn('cats_category.id', $cat_ids)
->whereRaw('deleted_at IS NULL')
->orderBy('cats_category.id', 'asc')
->get();
}
if ($type == "parent_id") {
$cat_ids = array_reverse($cat_ids);
return $cat_ids[0];
}
return $catNames;
}
public function getCatLevel($id)
{
//count parent and itself
return count($this->getParentCats($id)) + 1;
}
public function getParentsCount($id)
{
$parentCats = array();
$currentId = $id;
do {
$cat = $this->getCat($currentId);
$catParent = $cat->parent_category_id;
if ($catParent) {
$currentId = $catParent;
$parentCats[] = $catParent;
}
} while ($catParent);
return count($parentCats);
}
public function getSubCategories($id, $get = null)
{
$sub_categories = $this->where('parent_category_id', $id)->get();
if ($get == 'id') {
$list_categories_id = array();
foreach ($sub_categories as $item_category) {
$list_categories_id[] = $item_category->id;
}
return $list_categories_id;
}
return $sub_categories;
}
public function getAllSubCategories($id)
{
$sub = $this->getSubCategories($id, 'id');
for ($i = 0; $i <= count($sub) - 1; $i++) {
$sub = array_merge($sub, $this->getSubCategories($sub[$i], 'id'));
}
return $sub;
}
public function deleteSubCategories($id)
{
$subCategories = $this->getAllSubCategories($id);
if (count($subCategories)) {
$this->newQuery()->whereIn('id', $subCategories)->delete();
}
return true;
}
public function searchKeyword($keyword, $selected = null)
{
$data = [];
$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 . '%')
->whereRaw('deleted_at IS NULL');
$cats = $cats->leftJoin('cats_category_translations', function ($join) {
$join->on('cats_category.id', '=', 'cats_category_translations.entry_id');
$join->whereIn('cats_category_translations.locale', [config('app.locale'), setting_value('streams::default_locale'),'en']);//active lang
});
$cats = $cats->select('cats_category.*', 'cats_category_translations.name as name');
$cats = $cats->orderBy('id', 'DESC')
->groupBy(['cats_category.id'])
->get();
foreach ($cats as $cat) {
$link = '';
$parents = $this->getParentCats($cat->id, null);
krsort($parents);
foreach ($parents as $key => $parent) {
if ($key == 0) {
$link .= $parent . '';
} else {
$link .= $parent . ' > ';
}
}
$data[] = array(
'id' => $cat->id,
'name' => $cat->name,
'parents' => $link
);
}
return $data;
}
public function getMainCategory()
{
return $this->where('parent_category_id', NULL)->get();
}
public function getMeta_keywords($cat_id)
{
return $this->find($cat_id)->seo_keyword;
}
public function getMeta_description($cat_id)
{
return $this->find($cat_id)->seo_description;
}
public function getMeta_title($cat_id)
{
return $this->find($cat_id)->name;
}
public function getMains($id)
{
$categories = array();
$z = 1;
for ($i = 1; $i <= $z; $i++) {
$main = $this->newQuery()->where('id', $id)->first();
$new = array();
$new['id'] = $main->id;
$new['val'] = $main->name;
$new['slug'] = $main->slug;
$categories[] = $new;
if ($main->parent_category_id != null) {
$id = $main->parent_category_id;
$z++;
}
}
$categories = array_reverse($categories);
unset($categories[count($categories) - 1]);
return $categories;
}
} }

View File

@ -1,30 +1,8 @@
<?php namespace Visiosoft\CatsModule\Category; <?php namespace Visiosoft\CatsModule\Category;
use Anomaly\Streams\Platform\Entry\EntryPresenter; use Anomaly\Streams\Platform\Entry\EntryPresenter;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
class CategoryPresenter extends EntryPresenter class CategoryPresenter extends EntryPresenter
{ {
public function getAdvsListUrl($attributes)
{
return \route('visiosoft.module.advs::list', "cat=" . $attributes);
}
public function getCategoryName($id)
{
$category = $this->find($id);
return $category->name;
}
public function getname($id)
{
$cat = CatsCategoryEntryModel::query()->find($id);
return $cat->name;
}
public function getMains($id)
{
$category_model = new CategoryModel();
return $category_model->getMains($id);
}
} }

View File

@ -1,9 +1,9 @@
<?php namespace Visiosoft\CatsModule\Category; <?php namespace Visiosoft\CatsModule\Category;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
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;
use Visiosoft\CatsModule\Category\Events\DeletedCategory;
class CategoryRepository extends EntryRepository implements CategoryRepositoryInterface class CategoryRepository extends EntryRepository implements CategoryRepositoryInterface
{ {
@ -14,7 +14,6 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
* @var CategoryModel * @var CategoryModel
*/ */
protected $model; protected $model;
protected $advRepository;
/** /**
* Create a new CategoryRepository instance. * Create a new CategoryRepository instance.
@ -22,38 +21,64 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
* @param CategoryModel $model * @param CategoryModel $model
* @param AdvRepositoryInterface $advRepository * @param AdvRepositoryInterface $advRepository
*/ */
public function __construct(CategoryModel $model, AdvRepositoryInterface $advRepository) public function __construct(CategoryModel $model)
{ {
$this->model = $model; $this->model = $model;
$this->advRepository = $advRepository;
} }
public function findById($id) public function deleteSubCategories($id)
{ {
return $this->model->orderBy('created_at', 'DESC')->where('cats_category.id', $id)->first(); $sub = $this->getSubCategories($id);
for ($i = 0; $i <= count($sub) - 1; $i++) {
$sub = array_merge($sub, $this->getSubCategories($sub[$i]));
}
if (count($sub)) {
$this->newQuery()->whereIn('id', $sub)->delete();
}
return true;
} }
public function mainCats() public function deleteCategories($id)
{ {
return $this->newQuery() if ($category = $this->find($id)) {
->whereNull('parent_category_id') $category->delete();
->orderBy('sort_order')
event(new DeletedCategory($category, $this->getParents($id)));
$this->deleteSubCategories($id);
}
}
public function skipAndTake($take, $skip)
{
$this->newQuery()
->skip($take * $skip)
->take($take)
->get(); ->get();
} }
public function getItem($cat) public function getParents($id)
{ {
return $this->model->where('cats_category.id', $cat)->first(); $category = $this->find($id);
$z = 1;
$categories = [$category];
for ($i = 0; $i < $z; $i++) {
if ($category = $this->find($category->parent_category_id)) {
$categories[] = $category;
if (!$category->parent_category_id) {
break;
}
$z++;
}
}
return $categories;
} }
public function getCatById($id) public function getSubCategories($id)
{ {
return $this->model->where('cats_category.id', $id)->where('deleted_at', null)->orderBy('sort_order')->get(); $cats = $this->newQuery()
}
public function getSubCatById($id)
{
$cats = $this->model->newQuery()
->where('parent_category_id', $id) ->where('parent_category_id', $id)
->get(); ->get();
@ -61,54 +86,67 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
$subCount = $this->model->newQuery()->where('parent_category_id', $cat->id)->count(); $subCount = $this->model->newQuery()->where('parent_category_id', $cat->id)->count();
$cat->hasChild = !!$subCount; $cat->hasChild = !!$subCount;
} }
return $cats; return $cats;
} }
public function getSingleCat($id) public function getMainCategories()
{ {
return CatsCategoryEntryModel::query()->where('cats_category.id', $id)->first(); return $this->newQuery()->whereNull('parent_category_id')->get();
} }
public function findBySlug($slug) public function getCategoryTextSeo($categories)
{ {
return $this->model->orderBy('created_at', 'DESC')->where('slug', $slug)->first(); if (count($categories) == 1 || count($categories) == 2) {
} $catText = end($mainCats)['name'];
} elseif (count($categories) > 2) {
public function getCategories() $catArray = array_slice($categories->toArray(), 2);
{ $catText = '';
return $this->model->orderBy('sort_order')->get(); $loop = 0;
} foreach ($catArray as $cat) {
$catText = !$loop ? $catText . $cat['name'] : $catText . ' ' . $cat['name'];
public function removeCatFromAds($category) $loop++;
{
$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();
foreach ($advs as $adv) {
$nullableCats = array();
for ($i = $catLevelNum; $i <= 10; $i++) {
$nullableCats['cat' . $i] = null;
} }
$adv->update($nullableCats);
} }
} }
public function DeleteCategories($id) public function setQuerySearchingAds($query, $category)
{ {
if (!is_null($category = $this->find($id))) { $catLevel = "cat" . (!$category->parent_category_id) ? 1 : count($this->getParents($category->id));
// Remove deleted category from ads
$this->removeCatFromAds($category);
// Delete the category return $query->where($catLevel, $category->id);
$this->model->find($id)->delete(); }
// Delete the subcategories public function searchKeyword($keyword, $selected = null)
$this->model->deleteSubCategories($id); {
$data = [];
$cats = $this->newQuery();
if ($selected) {
if (strpos($selected, "-") !== false) {
$cats = $cats->whereNotIn('id', explode('-', $selected));
} else {
$cats = $cats->where('id', '!=', $selected);
}
} }
$cats = $cats->where('name', 'like', $keyword . '%')
->orderBy('id', 'DESC')
->get();
foreach ($cats as $cat) {
$link = '';
$parents = $this->getParents($cat->id);
krsort($parents);
foreach ($parents as $key => $parent) {
$link .= ($key == 0) ? $parent->name . '' : $parent->name . ' > ';
}
$data[] = array(
'id' => $cat->id,
'name' => $cat->name,
'parents' => $link
);
}
return $data;
} }
} }

View File

@ -1,38 +0,0 @@
<?php namespace Visiosoft\CatsModule\Category\Command;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
class GetCategoryDetail
{
/**
* @var $id
*/
protected $id;
/**
* GetProduct constructor.
* @param $id
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* @param CategoryRepositoryInterface $groups
* @return |null
*/
public function handle(CategoryRepositoryInterface $groups)
{
if ($this->id) {
$category = $groups->find($this->id);
if (!is_null($category))
return $category;
else
return null;
}
return null;
}
}

View File

@ -1,38 +0,0 @@
<?php namespace Visiosoft\CatsModule\Category\Command;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
class GetCategoryName
{
/**
* @var $id
*/
protected $id;
/**
* GetProduct constructor.
* @param $id
*/
public function __construct($id)
{
$this->id = $id;
}
/**
* @param CategoryRepositoryInterface $groups
* @return |null
*/
public function handle(CategoryRepositoryInterface $groups)
{
if ($this->id) {
$category = $groups->find($this->id);
if (!is_null($category))
return $category->name;
else
return null;
}
return null;
}
}

View File

@ -4,21 +4,21 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
interface CategoryRepositoryInterface extends EntryRepositoryInterface interface CategoryRepositoryInterface extends EntryRepositoryInterface
{ {
public function findById($id); public function deleteSubCategories($id);
public function mainCats(); public function deleteCategories($id);
public function getItem($cat); public function skipAndTake($take, $skip);
public function getCatById($id); public function getParents($id);
public function getSubCatById($id); public function getSubCategories($id);
public function getSingleCat($id); public function getMainCategories();
public function findBySlug($slug); public function getCategoryTextSeo($categories);
public function getCategories(); public function setQuerySearchingAds($query, $category);
public function DeleteCategories($id); public function searchKeyword($keyword, $selected = null);
} }

View File

@ -0,0 +1,25 @@
<?php namespace Visiosoft\CatsModule\Category\Events;
class DeletedCategory
{
public $category;
public $parents;
public function __construct($category, $parents)
{
$this->category = $category;
$this->parents = $parents;
}
public function getCategory()
{
return $this->category;
}
public function getParents()
{
$this->getParents();
}
}

View File

@ -5,62 +5,4 @@ use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
class CategoryFormBuilder extends FormBuilder class CategoryFormBuilder extends FormBuilder
{ {
/**
* The form fields.
*
* @var array|string
*/
protected $fields = [];
/**
* Additional validation rules.
*
* @var array|string
*/
protected $rules = [];
/**
* Fields to skip.
*
* @var array|string
*/
protected $skips = [];
/**
* The form actions.
*
* @var array|string
*/
protected $actions = [];
/**
* The form buttons.
*
* @var array|string
*/
protected $buttons = [
'cancel',
];
/**
* The form options.
*
* @var array
*/
protected $options = [];
/**
* The form sections.
*
* @var array
*/
protected $sections = [];
/**
* The form assets.
*
* @var array
*/
protected $assets = [];
} }

View File

@ -19,15 +19,6 @@ class CategoryTableBuilder extends TableBuilder
], ],
]; ];
/**
* The table filters.
*
* @var array|string
*/
protected $filters = [
];
/** /**
* The table columns. * The table columns.
* *

View File

@ -2,14 +2,10 @@
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler; use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface; use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CatsModule\Category\Table\CategoryTableBuilder;
class Delete extends ActionHandler class Delete extends ActionHandler
{ {
public function handle( public function handle(array $selected, CategoryRepositoryInterface $categoryRepository)
CategoryTableBuilder $builder, array $selected,
CategoryRepositoryInterface $categoryRepository
)
{ {
try { try {
foreach ($selected as $id) { foreach ($selected as $id) {

View File

@ -30,11 +30,6 @@ class CatsModule extends Module
'new_category', 'new_category',
], ],
], ],
'placeholderforsearch' => [
'buttons' => [
'new_placeholderforsearch',
],
],
]; ];
} }

View File

@ -1,50 +1,32 @@
<?php namespace Visiosoft\CatsModule; <?php namespace Visiosoft\CatsModule;
use Anomaly\Streams\Platform\Addon\Plugin\Plugin; use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
use Visiosoft\CatsModule\Category\CategoryModel; use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CatsModule\Category\Command\GetCategoryName;
use Visiosoft\CatsModule\Category\Command\GetCategoryDetail;
class CatsModulePlugin extends Plugin class CatsModulePlugin extends Plugin
{ {
public $categoryRepository;
public function __construct(CategoryRepositoryInterface $categoryRepository)
{
$this->categoryRepository = $categoryRepository;
}
/**
* @return array
*/
public function getFunctions() public function getFunctions()
{ {
return [ return [
new \Twig_SimpleFunction( new \Twig_SimpleFunction(
'category_name', 'findCategory',
function ($id) { function ($id) {
if (!$category = $this->categoryRepository->find($id)) {
if (!$ad = $this->dispatch(new GetCategoryName($id))) {
return null; return null;
} }
return $category;
return $ad;
} }
), new \Twig_SimpleFunction( ), new \Twig_SimpleFunction(
'category_detail', 'getParents',
function ($id) { function ($id) {
return $this->categoryRepository->getParents($id);
if (!$ad = $this->dispatch(new GetCategoryDetail($id))) {
return null;
}
return $ad;
}
), new \Twig_SimpleFunction(
'category_parents_name',
function ($id) {
$category_model = new CategoryModel();
return $category_model->getParentCats($id,'add_main');
}
), new \Twig_SimpleFunction(
'getParentsCount',
function ($id) {
$category_model = new CategoryModel();
return $category_model->getParentsCount($id);
} }
) )
]; ];

View File

@ -1,7 +1,6 @@
<?php namespace Visiosoft\CatsModule; <?php namespace Visiosoft\CatsModule;
use Anomaly\Streams\Platform\Database\Seeder\Seeder; use Anomaly\Streams\Platform\Database\Seeder\Seeder;
use Visiosoft\CatsModule\Placeholderforsearch\PlaceholderforsearchSeeder;
class CatsModuleSeeder extends Seeder class CatsModuleSeeder extends Seeder
{ {
@ -10,6 +9,5 @@ class CatsModuleSeeder extends Seeder
*/ */
public function run() public function run()
{ {
$this->call(PlaceholderforsearchSeeder::class);
} }
} }

View File

@ -1,10 +1,6 @@
<?php namespace Visiosoft\CatsModule; <?php namespace Visiosoft\CatsModule;
use Anomaly\Streams\Platform\Addon\AddonServiceProvider; use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
use Visiosoft\CatsModule\Placeholderforsearch\Contract\PlaceholderforsearchRepositoryInterface;
use Visiosoft\CatsModule\Placeholderforsearch\PlaceholderforsearchRepository;
use Anomaly\Streams\Platform\Model\Cats\CatsPlaceholderforsearchEntryModel;
use Visiosoft\CatsModule\Placeholderforsearch\PlaceholderforsearchModel;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface; use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CatsModule\Category\CategoryRepository; use Visiosoft\CatsModule\Category\CategoryRepository;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel; use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
@ -51,9 +47,6 @@ class CatsModuleServiceProvider extends AddonServiceProvider
*/ */
protected $routes = [ protected $routes = [
'admin/cats/clean_subcats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@cleanSubcats', 'admin/cats/clean_subcats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@cleanSubcats',
'admin/cats/placeholderforsearch' => 'Visiosoft\CatsModule\Http\Controller\Admin\PlaceholderforsearchController@index',
'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' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@index', 'admin/cats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@index',
'admin/cats/create' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@create', 'admin/cats/create' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@create',
'admin/cats/edit/{id}' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@edit', 'admin/cats/edit/{id}' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@edit',
@ -117,7 +110,6 @@ class CatsModuleServiceProvider extends AddonServiceProvider
* @type array|null * @type array|null
*/ */
protected $bindings = [ protected $bindings = [
CatsPlaceholderforsearchEntryModel::class => PlaceholderforsearchModel::class,
CatsCategoryEntryModel::class => CategoryModel::class, CatsCategoryEntryModel::class => CategoryModel::class,
]; ];
@ -127,7 +119,6 @@ class CatsModuleServiceProvider extends AddonServiceProvider
* @type array|null * @type array|null
*/ */
protected $singletons = [ protected $singletons = [
PlaceholderforsearchRepositoryInterface::class => PlaceholderforsearchRepository::class,
CategoryRepositoryInterface::class => CategoryRepository::class, CategoryRepositoryInterface::class => CategoryRepository::class,
]; ];
@ -203,11 +194,6 @@ class CatsModuleServiceProvider extends AddonServiceProvider
], ],
], ],
], ],
'placeholderforsearch' => [
'buttons' => [
'new_placeholderforsearch',
],
],
]; ];
$this->addon->setSections($sections); $this->addon->setSections($sections);
} }

View File

@ -31,15 +31,8 @@ class CategoryController extends AdminController
public function index(CategoryTableBuilder $table, Request $request) public function index(CategoryTableBuilder $table, Request $request)
{ {
if ($this->request->action == "delete") { if ($request->cat || $request->cat == "") {
$CategoriesModel = new CategoryModel(); $categories = $this->categoryRepository->getMainCategories();
foreach ($this->request->id as $item) {
$CategoriesModel->deleteSubCategories($item);
}
}
if (!isset($request->cat) || $request->cat == "") {
$categories = CategoryModel::query()->where('parent_category_id', '')->orWhereNull('parent_category_id')->get();
$categories = $categories->where('deleted_at', null);
} else { } else {
$categories = CategoryModel::query()->where('parent_category_id', $request->cat)->whereNull('deleted_at')->get(); $categories = CategoryModel::query()->where('parent_category_id', $request->cat)->whereNull('deleted_at')->get();
} }

View File

@ -1,43 +0,0 @@
<?php namespace Visiosoft\CatsModule\Http\Controller\Admin;
use Visiosoft\CatsModule\Placeholderforsearch\Form\PlaceholderforsearchFormBuilder;
use Visiosoft\CatsModule\Placeholderforsearch\Table\PlaceholderforsearchTableBuilder;
use Anomaly\Streams\Platform\Http\Controller\AdminController;
class PlaceholderforsearchController extends AdminController
{
/**
* Display an index of existing entries.
*
* @param PlaceholderforsearchTableBuilder $table
* @return \Symfony\Component\HttpFoundation\Response
*/
public function index(PlaceholderforsearchTableBuilder $table)
{
return $table->render();
}
/**
* Create a new entry.
*
* @param PlaceholderforsearchFormBuilder $form
* @return \Symfony\Component\HttpFoundation\Response
*/
public function create(PlaceholderforsearchFormBuilder $form)
{
return $form->render();
}
/**
* Edit an existing entry.
*
* @param PlaceholderforsearchFormBuilder $form
* @param $id
* @return \Symfony\Component\HttpFoundation\Response
*/
public function edit(PlaceholderforsearchFormBuilder $form, $id)
{
return $form->render($id);
}
}

View File

@ -7,77 +7,70 @@ use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
class SitemapController extends PublicController class SitemapController extends PublicController
{ {
private $categoryRepository; private $category;
private $cityRepository; private $city;
public function __construct( public function __construct(
CategoryRepositoryInterface $categoryRepository, CategoryRepositoryInterface $category,
CityRepositoryInterface $cityRepository CityRepositoryInterface $city
) )
{ {
parent::__construct(); parent::__construct();
$this->categoryRepository = $categoryRepository; $this->category = $category;
$this->cityRepository = $cityRepository; $this->city = $city;
} }
public function index() public function index()
{ {
$categoriesCount = $this->categoryRepository->count(); $categoriesCount = $this->category->count();
$include_cities_sitemap = setting_value('visiosoft.module.cats::include_cities_sitemap');
$sitemap_dividing_number = setting_value('visiosoft.module.cats::sitemap_dividing_number');
if (setting_value('visiosoft.module.cats::include_cities_sitemap')) { if ($include_cities_sitemap) {
$citiesCount = $this->cityRepository->count(); $citiesCount = $this->city->count();
$pagesCount = $citiesCount ? $categoriesCount * $citiesCount : $categoriesCount; $pagesCount = $citiesCount ? $categoriesCount * $citiesCount : $categoriesCount;
} else { } else {
$pagesCount = $categoriesCount; $pagesCount = $categoriesCount;
} }
$pagesCount = ceil($pagesCount / setting_value('visiosoft.module.cats::sitemap_dividing_number')); $pagesCount = ceil($pagesCount / $sitemap_dividing_number);
return response()->view('visiosoft.module.cats::sitemap.index', [ return $this->response->view('visiosoft.module.cats::sitemap.index', compact('pagesCount'))
'pagesCount' => $pagesCount, ->header('Content - Type', 'text / xml');
])->header('Content-Type', 'text/xml');
} }
public function categories() public function categories()
{ {
$sitemapDividingNumber = setting_value('visiosoft.module.cats::sitemap_dividing_number');
$page = request()->page ?: 1; $page = request()->page ?: 1;
$skip = $page - 1; $skip = $page - 1;
$sitemapLinks = array();
$sitemap_dividing_number = setting_value('visiosoft.module.cats::sitemap_dividing_number');
$include_cities_sitemap = setting_value('visiosoft.module.cats::include_cities_sitemap');
if (setting_value('visiosoft.module.cats::include_cities_sitemap')
&& $citiesCount = $this->cityRepository->count()) {
$categoriesCount = $this->categoryRepository->count();
$takeCategories = $categoriesCount / ($categoriesCount * $citiesCount / $sitemapDividingNumber); if ($citiesCount = $this->city->count() && $include_cities_sitemap) {
$categoriesCount = $this->category->count();
$categories = $this->categoryRepository $take = $categoriesCount / ($categoriesCount * $citiesCount / $sitemap_dividing_number);
->newQuery()
->skip($takeCategories * $skip) $categories = $this->category->skipAndTake($take, $skip);
->take($takeCategories)
->get(); $cities = $this->city->all();
$sitemapLinks = array();
$cities = $this->cityRepository->all();
foreach ($categories as $category) { foreach ($categories as $category) {
foreach ($cities as $city) { foreach ($cities as $city) {
$sitemapLinks[] = route('adv_list_seo', [$category->slug, $city->slug]); $sitemapLinks[] = route('adv_list_seo', [$category->slug, $city->slug]);
} }
} }
} else { } else {
$categories = $this->categoryRepository $categories = $this->category->skipAndTake($sitemap_dividing_number, $skip);
->newQuery()
->skip($sitemapDividingNumber * $skip)
->take($sitemapDividingNumber)
->get();
$sitemapLinks = array();
foreach ($categories as $category) { foreach ($categories as $category) {
$sitemapLinks[] = route('adv_list_seo', [$category->slug]); $sitemapLinks[] = route('adv_list_seo', [$category->slug]);
} }
} }
return response()->view('visiosoft.module.cats::sitemap.categories', [ return response()->view('visiosoft.module.cats::sitemap.categories', compact('sitemapLinks'))
'sitemapLinks' => $sitemapLinks, ->header('Content - Type', 'text / xml');
])->header('Content-Type', 'text/xml');
} }
} }

View File

@ -1,8 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch\Contract;
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
interface PlaceholderforsearchInterface extends EntryInterface
{
}

View File

@ -1,8 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch\Contract;
use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
interface PlaceholderforsearchRepositoryInterface extends EntryRepositoryInterface
{
}

View File

@ -1,66 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch\Form;
use Anomaly\Streams\Platform\Ui\Form\FormBuilder;
class PlaceholderforsearchFormBuilder extends FormBuilder
{
/**
* The form fields.
*
* @var array|string
*/
protected $fields = [];
/**
* Additional validation rules.
*
* @var array|string
*/
protected $rules = [];
/**
* Fields to skip.
*
* @var array|string
*/
protected $skips = [];
/**
* The form actions.
*
* @var array|string
*/
protected $actions = [];
/**
* The form buttons.
*
* @var array|string
*/
protected $buttons = [
'cancel',
];
/**
* The form options.
*
* @var array
*/
protected $options = [];
/**
* The form sections.
*
* @var array
*/
protected $sections = [];
/**
* The form assets.
*
* @var array
*/
protected $assets = [];
}

View File

@ -1,8 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch;
use Anomaly\Streams\Platform\Entry\EntryCollection;
class PlaceholderforsearchCollection extends EntryCollection
{
}

View File

@ -1,8 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch;
use Anomaly\Streams\Platform\Entry\EntryCriteria;
class PlaceholderforsearchCriteria extends EntryCriteria
{
}

View File

@ -1,9 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch;
use Visiosoft\CatsModule\Placeholderforsearch\Contract\PlaceholderforsearchInterface;
use Anomaly\Streams\Platform\Model\Cats\CatsPlaceholderforsearchEntryModel;
class PlaceholderforsearchModel extends CatsPlaceholderforsearchEntryModel implements PlaceholderforsearchInterface
{
}

View File

@ -1,8 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch;
use Anomaly\Streams\Platform\Entry\EntryObserver;
class PlaceholderforsearchObserver extends EntryObserver
{
}

View File

@ -1,8 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch;
use Anomaly\Streams\Platform\Entry\EntryPresenter;
class PlaceholderforsearchPresenter extends EntryPresenter
{
}

View File

@ -1,25 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch;
use Visiosoft\CatsModule\Placeholderforsearch\Contract\PlaceholderforsearchRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository;
class PlaceholderforsearchRepository extends EntryRepository implements PlaceholderforsearchRepositoryInterface
{
/**
* The entry model.
*
* @var PlaceholderforsearchModel
*/
protected $model;
/**
* Create a new PlaceholderforsearchRepository instance.
*
* @param PlaceholderforsearchModel $model
*/
public function __construct(PlaceholderforsearchModel $model)
{
$this->model = $model;
}
}

View File

@ -1,8 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch;
use Anomaly\Streams\Platform\Entry\EntryRouter;
class PlaceholderforsearchRouter extends EntryRouter
{
}

View File

@ -1,49 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch;
use Anomaly\Streams\Platform\Database\Seeder\Seeder;
use Illuminate\Support\Facades\DB;
class PlaceholderforsearchSeeder extends Seeder
{
/**
* Run the seeder.
*/
public function run()
{
DB::table('cats_placeholderforsearch')->truncate();
DB::table('cats_placeholderforsearch_translations')->truncate();
PlaceholderforsearchModel::create([
'en' => [
'name' => 'Chevrolet Camaro'
],
'tr' => [
'name' => 'Chevrolet Camaro'
]
]);
PlaceholderforsearchModel::create([
'en' => [
'name' => 'Xiaomi Black Shark 128 GB'
],
'tr' => [
'name' => 'Xiaomi Black Shark 128 GB'
]
]);
PlaceholderforsearchModel::create([
'en' => [
'name' => 'Apple MacBook Pro'
],
'tr' => [
'name' => 'Apple MacBook Pro'
]
]);
PlaceholderforsearchModel::create([
'en' => [
'name' => 'Make your search now'
],
'tr' => [
'name' => 'Make your search now'
]
]);
}
}

View File

@ -1,61 +0,0 @@
<?php namespace Visiosoft\CatsModule\Placeholderforsearch\Table;
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
class PlaceholderforsearchTableBuilder extends TableBuilder
{
/**
* The table views.
*
* @var array|string
*/
protected $views = [];
/**
* The table filters.
*
* @var array|string
*/
protected $filters = [];
/**
* The table columns.
*
* @var array|string
*/
protected $columns = [];
/**
* The table buttons.
*
* @var array|string
*/
protected $buttons = [
'edit'
];
/**
* The table actions.
*
* @var array|string
*/
protected $actions = [
'delete'
];
/**
* The table options.
*
* @var array
*/
protected $options = [];
/**
* The table assets.
*
* @var array
*/
protected $assets = [];
}