Merge pull request #993 from openclassify/fatihalp

New version 2.0 Beta
This commit is contained in:
Fatih Alp 2021-04-15 15:08:22 +03:00 committed by GitHub
commit e4ebd1d812
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
151 changed files with 1976 additions and 1608 deletions

View File

@ -1,4 +1,10 @@
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3307
DB_DATABASE=oc
DB_USERNAME=root
DB_PASSWORD=""
APP_NAME="OpenClassify"
FORCE_SSL=0
@ -13,13 +19,15 @@ DEFAULT_LOCALE="en"
ENABLED_LOCALES='a:1:{i:0;s:2:"en";}'
MAINTENANCE_MODE=0
MAINTENANCE_AUTH=0
FROM_ADDRESS="support@demo.openclassify.com"
FROM_ADDRESS="info@openclassify.com"
FROM_NAME="OpenClassify"
MAIL_DRIVER="smtp"
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME="029f2d0c9099d9"
MAIL_PASSWORD="8252f6d1c2ca42"
HTTP_CACHE=0
HTTP_CACHE_TTL=3600
HTTP_CACHE_ALLOW_BOTS=0

View File

@ -8,12 +8,5 @@
"files": [
"src/Support/_helpers.php"
]
},
"require": {
"wirelab/language_switcher-plugin": "^1.3",
"visiosoft/addblock-extension": "^1.1",
"ext-zip": "*",
"chumper/zipper": "^1.0",
"sentry/sentry-laravel": "2.3.1"
}
}

View File

@ -1,26 +0,0 @@
<?php
use Anomaly\Streams\Platform\Database\Migration\Migration;
class VisiosoftModuleAdvsCreateUserStatusField extends Migration
{
protected $delete = false;
protected $stream = [
'slug' => 'advs',
];
protected $fields = [
"user_status" => [
"type" => "anomaly.field_type.relationship",
"config" => [
"related" => \Visiosoft\AdvsModule\Status\StatusModel::class,
"mode" => "lookup",
]
],
];
protected $assignments = [
'user_status',
];
}

View File

@ -98,7 +98,7 @@ return [
'type' => 'anomaly.field_type.checkboxes',
'config' => [
'options' => function (\Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface $categoryRepository) {
return $categoryRepository->mainCats()->pluck('name', 'id')->all();
return $categoryRepository->getMainCategories()->pluck('name', 'id')->all();
},
],
],
@ -399,7 +399,7 @@ return [
'type' => 'anomaly.field_type.checkboxes',
'config' => [
'options' => function (\Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface $categoryRepository) {
return $categoryRepository->mainCats()->pluck('name', 'id')->all();
return $categoryRepository->getMainCategories()->pluck('name', 'id')->all();
},
],
],

View File

@ -126,4 +126,4 @@ function scroolToSelect(fields) {
$([document.documentElement, document.body]).animate({
scrollTop: $(fields[fields.length - 1]).offset().top + 300
}, 1000);
}
}

View File

@ -24,25 +24,25 @@
{% include 'visiosoft.module.cats::ads-list/partials/cat-filter' %}
</div>
{{ addBlock('ads-list/partials/list-filter',{
'mainCats':mainCats,
'subCats':subCats,
'ranges':ranges,
'checkboxes':checkboxes,
'topfields' : topfields,
'selectDropdown' : selectDropdown,
'selectRange' : selectRange,
'selectImage' : selectImage,
'radio':radio,
'countries':countries,
'cities':cities,
'districts':districts,
'neighborhoods':neighborhoods,
'villages':villages,
'param':param,
'categoryId':categoryId,
'cityId':cityId
})|raw }}
{{ addBlock('ads-list/partials/list-filter',{
'mainCats':mainCats,
'subCats':subCats,
'ranges':ranges,
'checkboxes':checkboxes,
'topfields' : topfields,
'selectDropdown' : selectDropdown,
'selectRange' : selectRange,
'selectImage' : selectImage,
'radio':radio,
'countries':countries,
'cities':cities,
'districts':districts,
'neighborhoods':neighborhoods,
'villages':villages,
'param':param,
'category':category,
'cityId':cityId
})|raw }}
<!-- Price Filter Start -->
{% include 'visiosoft.module.advs::list/partials/price-filter' %}

View File

@ -1,14 +1,16 @@
{% set isHidden = false %}
{% for cat in cats %}
{% if request().segment(2) == cat.slug %}
{% set isHidden = true %}
{% endif %}
{% endfor %}
{% if setting_value('visiosoft.module.advs::hide_price_filter') == false and not isHidden%}
{% set hidePriceCats = setting_value('visiosoft.module.advs::hide_price_categories') %}
{% set hidePriceCats = setting_value('visiosoft.module.advs::hide_price_categories') %}
{% if (hidePriceCats != null) %}
{% set cats = entries('cats','category').whereIn('id', hidePriceCats).get() %}
{% set isHidden = false %}
{% for cat in cats %}
{% if request().segment(2) == cat.slug %}
{% set isHidden = true %}
{% endif %}
{% endfor %}
{% endif %}
{% if setting_value('visiosoft.module.advs::hide_price_filter') == false and not isHidden %}
{% set active_currencies = setting_value('visiosoft.module.advs::enabled_currencies') %}
<div id="price" class="border rounded filter-box p-3 mb-3">

View File

@ -38,4 +38,4 @@
{{ asset_add("scripts.js", "visiosoft.module.advs::js/edit_cats.js") }}
{{ asset_style("visiosoft.module.advs::css/edit_category.css") }}
{% endblock %}
{% endblock %}

View File

@ -208,7 +208,7 @@
</div>
</div>
</div>
{% set other_fields = addBlock('new-ad/other-fields',{'custom_fields':custom_fields}) %}
{% set other_fields = addBlock('new-ad/other-fields',{'custom_fields':custom_fields,'id':id}) %}
{% if other_fields or (custom_fields and count(custom_fields)) %}
<h5 class="mt-5 pb-1 border-bottom">
{{ trans('visiosoft.module.advs::field.additional_fields') }}

View File

@ -91,7 +91,7 @@ class AdvCriteria extends EntryCriteria
public function countAdsByCategoryId($catId, $level = 1)
{
return $this->advRepository->countByCat($catId, $level);
return $this->advRepository->getAdsCountByCategory($catId, $level);
}
public function getCurrentLocale()

View File

@ -10,7 +10,7 @@ use Visiosoft\AdvsModule\Adv\Contract\AdvInterface;
use Anomaly\Streams\Platform\View\ViewTemplate;
use Visiosoft\CatsModule\Category\Contract\CategoryInterface;
use Visiosoft\LocationModule\City\Contract\CityInterface;
use Visiosoft\LocationModule\Country\Contract\CountryInterface;
use Visiosoft\LocationModule\Country\Contract\CountryRepositoryInterface;
class AdvLoader {
@ -21,8 +21,8 @@ class AdvLoader {
$this->template = $template;
}
public function load(AdvInterface $adv, CategoryInterface $cats, CityInterface $city, CountryInterface $country) {
public function load(AdvInterface $adv, CategoryInterface $cats, CityInterface $city, CountryRepositoryInterface $country) {
$this->template->set('adv', $adv);
$this->template->set('country', $country->getCountry($adv->country_id));
$this->template->set('country', $country->find($adv->country_id));
}
}

View File

@ -10,6 +10,7 @@ use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository;
use Visiosoft\AdvsModule\Support\Command\Currency;
use Visiosoft\CatsModule\Category\CategoryModel;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\LocationModule\Country\CountryModel;
use Visiosoft\LocationModule\District\DistrictModel;
@ -31,11 +32,6 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
$this->folderRepository = $folderRepository;
}
public function findById($id)
{
return $this->model->orderBy('created_at', 'DESC')->where('advs_advs.id', $id)->first();
}
public function searchAdvs(
$type, $param = null, $customParameters = [],
$limit = null, $category = null, $city = null, $paginate = true
@ -89,16 +85,11 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
}
}
if ($category) {
$cat = new CategoryModel();
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);
}
$category_repository = app(CategoryRepositoryInterface::class);
$catLevel = $category_repository->getLevelById($category->id);
$catLevel = "cat" . $catLevel;
$query = $query->where($catLevel, $category->id);
}
if (!empty($param['user'])) {
$query = $query->where('advs_advs.created_by_id', $param['user']);
@ -308,7 +299,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
$thumbnail = $this->fileRepository->findByNameAndFolder($fileName, $folder);
if (!$thumbnail) {
// Create thumbnail image
$image = Image::make(file_get_contents($adv->files[0]->url()));
$image = Image::make(file_get_contents($adv->files[0]->make()->url()));
$image->resize(
null,
setting_value('visiosoft.module.advs::thumbnail_height'),
@ -431,7 +422,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
return $ads;
}
public function countByCat($catID, $level = 1)
public function getAdsCountByCategory($catID, $level = 1)
{
return DB::table('advs_advs')
->whereDate('finish_at', '>=', date("Y-m-d H:i:s"))

View File

@ -16,6 +16,6 @@ class AdvResolver {
}
public function resolve() {
return $this->adv->findById($this->route->parameter('id'));
return $this->adv->find($this->route->parameter('id'));
}
}

View File

@ -27,7 +27,7 @@ class GetAd
public function handle(AdvRepositoryInterface $groups)
{
if ($this->id) {
return $groups->findById($this->id);
return $groups->find($this->id);
}
return null;
}

View File

@ -4,8 +4,6 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
interface AdvRepositoryInterface extends EntryRepositoryInterface
{
public function findById($id);
public function searchAdvs(
$type, $param = null, $customParameters = null,
$limit = null, $category = null, $city = null, $paginate = true
@ -39,7 +37,7 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
public function getByCat($catID, $level = 1, $limit = 20);
public function countByCat($catID, $level = 1);
public function getAdsCountByCategory($catID, $level = 1);
public function getCategoriesWithAdID($id);

View File

@ -1,12 +1,10 @@
<?php namespace Visiosoft\AdvsModule\Adv\Event;
use Visiosoft\AdvsModule\Adv\AdvModel;
class ChangedStatusAd
{
private $ad;
public function __construct(AdvModel $ad)
public function __construct($ad)
{
$this->ad = $ad;
}

View File

@ -1,17 +1,21 @@
<?php namespace Visiosoft\AdvsModule\Adv\Event;
class DeletedAd
{
protected $entry;
private $ad;
public function __construct($entry)
public function __construct($ad)
{
$this->entry = $entry;
$this->ad = $ad;
}
public function getAdDetail()
{
return $this->ad;
}
public function getEntry()
{
return $this->entry;
return $this->ad;
}
}

View File

@ -3,15 +3,13 @@
class EditAd
{
public function __construct($request, $settings, $adv)
public function __construct($ad)
{
$this->request = $request;
$this->settings = $settings;
$this->adv = $adv;
$this->ad = $ad;
}
public function getRequest()
public function getAd()
{
return $this;
return $this->ad;
}
}

View File

@ -0,0 +1,23 @@
<?php namespace Visiosoft\AdvsModule\Adv\Event;
class EditedAd
{
private $ad;
private $before_editing;
public function __construct($before_editing, $ad)
{
$this->ad = $ad;
$this->before_editing = $before_editing;
}
public function getAdDetail()
{
return $this->ad;
}
public function getBeforeEditingDetail()
{
return $this->before_editing;
}
}

View File

@ -0,0 +1,23 @@
<?php namespace Visiosoft\AdvsModule\Adv\Event;
class EditedAdCategory
{
private $ad;
private $before_editing;
public function __construct($before_editing_ad_params, $ad)
{
$this->ad = $ad;
$this->before_editing_ad_params = $before_editing_ad_params;
}
public function getAdDetail()
{
return $this->ad;
}
public function getBeforeEditingParams()
{
return $this->before_editing_ad_params;
}
}

View File

@ -1,7 +1,7 @@
<?php namespace Visiosoft\AdvsModule\Adv\Event;
class priceChange
class PriceChange
{
public function __construct($request)
{

View File

@ -1,7 +1,7 @@
<?php namespace Visiosoft\AdvsModule\Adv\Event;
class showAdPhone
class ShowAdPhone
{
public function __construct($request)
{

View File

@ -1,7 +1,7 @@
<?php namespace Visiosoft\AdvsModule\Adv\Event;
class viewAd
class ViewAd
{
public function __construct($request)
{

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

@ -27,7 +27,9 @@ class AdvTableBuilder extends TableBuilder
protected $buttons = [];
protected $actions = [
'delete',
'delete' => [
'handler' => \Visiosoft\AdvsModule\Adv\Table\Handler\Delete::class,
],
'approve' => [
'handler' => \Visiosoft\AdvsModule\Adv\Table\Handler\Approve::class,
'class' => 'btn btn-success'
@ -49,8 +51,7 @@ class AdvTableBuilder extends TableBuilder
protected $options = [
'order_by' => [
'id' => 'DESC',
],
'table_view' => 'visiosoft.module.advs::admin/table/table'
]
];
protected $assets = [

View File

@ -3,6 +3,7 @@
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
use Anomaly\Streams\Platform\Entry\EntryModel;
use Visiosoft\CatsModule\Category\CategoryModel;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
class AdvTableColumns
{
@ -39,10 +40,11 @@ class AdvTableColumns
}
return $value;
},
'category' => function (EntryInterface $entry, CategoryModel $categoryModel) {
$category = $categoryModel->getCat($entry->cat1);
if (!is_null($category))
'category' => function (EntryInterface $entry, CategoryRepositoryInterface $categoryRepository) {
$category = $categoryRepository->find($entry->cat1);
if ($category){
return $category->name;
}
}
],
],

View File

@ -14,7 +14,7 @@ class AdvTableFilters
{
$cities = $cityRepository->all()->pluck('name', 'id')->all();
$categories = $categoryRepository->mainCats()->pluck('name', 'id')->all();
$categories = $categoryRepository->getMainCategories()->pluck('name', 'id')->all();
$builder->setFilters(
[

View File

@ -15,14 +15,16 @@ class Approve extends ActionHandler
foreach ($selected as $id) {
$defaultAdPublishTime = $settingRepository->value('visiosoft.module.advs::default_published_time');
$ad = $model->newQuery()->find($id);
$ad->update([
'status' => 'approved',
'finish_at' => date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . $defaultAdPublishTime . ' day')),
'publish_at' => date('Y-m-d H:i:s')
]);
event(new ChangedStatusAd($ad));//Create Notify
if ($ad = $model->newQuery()->find($id)) {
$ad->update([
'status' => 'approved',
'finish_at' => date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . $defaultAdPublishTime . ' day')),
'publish_at' => date('Y-m-d H:i:s')
]);
event(new ChangedStatusAd($ad));//Create Notify
}
}
if ($selected) {

View File

@ -0,0 +1,52 @@
<?php namespace Visiosoft\AdvsModule\Adv\Table\Handler;
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
use Anomaly\Streams\Platform\Model\EloquentModel;
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
use Visiosoft\AdvsModule\Adv\Event\ChangedStatusAd;
use Visiosoft\AdvsModule\Adv\Event\DeletedAd;
use Visiosoft\AdvsModule\Adv\Table\AdvTableBuilder;
class Delete extends ActionHandler
{
public function handle(TableBuilder $builder, array $selected)
{
$count = 0;
$model = $builder->getTableModel();
/* @var EloquentModel $entry */
foreach ($selected as $id) {
$entry = $model->find($id);
$deletable = true;
if ($entry instanceof EloquentModel) {
$deletable = $entry->isDeletable();
}
if ($entry && $deletable && $entry->delete()) {
$builder->fire('row_deleted', compact('builder', 'model', 'entry'));
event(new DeletedAd($entry));
$count++;
}
}
if ($count) {
$builder->fire('rows_deleted', compact('count', 'builder', 'model'));
}
if ($selected && $count > 0) {
$this->messages->success(trans('streams::message.delete_success', compact('count')));
}
if ($selected && $count === 0) {
$this->messages->warning(trans('streams::message.delete_success', compact('count')));
}
}
}

View File

@ -43,18 +43,15 @@ class AdvsModulePlugin extends Plugin
), new \Twig_SimpleFunction(
'latestAds',
function () {
if (!$latestAds = $this->dispatch(new LatestAds())) {
return 0;
}
return $latestAds;
}
),
new \Twig_SimpleFunction(
'appendRequestURL',
function ($request, $url, $new_parameters, $removeParams = []) {
return $this->dispatch(new appendRequestURL($request, $url, $new_parameters, $removeParams));
}
),

View File

@ -1,5 +1,6 @@
<?php namespace Visiosoft\AdvsModule;
use Anomaly\FilesModule\File\FileModel;
use Anomaly\Streams\Platform\Addon\AddonCollection;
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
@ -67,101 +68,100 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
'uses' => 'Visiosoft\AdvsModule\Http\Controller\Admin\ExcelController@import',
],
// advsController
// AdvsController
'advs/list' => [
'as' => 'visiosoft.module.advs::list',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@index'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@index'
],
'advs/list?user={id}' => [
'as' => 'visiosoft.module.advs::list_user_ad',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@index',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@index',
],
'advs/list?cat={id}' => [
'as' => 'visiosoft.module.advs::list_cat',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@index',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@index',
],
'advs/adv/{id}' => [
'as' => 'adv_detail_backup',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@view'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@view'
],
'advs/adv/{id}/{seo}' => [
'as' => 'adv_detail_seo_backup',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@view'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@view'
],
'ad/{id}' => [
'as' => 'adv_detail',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@view'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@view'
],
'ad/{seo}/{id}' => [
'as' => 'adv_detail_seo',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@view'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@view'
],
'advs/preview/{id}' => [
'as' => 'advs_preview',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@preview'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@preview'
],
'advs/map?country={country}&city[]={city}&district={districts}' => [
'as' => 'visiosoft.module.advs::show_ad_map_location',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@index'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@index'
],
'c/{category?}/{city?}' => [
'as' => 'adv_list_seo',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@index'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@index'
],
'advs/create_adv' => [
'as' => "advs::create_adv",
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@cats',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@cats',
],
'advs/create_adv/post_cat' => [
'as' => 'post_adv',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@create',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@create',
],
'advs/save_adv' => [
'as' => 'visiosoft.module.advs::post_cat',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@store'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@store'
],
'advs/edit_advs/{id}' => [
'middleware' => 'auth',
'as' => 'visiosoft.module.advs::edit_adv',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@edit',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@edit',
],
'advs/status/{id},{type}' => [
'as' => 'visiosoft.module.advs::status',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@statusAds'
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@statusAds'
],
'advs/delete/{id}' => [
'as' => 'advs::delete',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@deleteAd',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@deleteAd',
],
'adv/addCart/{id}' => [
'as' => 'adv_AddCart',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@advAddCart',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@advAddCart',
],
'ajax/StockControl' => [
'as' => 'adv_stock_control_ajax',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@stockControl',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@stockControl',
],
'ajax/addCart' => [
'as' => 'adv_add_cart_ajax',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@addCart',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@addCart',
],
'ajax/countPhone' => [
'as' => 'adv_count_show_phone',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@showPhoneCounter',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@showPhoneCounter',
],
'view/{type}' => [
'as' => 'visiosoft.module.advs::view_type',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@viewType',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@viewType',
],
'adv/edit/category/{id}' => [
'middleware' => 'auth',
'as' => 'adv::edit_category',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@editCategoryForAd',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@editCategoryForAd',
],
'ajax/getcats/{id}' => [
'as' => 'ajax::getCats',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\advsController@getCats',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@getCats',
],
'advs/extendAll/{isAdmin?}' => [
'as' => 'advs::extendAll',
@ -171,11 +171,11 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
'as' => 'advs::extendSingle',
'uses' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@extendSingle',
],
'categories/checkparent/{id}' => 'Visiosoft\AdvsModule\Http\Controller\advsController@checkParentCat',
'getlocations' => 'Visiosoft\AdvsModule\Http\Controller\advsController@getLocations',
'class/getcats/{id}' => 'Visiosoft\AdvsModule\Http\Controller\advsController@getCatsForNewAd',
'mapJson' => 'Visiosoft\AdvsModule\Http\Controller\advsController@mapJson',
'check_user' => 'Visiosoft\AdvsModule\Http\Controller\advsController@checkUser',
'categories/checkparent/{id}' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@checkParentCat',
'getlocations' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@getLocations',
'class/getcats/{id}' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@getCatsForNewAd',
'mapJson' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@mapJson',
'check_user' => 'Visiosoft\AdvsModule\Http\Controller\AdvsController@checkUser',
// AjaxController
'admin/advs/ajax' => [
@ -271,8 +271,9 @@ class AdvsModuleServiceProvider extends AddonServiceProvider
StatusRepositoryInterface::class => StatusRepository::class,
];
public function boot(AddonCollection $addonCollection, FileModel $fileModel)
public function boot(AddonCollection $addonCollection, FileModel $fileModel,CategoryRepositoryInterface $categoryRepository)
{
$settings_url = [
'general_settings' => [
'title' => 'visiosoft.module.advs::button.general_settings',

View File

@ -15,19 +15,20 @@ use Visiosoft\AdvsModule\Adv\AdvModel;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\AdvsModule\Adv\Event\ChangedStatusAd;
use Visiosoft\AdvsModule\Adv\Event\CreatedAd;
use Visiosoft\AdvsModule\Adv\Event\priceChange;
use Visiosoft\AdvsModule\Adv\Event\showAdPhone;
use Visiosoft\AdvsModule\Adv\Event\viewAd;
use Visiosoft\AdvsModule\Adv\Event\EditAd;
use Visiosoft\AdvsModule\Adv\Event\EditedAd;
use Visiosoft\AdvsModule\Adv\Event\EditedAdCategory;
use Visiosoft\AdvsModule\Adv\Event\PriceChange;
use Visiosoft\AdvsModule\Adv\Event\ShowAdPhone;
use Visiosoft\AdvsModule\Adv\Event\ViewAd;
use Visiosoft\AdvsModule\Adv\Form\AdvFormBuilder;
use Visiosoft\AdvsModule\Option\Contract\OptionRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\Contract\OptionConfigurationRepositoryInterface;
use Visiosoft\AdvsModule\OptionConfiguration\OptionConfigurationModel;
use Visiosoft\AdvsModule\Productoption\Contract\ProductoptionRepositoryInterface;
use Visiosoft\AdvsModule\ProductoptionsValue\Contract\ProductoptionsValueRepositoryInterface;
use Visiosoft\AlgoliaModule\Search\SearchModel;
use Visiosoft\CatsModule\Category\CategoryModel;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CloudinaryModule\Video\VideoModel;
use Visiosoft\FavsModule\Http\Controller\FavsController;
use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\LocationModule\City\CityRepository;
@ -144,15 +145,14 @@ class AdvsController extends PublicController
$param = $this->requestHttp->toArray();
$countries = $this->country_repository->viewAll();
$countries = $this->country_repository->newQuery()->get();
$isActiveDopings = $this->adv_model->is_enabled('dopings');
// Search by category slug
$categoryId = null;
if ($category) { // Slug
$categoryId = $this->category_repository->findBy('slug', $category);
if (!$categoryId) {
$category = $this->category_repository->findBy('slug', $category);
if (!$category) {
$this->messages->error(trans('visiosoft.module.advs::message.category_not_exist'));
return redirect('/');
}
@ -160,19 +160,19 @@ class AdvsController extends PublicController
unset($param['cat']);
return redirect(fullLink(
$param,
route('adv_list_seo', [$categoryId->slug])
route('adv_list_seo', [$category->slug])
));
}
} elseif (isset($param['cat']) && !empty($param['cat'])) { // Only Param
$categoryId = $this->category_repository->find($param['cat']);
if (!$categoryId) {
$category = $this->category_repository->find($param['cat']);
if (!$category) {
$this->messages->error(trans('visiosoft.module.advs::message.category_not_exist'));
return redirect('/');
}
unset($param['cat']);
return redirect(fullLink(
$param,
route('adv_list_seo', [$categoryId->slug])
route('adv_list_seo', [$category->slug])
));
}
@ -191,7 +191,7 @@ class AdvsController extends PublicController
unset($param['city']);
return redirect(fullLink(
$param,
route('adv_list_seo', [$categoryId->slug, $cityId->slug])
route('adv_list_seo', [$category->slug, $cityId->slug])
));
} elseif ($isOneCity) { // Param and slug
$cityId = $this->cityRepository->find($param['city'][0]);
@ -199,13 +199,13 @@ class AdvsController extends PublicController
unset($param['city']);
return redirect(fullLink(
$param,
route('adv_list_seo', [$categoryId->slug, $cityId->slug])
route('adv_list_seo', [$category->slug, $cityId->slug])
));
}
} elseif ($city && $isMultipleCity) { // Slug and multiple param cities
return redirect(fullLink(
$param,
route('adv_list_seo', [$categoryId->slug]),
route('adv_list_seo', [$category->slug]),
array()
));
} elseif ($city) {
@ -213,14 +213,14 @@ class AdvsController extends PublicController
unset($param['city']);
return redirect(fullLink(
$param,
route('adv_list_seo', [$categoryId->slug])
route('adv_list_seo', [$category->slug])
));
} else { // Only slug
$cityId = $this->cityRepository->findBy('slug', $city);
if (!$cityId) {
return redirect(fullLink(
$param,
route('adv_list_seo', [$categoryId->slug])
route('adv_list_seo', [$category->slug])
), 301);
}
}
@ -229,7 +229,7 @@ class AdvsController extends PublicController
$isActiveCustomFields = $this->adv_model->is_enabled('customfields');
$advs = $this->adv_repository->searchAdvs(
'list', $param, $customParameters, null, $categoryId, $cityId, false
'list', $param, $customParameters, null, $category, $cityId, false
);
if ($isActiveDopings) {
@ -265,34 +265,40 @@ class AdvsController extends PublicController
}
}
$seenList = array();
if ($isActiveCustomFields) {
$cfRepository = app('Visiosoft\CustomfieldsModule\CustomField\CustomFieldRepository');
$return_values = $cfRepository->getSeenList($advs);
$return_values = $cfRepository
->getSeenWithCategory($return_values['advs'], $return_values['seenList'], $categoryId);
->getSeenWithCategory($return_values['advs'], $return_values['seenList'], $category);
$advs = $return_values['advs'];
$seenList = $return_values['seenList'];
}
if ($categoryId) {
$mainCats = $this->category_model->getMains($categoryId->id);
$current_cat = $this->category_model->getCat($categoryId->id);
$mainCats[] = $current_cat;
$subCats = $this->category_repository->getSubCatById($categoryId->id);
if ($category) {
$mainCats = $this->category_repository->getParentCategoryById($category->id);
$subCats = $this->category_repository->getCategoryById($category->id);
//if there is no subcategory
if (count($subCats) < 1 and count($mainCats) > 1) {
//fetch subcategories of the last category
$subCats = $this->category_repository->getCategoryById($mainCats[1]['id']);
unset($mainCats[0]);//remove last category
}
$allCats = false;
} else {
$mainCats = $this->category_repository->mainCats();
$mainCats = $this->category_repository->getMainCategories();
$allCats = true;
}
$cFArray = array();
$cFArray = $checkboxes = $topfields = $selectDropdown = $selectRange = $selectImage = $ranges = $radio = array();
if ($isActiveCustomFields) {
$returnvalues = app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')->index($mainCats, $subCats, $categoryId);
$returnvalues = app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')->index($mainCats, $subCats, $category);
$checkboxes = $returnvalues['checkboxes'];
$topfields = $returnvalues['topfields'];
$selectDropdown = $returnvalues['selectDropdown'];
@ -382,11 +388,11 @@ class AdvsController extends PublicController
$viewType = $this->requestHttp->cookie('viewType');
list('catText' => $catText, 'user' => $user) = $this->handleSeo($categoryId, $mainCats, $cityId);
list('catText' => $catText, 'user' => $user) = $this->handleSeo($category, $mainCats, $cityId);
$compact = compact('advs', 'countries', 'mainCats', 'subCats', 'checkboxes', 'param',
'user', 'featured_advs', 'viewType', 'topfields', 'selectDropdown', 'selectRange', 'selectImage', 'ranges',
'seenList', 'radio', 'categoryId', 'cityId', 'allCats', 'catText', 'cFArray');
'seenList', 'radio', 'category', 'cityId', 'allCats', 'catText', 'cFArray');
return $this->viewTypeBasedRedirect($viewType, $compact);
}
@ -398,10 +404,9 @@ class AdvsController extends PublicController
$catText = '';
if ($category) {
$seo_keywords = $this->category_model->getMeta_keywords($category->id);
$seo_description = $this->category_model->getMeta_description($category->id);
$metaTitle = $this->category_model->getMeta_title($category->id);
$seo_keywords = $category->getMetaKeywords();
$seo_description = $category->getMetaDescription();
$metaTitle = $category->name;
$metaDesc = $seo_description;
$this->template->set('meta_keywords', implode(', ', $seo_keywords));
@ -512,7 +517,7 @@ class AdvsController extends PublicController
for ($i = 1; $i <= 10; $i++) {
$cat = "cat" . $i;
if ($adv->$cat != null) {
$item = $this->category_repository->getItem($adv->$cat);
$item = $this->category_repository->find($adv->$cat);
if (!is_null($item)) {
$categories['cat' . $i] = [
'name' => $item->name,
@ -530,21 +535,14 @@ class AdvsController extends PublicController
$features = app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')->view($adv);
}
//Cloudinary Module
$adv->video_url = null;
if ($this->adv_model->is_enabled('cloudinary')) {
$CloudinaryModel = new VideoModel();
$Cloudinary = $CloudinaryModel->getVideo($id);
if (count($Cloudinary->get()) > 0) {
$adv->video_url = $Cloudinary->first()->toArray()['url'];
}
$adv->video_url = app('Visiosoft\CloudinaryModule\Http\Controller\VideoController')->getVideoUrl($adv->id);
}
$options = $this->optionRepository->findAllBy('adv_id', $id);
$this->event->dispatch(new viewAd($adv));//view ad
$this->event->dispatch(new ViewAd($adv));//view ad
if (substr($adv->cover_photo, 0, 4) === "http") {
$coverPhoto = $adv->cover_photo;
@ -626,7 +624,7 @@ class AdvsController extends PublicController
for ($i = 1; $i <= 10; $i++) {
$cat = "cat" . $i;
if ($adv->$cat != null) {
$item = $this->category_repository->getItem($adv->$cat);
$item = $this->category_repository->find($adv->$cat);
if (!is_null($item)) {
$categories['cat' . $i] = [
'name' => $item->name,
@ -640,6 +638,7 @@ class AdvsController extends PublicController
$options = $this->optionRepository->findAllBy('adv_id', $id);
$features = array();
if ($this->adv_model->is_enabled('customfields')) {
$features = app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')->view($adv);
}
@ -688,7 +687,7 @@ class AdvsController extends PublicController
public function getCats($id)
{
return $this->category_repository->getSubCatById($id);
return $this->category_repository->getCategoryById($id);
}
public function getCatsForNewAd($id)
@ -705,14 +704,14 @@ class AdvsController extends PublicController
return $cats;
}
public function create(Request $request, AdvFormBuilder $formBuilder, CategoryRepositoryInterface $repository)
public function create(AdvFormBuilder $formBuilder, CategoryRepositoryInterface $repository)
{
if (!Auth::user()) {
redirect('/login?redirect=' . url()->current())->send();
}
$isActive = new AdvModel();
$cats = $request->toArray();
$cats = $this->request->toArray();
unset($cats['_token']);
$end = count($cats);
@ -723,13 +722,13 @@ class AdvsController extends PublicController
for ($i = 0; $i < $end; $i++) {
$plus1 = $i + 1;
$cat = $repository->getSingleCat($cats['cat' . $plus1]);
$cat = $repository->find($cats['cat' . $plus1]);
$cats_d['cat' . $plus1] = $cat->name;
}
if ($isActive->is_enabled('customfields')) {
$custom_fields = app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')->create($categories);
}
//Cloudinary Module
return $this->view->make('visiosoft.module.advs::new-ad/new-create', compact(
'request', 'formBuilder', 'cats_d', 'custom_fields'));
}
@ -737,37 +736,31 @@ class AdvsController extends PublicController
public function store
(
AdvFormBuilder $form,
MessageBag $messages,
Request $request,
SettingRepositoryInterface $settings,
AdvRepositoryInterface $advRepository,
CategoryRepositoryInterface $categoryRepository,
Dispatcher $events,
AdvModel $advModel,
AdressRepositoryInterface $address
)
{
if (!Auth::user()) {
redirect('/login?redirect=' . url()->current())->send();
}
$messages->pull('error');
if ($request->action == "update") {
$error = $form->build($request->update_id)->validate()->getFormErrors()->getMessages();
if ($this->request->action == "update") {
$error = $form->build($this->request->update_id)->validate()->getFormErrors()->getMessages();
if (!empty($error)) {
return $this->redirect->back();
}
/* Update Adv */
$adv = AdvsAdvsEntryModel::find($request->update_id);
/* Update Adv */
$before_editing = $this->adv_repository->find($this->request->update_id);
$adv = $before_editing;
$is_new_create = ($adv->slug == "") ? true : false;
//Set Old Price
$old_price = ($adv->slug == "") ? $request->price : $adv->price;
$old_price = ($adv->slug == "") ? $this->request->price : $adv->price;
$adv->old_price = $old_price;
$allowPendingAdCreation = false;
if ($advModel->is_enabled('packages') and $adv->slug == "") {
$cat = app('Visiosoft\PackagesModule\Http\Controller\PackageFEController')->AdLimitForNewAd($request);
if (is_module_installed('visiosoft.module.packages') and $is_new_create) {
$cat = app('Visiosoft\PackagesModule\Http\Controller\PackageFEController')->AdLimitForNewAd($this->request);
if (!is_null($cat)) {
if (array_key_exists('allowPendingAds', $cat)) {
$allowPendingAdCreation = $cat['allowPendingAds'];
@ -778,65 +771,52 @@ class AdvsController extends PublicController
}
// Create options
$deletedOptions = $request->deleted_options;
$newOptions = $request->new_options;
$deletedOptions = $this->request->deleted_options;
$newOptions = $this->request->new_options;
if (!empty($deletedOptions)) {
$deletedOptions = explode(',', $request->deleted_options);
$deletedOptions = explode(',', $this->request->deleted_options);
$this->optionRepository->newQuery()
->whereIn('id', $deletedOptions)
->where('adv_id', $request->update_id)
->where('adv_id', $this->request->update_id)
->delete();
}
if (!empty($newOptions)) {
$newOptions = explode(',', $request->new_options);
$newOptions = explode(',', $this->request->new_options);
foreach ($newOptions as $option) {
$this->optionRepository->create([
'name' => $option,
'adv_id' => $request->update_id,
'adv_id' => $this->request->update_id,
]);
}
}
//Get Categories Settings
$get_categories_status = false;
if ($get_categories = setting_value('visiosoft.module.advs::get_categories') and $get_categories = in_array($adv->cat1, $get_categories)) {
$get_categories_status = true;
}
$adv->is_get_adv = ($request->is_get_adv and $get_categories_status) ? true : false;
$adv->is_get_adv = ($this->request->is_get_adv and $get_categories_status) ? true : false;
$adv->save();
//algolia Search Module
$isActiveAlgolia = $advModel->is_enabled('algolia');
if ($isActiveAlgolia) {
$algolia = new SearchModel();
if ($adv->slug == "") {
$algolia->saveAlgolia($adv->toArray(), $settings);
} else {
$algolia->updateAlgolia($request->toArray(), $settings);
}
}
//Cloudinary Module
$isActiveCloudinary = $advModel->is_enabled('cloudinary');
if ($isActiveCloudinary) {
$CloudinaryModel = new VideoModel();
$CloudinaryModel->updateRequest($request);
if ($request->url != "") {
$adv->save();
}
}
if ($this->adv_model->is_enabled('customfields')) {
app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')->store($adv, $request);
//Todo Create Event
if (is_module_installed('visiosoft.module.customfields')) {
app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')->store($adv, $this->request);
}
// Auto approve
//Todo Create Event
// Auto Approve
$autoApprove = true;
if ($allowPendingAdCreation) {
$adLogExists = app('Visiosoft\PackagesModule\AdvsLog\Contract\AdvsLogRepositoryInterface')
->findByAdID($adv->id);
$autoApprove = $adLogExists ? false : true;
}
if (setting_value('visiosoft.module.advs::auto_approve') && $autoApprove) {
$defaultAdPublishTime = setting_value('visiosoft.module.advs::default_published_time');
$adv->update([
@ -846,9 +826,11 @@ class AdvsController extends PublicController
]);
}
$form->render($request->update_id);
$adv = $this->adv_repository->find($request->update_id);
$form->render($this->request->update_id);
$adv = $this->adv_repository->find($form->getFormEntryId());
//Create Adress
if ($this->request->address_id != "") {
$address = $address->find($this->request->address_id);
$adv->country_id = $address->country_id;
@ -858,57 +840,70 @@ class AdvsController extends PublicController
$adv->village = null;
$adv->save();
}
$post = $form->getPostData();
$post['id'] = $request->update_id;
$events->dispatch(new priceChange($post));//price history
if ($request->url == "") {
$advRepository->cover_image_update($adv);
$post['id'] = $this->request->update_id;
//Price Change Event
$this->event->dispatch(new PriceChange($post));
//Cover Image URL
if ($this->request->video_url == "") {
$this->adv_repository->cover_image_update($adv);
}
if ($form->hasFormErrors()) {
$cats = $request->toArray();
$cats = $this->request->toArray();
$cats_d = array();
foreach ($cats as $para => $value) {
if (substr($para, 0, 3) === "cat") {
$id = $cats[$para];
$cat = $categoryRepository->getSingleCat($id);
$cat = $this->category_repository->find($id);
if ($cat != null) {
$cats_d[$para] = $cat->name;
}
}
}
return redirect('/advs/edit_advs/' . $request->update_id)->with('cats_d', $cats_d)->with('request', $request);
return redirect('/advs/edit_advs/' . $this->request->update_id)
->with('cats_d', $cats_d)
->with('request', $this->request);
}
event(new CreatedAd($adv));
$this->adv_model->foreignCurrency($request->currency, $request->price, $request->update_id, $this->settings_repository, false);
return redirect(route('advs_preview', [$request->update_id]));
if ($is_new_create) {
event(new CreatedAd($adv));
} else {
$this->adv_model->foreignCurrency($this->request->currency, $this->request->price, $this->request->update_id, $this->settings_repository, false);
event(new EditedAd($before_editing, $adv));
}
return redirect(route('advs_preview', [$this->request->update_id]));
}
/* New Create Adv */
$request->publish_at = date('Y-m-d H:i:s');
$all = $request->all();
$this->request->publish_at = date('Y-m-d H:i:s');
$all = $this->request->all();
$packageEnabled = $advModel->is_enabled('packages');
if ($packageEnabled) {
if (is_module_installed('visiosoft.module.packages')) {
unset($all['pack_id']);
}
$new = AdvModel::query()->create($all);
$adv = $this->adv_repository->create($all);
if ($packageEnabled
if (is_module_installed('visiosoft.module.packages')
&& \request()->pack_id
&& setting_value('visiosoft.module.packages::allow_pending_ad_creation')) {
$package = app('Visiosoft\PackagesModule\Package\Contract\PackageRepositoryInterface')
->find(\request()->pack_id);
if ($package->price) {
app('Visiosoft\PackagesModule\Http\Controller\PackageFEController')
->packageAddCart(\request()->pack_id, $new->id);
->packageAddCart(\request()->pack_id, $adv->id);
}
}
return redirect('/advs/edit_advs/' . $new->id);
return redirect('/advs/edit_advs/' . $adv->id);
}
public function edit($id)
@ -932,7 +927,7 @@ class AdvsController extends PublicController
for ($i = 1; $i <= 10; $i++) {
if ($adv[$cat . $i]) {
$name = $this->category_repository->getSingleCat($adv[$cat . $i]);
$name = $this->category_repository->find($adv[$cat . $i]);
if ($name) {
$cats_d['cat' . $i] = $name->name;
$cats['cat' . $i] = $name->id;
@ -945,20 +940,9 @@ class AdvsController extends PublicController
$options = $this->optionRepository->findAllBy('adv_id', $id);
//Cloudinary Module
$Cloudinary = null;
$isActiveCloudinary = $this->adv_model->is_enabled('cloudinary');
if ($isActiveCloudinary) {
$CloudinaryModel = new VideoModel();
$Cloudinary = $CloudinaryModel->getVideo($id)->get();
if (count($Cloudinary) > 0) {
$Cloudinary = $Cloudinary->first()->toArray();
}
}
$categories = array_keys($cats);
$custom_fields = array();
if ($this->adv_model->is_enabled('customfields')) {
$custom_fields = app('Visiosoft\CustomfieldsModule\Http\Controller\CustomFieldsController')
->edit($adv, $categories, $cats);
@ -974,7 +958,7 @@ class AdvsController extends PublicController
return $this->view->make(
'visiosoft.module.advs::new-ad/new-create',
compact('id', 'cats_d', 'cats', 'Cloudinary', 'adv', 'custom_fields', 'options', 'hidePrice')
compact('id', 'cats_d', 'cats', 'adv', 'custom_fields', 'options', 'hidePrice')
);
}
@ -1005,14 +989,10 @@ class AdvsController extends PublicController
}
}
$isActiveAlgolia = $this->adv_model->is_enabled('algolia');
if ($isActiveAlgolia) {
$algolia = new SearchModel();
$algolia->updateStatus($id, $type, $settings);
}
$this->adv_model->statusAds($id, $type);
event(new ChangedStatusAd($ad));//Create Notify
if ($type === 'approved') {
$message = trans('visiosoft.module.advs::message.approve_status_change');
} elseif ($type === 'sold') {
@ -1029,7 +1009,7 @@ class AdvsController extends PublicController
if (!Auth::user()) {
redirect('/login?redirect=' . url()->current())->send();
}
$main_cats = $this->category_repository->mainCats();
$main_cats = $this->category_repository->getMainCategories();
return $this->view->make('visiosoft.module.advs::new-ad/post-cat', compact('main_cats'));
}
@ -1037,13 +1017,14 @@ class AdvsController extends PublicController
public function editCategoryForAd($id)
{
$adv = $this->adv_model->userAdv(true)->find($id);
$before_editing_ad_params = $adv->toArray();
if (is_null($adv)) {
abort(403);
}
if ($this->requestHttp->action == 'update') {
$params = $this->requestHttp->all();
if ($this->request->action == 'update') {
$params = $this->request->all();
unset($params['action']);
for ($i = 1; $i <= 10; $i++) {
@ -1053,6 +1034,7 @@ class AdvsController extends PublicController
}
$adv->update($params);
$this->event->dispatch(new EditedAdCategory($before_editing_ad_params,$adv));
$this->messages->success(trans('visiosoft.module.advs::message.updated_category_msg'));
return redirect('/advs/edit_advs/' . $id);
}
@ -1063,55 +1045,9 @@ class AdvsController extends PublicController
}
public function login()
public function mapJson(AdvRepositoryInterface $repository)
{
if (auth()->check()) {
return $this->redirect->to($this->request->get('redirect', '/'));
}
$urlPrev = str_replace(url('/'), '', url()->previous());
return $this->view->make('theme::login', compact('urlPrev'));
}
public function register()
{
if (auth()->check()) {
return redirect('/');
}
return $this->view->make('theme::register');
}
public function passwordForgot()
{
if (auth()->check()) {
return redirect('/');
}
return $this->view->make('theme::passwords/forgot');
}
public function passwordReset(Request $request)
{
if (auth()->check()) {
return redirect('/');
}
$code = $request->email;
return $this->view->make('theme::passwords/reset', compact('code'));
}
public function homePage(CategoryRepositoryInterface $repository)
{
$cats = $repository->mainCats();
return $this->view->make('theme::addons/anomaly/pages-module/page', compact('cats'));
}
public function mapJson(Request $request, AdvRepositoryInterface $repository)
{
$param = $request->toArray();
$param = $this->request->toArray();
$customParameters = array();
$advModel = new AdvModel();
@ -1123,161 +1059,6 @@ class AdvsController extends PublicController
return response()->json($advs);
}
public function getAdvsByProfile(AdvRepositoryInterface $advRepository, Request $request)
{
$my_advs = new AdvModel();
$type = $request->type;
if ($type == 'pending') {
$page_title = trans('visiosoft.module.advs::field.pending_adv.name');
$my_advs = $my_advs->pendingAdvsByUser();
} else if ($type == 'favs') {
//Get Favorites Advs
$isActiveFavs = new AdvModel();
$isActiveFavs = $isActiveFavs->is_enabled('favs');
if ($isActiveFavs) {
$page_title = trans('visiosoft.module.advs::field.favs_adv.name');
$favs = new FavsController();
$favs = $favs->getFavsByProfile();
$fav_ids = array();
foreach ($favs as $fav) {
$fav_ids[] = $fav['adv_name_id'];//fav advs id List
}
$my_advs = $my_advs->favsAdvsByUser($fav_ids);
}
} else {
$page_title = trans('visiosoft.module.advs::field.my_adv.name');
$my_advs = $my_advs->myAdvsByUser();
}
$my_advs = $my_advs->orderByDesc('id');
$my_advs = $advRepository->addAttributes($my_advs->get());
$files = array();
foreach ($my_advs as $my_adv) {
$files[] = $my_adv->files;
}
return response()->json(['success' => true, 'content' => $my_advs, 'files' => $files, 'title' => $page_title]);
}
public function authCheck()
{
if (auth()->check()) {
return auth()->user();
}
return "false";
}
public function isActiveJson($slug)
{
$isActive = $this->isActive($slug);
return response()->json(array('isActive' => $isActive));
}
public function isActive($slug)
{
$query = new AdvModel();
return $query->is_enabled($slug);
}
public function checkParentCat($id)
{
$option = new CategoryModel();
return $option->getParentCats($id);
}
public function checkUser()
{
if (Auth::check()) {
return response()->json([
'success' => true,
]);
} else {
return response()->json([
'success' => false,
]);
}
}
public function advAddCart($id, $quantity = 1)
{
$thisModel = new AdvModel();
$adv = $thisModel->isAdv($id);
$response = array();
if ($adv) {
$cart = $thisModel->addCart($adv, $quantity);
$response['status'] = "success";
} else {
$response['status'] = "error";
$response['msg'] = trans('visiosoft.module.advs::message.error_added_cart');
}
return back();
}
public function addCart(Request $request)
{
$id = $request->id;
$quantity = $request->quantity;
$name = $request->name;
$thisModel = new AdvModel();
$adv = $thisModel->isAdv($id);
$response = array();
if ($adv and $adv->getStatus() == "approved") {
$cart = $thisModel->addCart($adv, $quantity, $name);
$response['status'] = "success";
$count = $cart->getItems()->count;
$response['count'] = $count;
} else {
$response['status'] = "error";
$response['msg'] = trans('visiosoft.module.advs::message.error_added_cart');
}
return $response;
}
public function stockControl(Request $request, AdvRepositoryInterface $advRepository)
{
$quantity = $request->quantity;
$id = $request->id;
$type = $request->type;
if ($request->dataType === 'ad-configuration') {
$optionConf = new OptionConfigurationModel();
$adv = $optionConf->newQuery()->find($id);
$status = $adv->stockControl($id, $quantity);
} else {
$advmodel = new AdvModel();
$adv = $advmodel->getAdv($id);
$status = $advmodel->stockControl($id, $quantity);
}
$response = array();
if ($status == 1) {
$response['newQuantity'] = $advRepository->getQuantity($quantity, $type, $adv);
} else {
$response['newQuantity'] = $adv->stock;
}
$response['newPrice'] = $adv->price * $response['newQuantity'];
$response['newPrice'] = app(Currency::class)->format($response['newPrice'], strtoupper($adv->currency));
$response['status'] = $status;
$response['maxQuantity'] = $adv->stock;
return $response;
}
public function showPhoneCounter(Request $request, AdvModel $advModel, Dispatcher $events)
{
$ad_id = $request->id;
$ad = $advModel->getAdv($ad_id);
if ($advModel->is_enabled('phoneclickcounter')) {
$events->dispatch(new showAdPhone($ad));//show ad phone events
}
return "success";
}
public function extendAll($isAdmin = null)
{
if (\request()->unpublished) {
@ -1297,12 +1078,32 @@ class AdvsController extends PublicController
return $this->redirect->back();
}
public function sold($id, Request $request, AdvModel $advModel)
public function sold($id, AdvModel $advModel)
{
if ($request->sold == 'sold') {
if ($this->request->sold == 'sold') {
$advModel->find($id)->update(['status' => 'sold']);
} elseif ($request->sold = 'not-sold') {
} elseif ($this->request->sold = 'not-sold') {
$advModel->find($id)->update(['status' => 'approved']);
}
}
public function addCart(Request $request)
{
$id = $request->id;
$quantity = $request->quantity;
$name = $request->name;
$thisModel = new AdvModel();
$adv = $thisModel->isAdv($id);
$response = array();
if ($adv and $adv->getStatus() == "approved") {
$cart = $thisModel->addCart($adv, $quantity, $name);
$response['status'] = "success";
$count = $cart->getItems()->count;
$response['count'] = $count;
} else {
$response['status'] = "error";
$response['msg'] = trans('visiosoft.module.advs::message.error_added_cart');
}
return $response;
}
}

View File

@ -50,14 +50,6 @@ class AjaxController extends PublicController
return response()->json($datas);
}
public function keySearch(Request $request)
{
$datas = [];
$catModel = new CategoryModel();
$datas['category'] = $catModel->searchKeyword($request->q, $request->selected);
return response()->json($datas);
}
public function viewed(AdvModel $advModel, $id)
{
$advModel->viewed_Ad($id);

View File

@ -18,7 +18,7 @@ class OptionConfigurationTableColumns
'value' => function (EntryModel $entry,
AdvRepositoryInterface $advRepository) {
$adv = $advRepository->findById($entry->parent_adv_id);
$adv = $advRepository->find($entry->parent_adv_id);
return "<span><a href='" . route('adv_detail', [$entry->parent_adv_id]) . "'>$adv->name</a></span>";
}
],

View File

@ -14,7 +14,7 @@ class CategoriesOptions
public function handle(SelectFieldType $fieldType)
{
$categories = $this->categoryRepository->mainCats();
$categories = $this->categoryRepository->getMainCategories();
$options = $categories->pluck('name', 'id')->all();
$fieldType->setOptions($options);
}

View File

@ -1,5 +1,5 @@
(function (window, document) {
// Go!
})(window, document);
// (function (window, document) {
//
// // Go!
//
// })(window, document);

View File

@ -1,10 +1,8 @@
<div class="home-container">
<div class="row">
<div class="col-md-4">{% include "visiosoft.theme.base::partials/categories" %}</div>
<div class="col-md-8"><div class="album bg-light">
<div class="col-md-8">
<div class="album bg-light">
{{ addBlock('index_top')|raw }}
<div class="row p-2">
@ -19,8 +17,6 @@
{% endif %}
</div>
<div class="row list-classified-home">
{% for latestAd in latestAds() %}
<div class="col-sm-6 col-md-4 col-lg-3 d-flex align-items-stretch">
@ -28,7 +24,8 @@
<div class="row p-2" style="min-height: 150px;">
<a href="{{ latestAd.detail_url }}">
<div class="col-md-12 justify-content-center align-self-center">
<img class="card-img-top img-fluid img-thumbnail" src="{{ latestAd.cover_photo }}"
<img class="card-img-top img-fluid img-thumbnail"
src="{{ latestAd.cover_photo }}"
style="height: 150px">
</div>
</a>
@ -70,9 +67,4 @@
{{ addBlock('index')|raw }}
</div>
</div>
</div>

View File

@ -1,15 +1,14 @@
{% set sub_categories_limit = setting_value('visiosoft.theme.base::home_page_sub_categories_limit') %}
<ul class="categories-list px-0 mr-2 d-block d-sm-none">
<li class="categories-list-li category-icon text-truncate category-{{ main_category.slug }}">
<a href="{{ url_route('adv_list_seo', [main_category.slug]) }}" class="main-category">
{% set catIcon = main_category.icon.path != "" ? url('files/' ~ main_category.icon.path) : img('visiosoft.theme.base::images/default-categories-icon.png').url %}
<img src="{{ catIcon }}" alt="{{ main_category.name }}" class="img-responsive">
{% set categoryIcon = (main_category.icon) ? main_category.icon : img('visiosoft.theme.base::images/default-categories-icon.png').url %}
<img src="{{ categoryIcon }}" alt="{{ main_category.name }}" class="img-responsive">
<span>{{ main_category.name }}</span>
<p class="p-0 sub-categories">
{% set sub_categories = entries('cats','category').where('parent_category_id', main_category.id).where('deleted_at', null).orderBy('sort_order').get() %}
{% for sub_category in sub_categories|slice(0,sub_categories_limit) %}
{{ sub_category.name }},
{% for subcats in cats.subcats %}
{% if main_category.id == subcats.id %}
{{ subcats.c2_name }},
{% endif %}
{% endfor %}
</p>
</a>

View File

@ -1,48 +1,40 @@
{% set sub_categories_limit = setting_value('visiosoft.theme.base::home_page_sub_categories_limit') %}
{% set showAdsCount = setting_value('visiosoft.module.advs::show_ads_count') %}
<ul class="categories-list p-0 d-none d-sm-block">
<li class="categories-list-li category-icon category-{{ main_category.slug }}">
{% set catIcon = main_category.icon.path != "" ? url('files/' ~ main_category.icon.path) : img('visiosoft.theme.base::images/default-categories-icon.png').url %}
<img src="{{ catIcon }}" alt="{{ main_category.name }}" class="img-responsive">
{% set categoryIcon = (main_category.icon) ? main_category.icon : img('visiosoft.theme.base::images/default-categories-icon.png').url %}
<img src="{{ categoryIcon }}" alt="{{ main_category.name }}" class="img-responsive">
<a href="{{ url_route('adv_list_seo', [main_category.slug]) }}" class="main-category">
<b>{{ main_category.name }}</b>
{% if showAdsCount %}
{% set catAdsCount = entries('advs', 'advs').countAdsByCategoryId(main_category.id) %}
<small class="text-muted">
({{ catAdsCount }})
({{ main_category.count }})
</small>
{% endif %}
</a>
<ul class="p-0">
{% set sub_categories = entries('cats','category').where('parent_category_id', main_category.id).where('deleted_at', null).orderBy('sort_order').get() %}
{% set subCatLoop = [
{
'start': 0,
'end': sub_categories_limit,
'class': '',
},
{
'start': sub_categories_limit,
'end': count(sub_categories),
'class': 'hidden hidden-category',
}
] %}
{% for subLoop in subCatLoop %}
{% for sub_category in sub_categories|slice(subLoop.start, subLoop.end) %}
<li class="{{ subLoop.class }}">
<a href="{{ url_route('adv_list_seo', [sub_category.slug]) }}">{{ sub_category.name }}</a>
{% set subCatCount = 0 %}
{% for subcats in cats.subcats %}
{% if main_category.id == subcats.id %}
{% set subCatCount = subCatCount + 1 %}
{% set hideclass = "" %}
{% if subCatCount > sub_categories_limit %}
{% set hideclass = "hidden hidden-category" %}
{% endif %}
<li class="{{ hideclass }}">
<a href="{{ url_route('adv_list_seo', [subcats.c2_slug]) }}"
class="">{{ subcats.c2_name }}</a>
{% if showAdsCount %}
{% set catLevel = getParentsCount(sub_category.id) + 1 %}
{% set catAdsCount = entries('advs', 'advs').countAdsByCategoryId(sub_category.id, catLevel) %}
<small class="text-muted">
({{ catAdsCount }})
({{ subcats.c2_count }})
</small>
{% endif %}
</li>
{% endfor %}
{% endif %}
{% endfor %}
{% if count(sub_categories) > sub_categories_limit %}
{% if subCatCount > sub_categories_limit %}
<li class="show-all" data-limit="{{ sub_categories_limit }}">
<a>
<span class="">
@ -53,7 +45,6 @@
{{ trans('visiosoft.theme.base::button.hide_all') }}
<i class="fas fa-arrow-circle-up"></i>
</span>
</a>
</li>
{% endif %}

View File

@ -1,14 +1,8 @@
<div class="col left-categories-section mx-0">
{% set sub_categories_limit = setting_value('visiosoft.theme.base::home_page_sub_categories_limit') %}
{% set showAdsCount = setting_value('visiosoft.module.advs::show_ads_count') %}
<div class="col left-categories-section mx-0">
<ul class="categories-list p-0 d-none d-sm-block mb-0">
<li class="categories-list-li category-icon border-bottom-0 mt-0">
<img src="{{ img('visiosoft.theme.base::images/store-search.png').url }}" class="img-responsive">
<a href="{{ url_route('store::list') }}" class="main-category">
<span class="text-dark" class="text-dark">
{{ trans('visiosoft.theme.base::field.company_directory') }}
</span>
</a>
</li>
<li class="categories-list-li category-icon border-bottom-0 mt-0">
<img src="{{ img('visiosoft.theme.base::images/popular-ads.png').url }}" class="img-responsive">
<a href="{{ url_route('visiosoft.module.advs::list') }}?sort_by=popular" class="main-category">
@ -25,22 +19,12 @@
</span>
</a>
</li>
<li class="categories-list-li category-icon mt-0 pb-3">
<img src="{{ img('visiosoft.theme.base::images/get-ads.png').url }}" class="img-responsive">
<a href="{{ url_route('visiosoft.module.advs::list') }}?get_ads=true" class="main-category">
<span class="text-dark">
{{ trans('visiosoft.theme.base::field.secure_e-commerce_ads') }}
</span>
</a>
</li>
{{ addBlock('base/leftSidebar')|raw }}
</ul>
{{ addBlock('base/categoriesRow')|raw }}
<div class="col-12 p-0 m-0">
{% set main_categories = entries('cats','category').where('parent_category_id', null).where('deleted_at', null).orderBy('sort_order').get() %}
{% for main_category in main_categories %}
{% set cats = getCategoriesLevel2() %}
{% for main_category in cats.maincats %}
{% include "visiosoft.theme.base::partials/categories-web" %}
{% include "visiosoft.theme.base::partials/categories-mobile" %}
{% endfor %}

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

@ -0,0 +1,19 @@
<?php
use Anomaly\Streams\Platform\Database\Migration\Migration;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
class VisiosoftModuleCatsAdcountLevel extends Migration
{
public function up()
{
Schema::table('cats_category', function (Blueprint $table) {
$table->integer('level');
$table->datetime('level_at');
$table->integer('count');
$table->datetime('count_at');
});
}
}

View File

@ -0,0 +1,18 @@
<?php
use Anomaly\Streams\Platform\Database\Migration\Migration;
class VisiosoftModuleCatsChangeIconFieldType extends Migration
{
public function up()
{
if (!$field = $this->fields()->findBySlugAndNamespace('icon', 'cats')) {
return;
}
$field->setAttribute('type', 'visiosoft.field_type.input_file');
$field->setAttribute('config', []);
$this->fields()->save($field);
}
}

View File

@ -6,14 +6,14 @@ use Anomaly\Streams\Platform\Database\Migration\Migration;
class VisiosoftModuleCatsAddIndexTable extends Migration
{
public function up()
{
Schema::table('cats_category', function (Blueprint $table) {
$table->index('deleted_at');
$table->index('slug');
$table->index('parent_category_id');
$table->index('icon_id');
$table->index('sort_order');
});
}
// public function up()
// {
// Schema::table('cats_category', function (Blueprint $table) {
// $table->index('deleted_at');
// $table->index('slug');
// $table->index('parent_category_id');
// $table->index('icon_id');
// $table->index('sort_order');
// });
// }
}

View File

@ -4,11 +4,6 @@ return [
'category' => [
'read',
'write',
'delete',
],
'placeholderforsearch' => [
'read',
'write',
'delete',
],
'delete'
]
];

View File

@ -2,4 +2,6 @@
return [
'clean_subcategories' => 'Clean Subcategories',
'ad_count_calculate' => 'Ad Count Calculate',
'cat_level_calculate' => 'Category Level Calculate',
];

View File

@ -5,11 +5,8 @@
<li>
<div class="d-flex">
{% if (not categoryId) or (loop.first and categoryId) %}
{% if maincat.icon %}
<img src="{{ maincat.icon.url }}" alt="{{ maincat.name }}">
{% else %}
{{ img('visiosoft.module.advs::images/listing/sample-cat-icon.svg').data|raw }}
{% endif %}
{% set categoryIcon = (maincat.icon.value) ? maincat.icon.value : img('visiosoft.module.advs::images/listing/sample-cat-icon.svg').url %}
<img src="{{ categoryIcon }}" alt="{{ main_category.name }}" class="img-responsive">
{% endif %}
<div class="{{ not loop.first and categoryId ? 'sub-cat' : 'ml-2' }}" style="{{ not loop.first and categoryId ? 'padding-left: ' ~ (loop.index - 1) * 0.5 ~ 'rem;' }}">
<a href="{{ appendRequestURL(request_query(),url_route('adv_list_seo', [maincat.slug, cityId.slug]),{},['page']) }}">

View File

@ -1,6 +1,6 @@
{{ asset_add("scripts.js", "streams::js/table/table.js") }}
{% if not actions.empty() %}
{% if not actions.isEmpty() %}
{{ asset_add("scripts.js", "streams::js/table/actions.js") }}
{% endif %}
@ -9,70 +9,71 @@
{% endif %}
<div class="{{ table.options.container_class ?: 'container-fluid' }}">
{{ view("streams::table/partials/filters", {'table': table}) }}
<div class="card card-custom gutter-b table-responsive">
<div class="card-body pb-0">
{{ view("streams::table/partials/views", {'table': table}) }}
{{ view(table.options.heading ?: "streams::table/partials/heading", {'table': table}) }}
</div>
<div class="card-body pb-0">
{% if app.request.get('cat') != null %}
<ol class="breadcrumb">
{% for parnt in category_parents_name(app.request.get('cat'))|reverse %}
<li class="breadcrumb-item"><b>{{ parnt }}</b></li>
{% endfor %}
</ol>
<div id="buttons">
{% set parent = category_detail(app.request.get('cat')) %}
{% if parent.parent_category is null %}
{% set parent_url = url('admin/cats') %}
{% else %}
{% set parent_url = url('admin/cats?cat='~parent.parent_category_id) %}
{% endif %}
<a class="btn btn-md btn-warning " href="{{ parent_url }}">
<i class="fa fa-arrow-left"></i> {{ trans('module::field.go_to_parent') }}
</a>
</div>
{% endif %}
</div>
<div class="card-body">
{% if not table.rows.empty() %}
{% block card %}
{{ form_open({ 'url': url_full() }) }}
<div class="table-stack">
<table
class="
{{ view("streams::table/partials/filters", {'table': table}) }}
{{ view("streams::table/partials/views", {'table': table}) }}
{{ view(table.options.heading ?: "streams::table/partials/heading", {'table': table}) }}
<div class="card-body pb-0">
{% if app.request.get('cat') != null %}
<ol class="breadcrumb">
{% for parent in category_parents_name(app.request.get('cat'))|reverse %}
<li class="breadcrumb-item"><b>{{ parent.name }}</b></li>
{% endfor %}
</ol>
<div id="buttons">
{% set parent = category_detail(app.request.get('cat')) %}
{% if parent.parent_category is null %}
{% set parent_url = url('admin/cats') %}
{% else %}
{% set parent_url = url('admin/cats?cat='~parent.parent_category_id) %}
{% endif %}
<a class="btn btn-md btn-warning " href="{{ parent_url }}">
<i class="fa fa-arrow-left"></i> {{ trans('module::field.go_to_parent') }}
</a>
</div>
{% endif %}
</div>
{% if not table.rows.isEmpty() %}
{% block card %}
<div class="card">
{{ form_open({ 'url': table.options.url ?: url_full() }) }}
<div class="table-stack">
<table
class="
{{ table.options.class ?: 'table' }}
{{ table.options.sortable ? 'table--sortable' }}
"
{{ table.options.sortable ? 'data-sortable' }}
{{ html_attributes(table.options.attributes) }}>
{{ table.options.sortable ? 'data-sortable' }}
{{ html_attributes(table.options.attributes) }}>
{{ view("streams::table/partials/header", {'table': table}) }}
{{ view("streams::table/partials/header", {'table': table}) }}
{% block body %}
{{ view("streams::table/partials/body", {'table': table}) }}
{% endblock %}
{% block body %}
{{ view("streams::table/partials/body", {'table': table}) }}
{% endblock %}
{{ view("streams::table/partials/footer", {'table': table}) }}
{{ view("streams::table/partials/footer", {'table': table}) }}
</table>
</div>
{{ form_close() }}
{% endblock %}
{% else %}
</table>
</div>
{{ form_close() }}
{% block no_results %}
<div class="card">
<div class="card-block card-body">
{{ trans(table.options.get('no_results_message', 'streams::message.no_results')) }}
</div>
</div>
{% endblock %}
</div>
{% endblock %}
{% else %}
{% endif %}
</div>
</div>
{% block no_results %}
<div class="card">
<div class="card-block card-body">
{{ trans(table.options.get('no_results_message', 'streams::message.no_results')) }}
</div>
</div>
{% endblock %}
{% endif %}
</div>

View File

@ -1,16 +1,14 @@
<?php namespace Visiosoft\CatsModule\Category;
use Anomaly\Streams\Platform\Entry\EntryCollection;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
class CategoryCollection extends EntryCollection
{
public function mainCategories()
public function getMainCategories()
{
return $this->filter(
function ($category) {
return (is_null($category->parent_category_id));
}
);
$category_repository = app(CategoryRepositoryInterface::class);
return $category_repository->getMainCategories();
}
}

View File

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

View File

@ -1,175 +1,44 @@
<?php namespace Visiosoft\CatsModule\Category;
use Illuminate\Support\Facades\DB;
use Visiosoft\CatsModule\Category\Contract\CategoryInterface;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
{
public function getCat($id)
public function getMetaKeywords()
{
return CategoryModel::query()
->where('cats_category.id', $id)
->whereRaw('deleted_at IS NULL')
->first();
return $this->seo_keyword;
}
public function getParentCats($id, $type = null, $noMainCat = true)
public function getMetaDescription()
{
$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;
if ($noMainCat) {
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;
return $this->seo_description;
}
public function getCatLevel($id)
public function getParent()
{
//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, false);
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,
'slug' => $cat->slug
);
}
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;
return $this->parent_category;
}
// public function getMains($id)
// {
// $id = $id ?: $this->id;
//
// $categories = array();
// $z = 1;
// for ($i = 1; $i <= $z; $i++) {
// if ($main = $this->newQuery()->where('id', $id)->first()->select('id', 'name', 'slug', '')) {
// $categories[] = $main;
// if ($main->parent_category_id != null) {
// $id = $main->parent_category_id;
// $z++;
// }
// }
// }
// $categories = array_reverse($categories);
// unset($categories[count($categories) - 1]);
// return $categories;
// }
public function getMains($id = null)
{
@ -191,8 +60,8 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
return $categories;
}
public function getParent()
public function setCategoryIconUrl($url)
{
return $this->parent_category;
$this->update(['icon' => $url]);
}
}

View File

@ -1,30 +1,19 @@
<?php namespace Visiosoft\CatsModule\Category;
use Anomaly\Streams\Platform\Entry\EntryPresenter;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
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)
public function getParentCategoryById($id)
{
$cat = CatsCategoryEntryModel::query()->find($id);
return $cat->name;
}
public function getMains($id)
{
$category_model = new CategoryModel();
return $category_model->getMains($id);
$category_repository = app(CategoryRepositoryInterface::class);
return $category_repository->getParentCategoryById($id);
}
}

View File

@ -1,52 +1,28 @@
<?php namespace Visiosoft\CatsModule\Category;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
use Illuminate\Support\Facades\DB;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository;
use Illuminate\Support\Facades\DB;
class CategoryRepository extends EntryRepository implements CategoryRepositoryInterface
{
/**
* The entry model.
*
* @var CategoryModel
*/
protected $model;
protected $advRepository;
/**
* Create a new CategoryRepository instance.
*
* @param CategoryModel $model
* @param AdvRepositoryInterface $advRepository
*/
public function __construct(CategoryModel $model, AdvRepositoryInterface $advRepository)
{
$this->model = $model;
$this->advRepository = $advRepository;
}
public function findById($id)
public function getMainCategories()
{
return $this->model->orderBy('created_at', 'DESC')->where('cats_category.id', $id)->first();
}
public function mainCats()
{
return $this->model->where('parent_category_id', null)->orderBy('sort_order')->get();
}
public function getItem($cat)
{
return $this->model->where('cats_category.id', $cat)->first();
}
public function getCatById($id)
{
return $this->model->where('cats_category.id', $id)->where('deleted_at', null)->orderBy('sort_order')->get();
return $this->newQuery()
->where('parent_category_id', null)
->orderBy('sort_order')
->get();
}
public function getSubCatById($id)
@ -63,92 +39,142 @@ class CategoryRepository extends EntryRepository implements CategoryRepositoryIn
return $cats;
}
public function getSingleCat($id)
public function getCategoriesLevel2()
{
return CatsCategoryEntryModel::query()->where('cats_category.id', $id)->first();
$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.icon'),
DB::raw('c1.count'),
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.count as c2_count'),
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;
}
public function getCategoryById($id)
{
return $this->newQuery()
->where('parent_category_id', $id)
->where('deleted_at', null)
->orderBy('sort_order')->get();
}
public function findBySlug($slug)
{
return $this->model->orderBy('created_at', 'DESC')->where('slug', $slug)->first();
return $this->newQuery()
->where('slug', $slug)
->first();
}
public function getCategories()
public function getParentCategoryById($id)
{
return $this->model->orderBy('sort_order')->get();
}
public function removeCatFromAds($category)
{
$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;
if ($category = $this->find($id)) {
$parents_count = ($category->parent_category_id) ? 1 : 0;
$parents[] = $category;
for ($i = 0; $i < $parents_count; $i++) {
if ($category = $this->find($category->parent_category_id)) {
$parents[] = $category;
$parents_count++;
}
}
$adv->update($nullableCats);
return $parents;
}
return null;
}
public function DeleteCategories($id)
public function getLevelById($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 subcategories
$this->model->deleteSubCategories($id);
}
$parents = $this->getParentCategoryById($id);
return (is_array($parents)) ? count($parents) : null;
}
public function getMainAndSubCats()
{
$dBName = 'cats_category';
$dBNamet = $dBName . '_translations';
public function getCategoriesByName($keyword)
{
$cats = DB::table('cats_category');
$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')
$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
})
->select('cats_category.*', 'cats_category_translations.name as name')
->orderBy('id', 'DESC')->groupBy(['cats_category.id'])->get();
return $cats;
}
public function getDeletedCategories()
{
return $this->model->withTrashed()->newQuery()->whereNotNull('deleted_at')->get();
}
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')
->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;
}
}

View File

@ -0,0 +1,53 @@
<?php namespace Visiosoft\CatsModule\Category\Command;
use DateTime;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\DB;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
class CalculateAdsCount
{
use DispatchesJobs;
protected $category_id;
public function __construct($category_id = null)
{
$this->category_id = $category_id;
}
public function handle()
{
$date = new DateTime;
$date->modify('-30 minutes');
$formatted_date = $date->format('Y-m-d H:i:s');
$query = DB::table('cats_category')
->select('id', 'level');
if ($this->category_id and $category = $query->where('id', $this->category_id)->first()) {
$this->calculateCategory($category->id, $category->level);
} else {
$result = $query->where('count_at', '<', $formatted_date)
->orWhereNull('count_at')->get();
foreach ($result as $key => $category) {
$this->calculateCategory($category->id, $category->level);
}
}
}
public function calculateCategory($category_id, $level)
{
$advRepository = app(AdvRepositoryInterface::class);
if (!empty($level)) {
$count = $advRepository->getAdsCountByCategory($category_id, $level);
DB::table('cats_category')->where('id', $category_id)->update(array(
'count' => $count,
'count_at' => now(),
));
} else {
$this->dispatch(new CalculateCategoryLevel($category_id));
}
}
}

View File

@ -0,0 +1,56 @@
<?php namespace Visiosoft\CatsModule\Category\Command;
use DateTime;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Support\Facades\DB;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
class CalculateCategoryLevel
{
use DispatchesJobs;
protected $category_id;
public function __construct($category_id = null)
{
$this->category_id = $category_id;
}
public function handle()
{
if ($this->category_id) {
$this->calculateLevelByCategory($this->category_id);
} else {
$date = new DateTime;
$date->modify('-30 minutes');
$formatted_date = $date->format('Y-m-d H:i:s');
$result = DB::table('cats_category')
->select('id')
->where('level_at', '<', $formatted_date)
->where('level', '=', 0)
->orWhereNull('level_at')
->get();
foreach ($result as $key => $category) {
$this->calculateLevelByCategory($category->id);
}
}
}
public function calculateLevelByCategory($category_id)
{
$categoryRepository = app(CategoryRepositoryInterface::class);
$level = $categoryRepository->getLevelById($category_id);
if($level)
{
DB::table('cats_category')->where('id', $category_id)
->update(array(
'level' => $level,
'level_at' => now(),
));
}
}
}

View File

@ -0,0 +1,12 @@
<?php
namespace Visiosoft\CatsModule\Category\Command;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
class getCategoriesLevel2
{
public function handle(CategoryRepositoryInterface $repo)
{
return $repo->getCategoriesLevel2();
}
}

View File

@ -4,31 +4,13 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
interface CategoryInterface extends EntryInterface
{
public function getCat($id);
public function getMetaKeywords();
public function getParentCats($id, $type = null);
public function getMetaDescription();
public function getCatLevel($id);
public function getParentsCount($id);
public function getSubCategories($id, $get = null);
public function getAllSubCategories($id);
public function deleteSubCategories($id);
public function searchKeyword($keyword, $selected = null);
public function getMainCategory();
public function getMeta_keywords($cat_id);
public function getMeta_description($cat_id);
public function getMeta_title($cat_id);
public function getParent();
public function getMains($id);
public function getParent();
public function setCategoryIconUrl($url);
}

View File

@ -4,23 +4,21 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
interface CategoryRepositoryInterface extends EntryRepositoryInterface
{
public function findById($id);
public function getMainCategories();
public function mainCats();
public function getCategoriesLevel2();
public function getItem($cat);
public function getCatById($id);
public function getCategoryById($id);
public function getSubCatById($id);
public function getSingleCat($id);
public function findBySlug($slug);
public function getCategories();
public function getParentCategoryById($id);
public function DeleteCategories($id);
public function getLevelById($id);
public function getDeletedCategories();
public function getMainAndSubCats();
}

View File

@ -0,0 +1,24 @@
<?php namespace Visiosoft\CatsModule\Category\Listener;
use Visiosoft\AdvsModule\Adv\Event\ChangedStatusAd;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CatsModule\Category\Listener\Traits\CalculateAdTrait;
class CalculatedTotalForChangedAdStatus
{
use CalculateAdTrait;
protected $categoryRepository;
public function __construct(CategoryRepositoryInterface $categoryRepository)
{
return $this->categoryRepository = $categoryRepository;
}
public function handle(ChangedStatusAd $event)
{
$ad_detail = $event->getAdDetail()->toArray();
$this->calculateAdAction($ad_detail);
}
}

View File

@ -0,0 +1,24 @@
<?php namespace Visiosoft\CatsModule\Category\Listener;
use Visiosoft\AdvsModule\Adv\Event\DeletedAd;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CatsModule\Category\Listener\Traits\CalculateAdTrait;
class CalculatedTotalForDeletedAd
{
use CalculateAdTrait;
protected $categoryRepository;
public function __construct(CategoryRepositoryInterface $categoryRepository)
{
return $this->categoryRepository = $categoryRepository;
}
public function handle(DeletedAd $event)
{
$ad_detail = $event->getAdDetail()->toArray();
$this->calculateAdAction($ad_detail);
}
}

View File

@ -0,0 +1,52 @@
<?php namespace Visiosoft\CatsModule\Category\Listener;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Visiosoft\AdvsModule\Adv\Event\EditedAdCategory;
use Visiosoft\CatsModule\Category\Command\CalculateAdsCount;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
class CalculatedTotalForEditedAdCategory
{
use DispatchesJobs;
protected $categoryRepository;
public function __construct(CategoryRepositoryInterface $categoryRepository)
{
return $this->categoryRepository = $categoryRepository;
}
public function handle(EditedAdCategory $event)
{
$ad_detail = $event->getAdDetail()->toArray();
$before_editing_ad = $event->getBeforeEditingParams();
//Categories New Ad
$category_fields_new_ad = preg_grep('/^cat/i', array_keys($ad_detail));
$category_fields_new_ad = array_combine($category_fields_new_ad, $category_fields_new_ad);
foreach ($category_fields_new_ad as $key => $field) {
$category_fields_new_ad[$key] = $ad_detail[$key];
}
$category_fields_new = array_filter($category_fields_new_ad);
//Categories Before Editing Ad
$category_fields_old_ad = preg_grep('/^cat/i', array_keys($before_editing_ad));
$category_fields_old_ad = array_combine($category_fields_old_ad, $category_fields_old_ad);
foreach ($category_fields_old_ad as $key => $field) {
$category_fields_old_ad[$key] = $before_editing_ad[$key];
}
$category_fields_old = array_filter($category_fields_old_ad);
//Update previous category Count
foreach ($category_fields_old as $category_id) {
$this->dispatch(new CalculateAdsCount($category_id));
}
//Update New Category Count
foreach ($category_fields_new as $category_id) {
$this->dispatch(new CalculateAdsCount($category_id));
}
}
}

View File

@ -0,0 +1,24 @@
<?php namespace Visiosoft\CatsModule\Category\Listener;
use Visiosoft\AdvsModule\Adv\Event\CreatedAd;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CatsModule\Category\Listener\Traits\CalculateAdTrait;
class CalculatedTotalForNewAd
{
use CalculateAdTrait;
protected $categoryRepository;
public function __construct(CategoryRepositoryInterface $categoryRepository)
{
return $this->categoryRepository = $categoryRepository;
}
public function handle(CreatedAd $event)
{
$ad_detail = $event->getAdDetail()->toArray();
$this->calculateAdAction($ad_detail);
}
}

View File

@ -0,0 +1,26 @@
<?php namespace Visiosoft\CatsModule\Category\Listener\Traits;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Visiosoft\CatsModule\Category\Command\CalculateAdsCount;
trait CalculateAdTrait
{
use DispatchesJobs;
public function calculateAdAction($ad_detail)
{
$category_fields = preg_grep('/^cat/i', array_keys($ad_detail));
$category_fields = array_combine($category_fields, $category_fields);
foreach ($category_fields as $key => $field) {
$category_fields[$key] = $ad_detail[$key];
}
$category_fields = array_filter($category_fields);
foreach ($category_fields as $category_id) {
$this->dispatch(new CalculateAdsCount($category_id));
}
}
}

View File

@ -17,6 +17,14 @@ class CategoryTableBuilder extends TableBuilder
'clean_subcategories' => [
'href' => '/admin/cats/clean_subcats',
],
'adcountcalc' => [
'text' => 'visiosoft.module.cats::view.ad_count_calculate',
'href' => '/admin/cats/adcountcalc',
],
'catLevelCalc' => [
'text' => 'visiosoft.module.cats::view.cat_level_calculate',
'href' => '/admin/cats/catlevelcalc',
],
];
/**
@ -37,32 +45,6 @@ class CategoryTableBuilder extends TableBuilder
'name',
];
/**
* The table buttons.
*
* @var array|string
*/
protected $buttons = [
'edit' => [
'href' => '/admin/cats/edit/{entry.id}?parent={entry.parent_category_id}'
],
'add_sub_category' => [
'icon' => 'fa fa-caret-square-o-down',
'type' => 'success',
'href' => '/admin/cats/create?parent={entry.id}'
],
'sub_category' => [
'icon' => 'fa fa-caret-square-o-down',
'type' => 'success',
'href' => '/admin/cats?cat={entry.id}'
],
'delete' => [
'icon' => 'fa fa-trash',
'type' => 'danger',
'href' => '/admin/cats/category/delete/{entry.id}?parent={entry.parent_category_id}'
]
];
/**
* The table actions.
*
@ -80,7 +62,7 @@ class CategoryTableBuilder extends TableBuilder
* @var array
*/
protected $options = [
'table_view' => 'visiosoft.module.cats::table.table'
'table_view' => 'visiosoft.module.cats::table/table'
];
/**

View File

@ -0,0 +1,34 @@
<?php namespace Visiosoft\CatsModule\Category\Table;
use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
class CategoryTableButtons
{
public function handle(CategoryTableBuilder $builder)
{
$builder->setButtons([
'edit' => [
'href' => '/admin/cats/edit/{entry.id}?parent={entry.parent_category_id}'
],
'add_sub_category' => [
'icon' => 'fa fa-caret-square-o-down',
'type' => 'success',
'href' => '/admin/cats/create?parent={entry.id}'
],
'sub_category' => [
'icon' => 'fa fa-caret-square-o-down',
'type' => 'success',
'href' => '/admin/cats?cat={entry.id}'
],
'delete' => [
'icon' => 'fa fa-trash',
'type' => 'danger',
'href' => function(EntryInterface $entry)
{
return route('visiosoft.module.cats::admin.delete_category', ['id' => $entry->getId()])."?parent=".$entry->parent_category_id;
}
]
]);
}
}

View File

@ -1,26 +1,14 @@
<?php namespace Visiosoft\CatsModule\Category\Table\Handler;
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CatsModule\Category\Table\CategoryTableBuilder;
use Visiosoft\CatsModule\Category\Traits\DeleteCategory;
class Delete extends ActionHandler
{
public function handle(
CategoryTableBuilder $builder, array $selected,
CategoryRepositoryInterface $categoryRepository
)
{
try {
foreach ($selected as $id) {
$categoryRepository->DeleteCategories($id);
}
use DeleteCategory;
if ($selected) {
$this->messages->success(trans('visiosoft.module.cats::message.categories_mass_delete_success'));
}
} catch (\Exception $e) {
$this->messages->error($e->getMessage());
}
public function handle(array $selected)
{
$this->deleteCategories($selected);
}
}

View File

@ -0,0 +1,42 @@
<?php namespace Visiosoft\CatsModule\Category\Traits;
use Anomaly\Streams\Platform\Message\MessageBag;
use Anomaly\Streams\Platform\Model\EloquentModel;
use Visiosoft\CatsModule\Category\CategoryModel;
trait DeleteCategory
{
public function deleteCategories(array $selected)
{
$messages = app(MessageBag::class);
$count = 0;
foreach ($selected as $id) {
if ($this->deleteCategory($id)) {
$count++;
}
}
if ($selected && $count > 0) {
$messages->success(trans('streams::message.delete_success', compact('count')));
}
}
public function deleteCategory($id)
{
$model = new CategoryModel();
$entry = $model->find($id);
$deletable = true;
if ($entry instanceof EloquentModel) {
$deletable = $entry->isDeletable();
}
if ($entry && $deletable && $entry->delete()) {
return true;
}
return false;
}
}

View File

@ -28,8 +28,8 @@ class CatsModule extends Module
'category' => [
'buttons' => [
'new_category',
],
],
]
]
];
}

View File

@ -1,12 +1,21 @@
<?php namespace Visiosoft\CatsModule;
use Anomaly\Streams\Platform\Addon\Plugin\Plugin;
use Visiosoft\CatsModule\Category\CategoryModel;
use Anomaly\Streams\Platform\Image\Command\MakeImageInstance;
use Visiosoft\CatsModule\Category\Command\getCategoriesLevel2;
use Visiosoft\CatsModule\Category\Command\GetCategoryName;
use Visiosoft\CatsModule\Category\Command\GetCategoryDetail;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
class CatsModulePlugin extends Plugin
{
protected $categoryRepository;
public function __construct(CategoryRepositoryInterface $categoryRepository)
{
$this->categoryRepository = $categoryRepository;
}
/**
* @return array
@ -37,14 +46,29 @@ class CatsModulePlugin extends Plugin
), new \Twig_SimpleFunction(
'category_parents_name',
function ($id) {
$category_model = new CategoryModel();
return $category_model->getParentCats($id,'add_main');
return $this->categoryRepository->getParentCategoryById($id);
}
), new \Twig_SimpleFunction(
'getParentsCount',
function ($id) {
$category_model = new CategoryModel();
return $category_model->getParentsCount($id);
return count($this->categoryRepository->getParentCategoryById($id)) - 1;
}
), new \Twig_SimpleFunction(
'catIcon',
function ($path) {
if ($path == "") {
return $this->dispatch(new MakeImageInstance('visiosoft.theme.base::images/default-categories-icon.png', 'img'))->url();
} else {
return url('files/' . $path);
}
}
), new \Twig_SimpleFunction(
'getCategoriesLevel2',
function () {
if (!$getCategoriesLevel2 = $this->dispatch(new getCategoriesLevel2())) {
return 0;
}
return $getCategoriesLevel2;
}
)
];

View File

@ -9,6 +9,6 @@ class CatsModuleSeeder extends Seeder
*/
public function run()
{
//
}
}

View File

@ -1,11 +1,20 @@
<?php namespace Visiosoft\CatsModule;
use Anomaly\Streams\Platform\Addon\AddonServiceProvider;
use Visiosoft\AdvsModule\Adv\Event\ChangedStatusAd;
use Visiosoft\AdvsModule\Adv\Event\CreatedAd;
use Visiosoft\AdvsModule\Adv\Event\DeletedAd;
use Visiosoft\AdvsModule\Adv\Event\EditedAdCategory;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CatsModule\Category\CategoryRepository;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryModel;
use Visiosoft\CatsModule\Category\CategoryModel;
use Illuminate\Routing\Router;
use Visiosoft\CatsModule\Category\Listener\CalculatedTotalForChangedAdStatus;
use Visiosoft\CatsModule\Category\Listener\CalculatedTotalForDeletedAd;
use Visiosoft\CatsModule\Category\Listener\CalculatedTotalForEditedAdCategory;
use Visiosoft\CatsModule\Category\Listener\CalculatedTotalForNewAd;
use Visiosoft\CatsModule\Category\Table\Handler\Delete;
class CatsModuleServiceProvider extends AddonServiceProvider
{
@ -46,11 +55,17 @@ class CatsModuleServiceProvider extends AddonServiceProvider
* @type array|null
*/
protected $routes = [
'admin/cats/clean_subcats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@cleanSubcats',
'admin/cats/clean_subcats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@cleanSubCategories',
'admin/cats/adcountcalc' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@adCountCalc',
'admin/cats/catlevelcalc' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@catLevelCalc',
'admin/cats' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@index',
'admin/cats/create' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@create',
'admin/cats/edit/{id}' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@edit',
'admin/cats/category/delete/{id}' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@delete',
'admin/cats/category/delete/{id}' => [
'as' => 'visiosoft.module.cats::admin.delete_category',
'uses' => 'Visiosoft\CatsModule\Http\Controller\Admin\CategoryController@delete',
],
// Sitemap
'sitemap.xml' => 'Visiosoft\CatsModule\Http\Controller\SitemapController@index',
@ -90,9 +105,18 @@ class CatsModuleServiceProvider extends AddonServiceProvider
* @type array|null
*/
protected $listeners = [
//Visiosoft\CatsModule\Event\ExampleEvent::class => [
// Visiosoft\CatsModule\Listener\ExampleListener::class,
//],
CreatedAd::class => [
CalculatedTotalForNewAd::class,
],
EditedAdCategory::class => [
CalculatedTotalForEditedAdCategory::class,
],
ChangedStatusAd::class => [
CalculatedTotalForChangedAdStatus::class,
],
DeletedAd::class => [
CalculatedTotalForDeletedAd::class,
],
];
/**
@ -190,16 +214,13 @@ class CatsModuleServiceProvider extends AddonServiceProvider
'category' => [
'buttons' => [
'new_category' => [
'href' => '/admin/cats/create?parent='.$request->cat
'href' => '/admin/cats/create?parent=' . $request->cat
],
],
],
]
];
$this->addon->setSections($sections);
}
return parent::getOverrides();
}
}

View File

@ -1,15 +1,22 @@
<?php namespace Visiosoft\CatsModule\Http\Controller\Admin;
use Anomaly\Streams\Platform\Image\Command\MakeImageInstance;
use Anomaly\FilesModule\File\FileSanitizer;
use Anomaly\FilesModule\File\FileUploader;
use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface;
use Anomaly\Streams\Platform\Model\Cats\CatsCategoryEntryTranslationsModel;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Sunra\PhpSimple\HtmlDomParser;
use League\Flysystem\MountManager;
use Visiosoft\CatsModule\Category\CategoryModel;
use Visiosoft\CatsModule\Category\Command\CalculateAdsCount;
use Visiosoft\CatsModule\Category\Command\CalculateCategoryLevel;
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\CatsModule\Category\Form\CategoryFormBuilder;
use Visiosoft\CatsModule\Category\Table\CategoryTableBuilder;
use Anomaly\Streams\Platform\Http\Controller\AdminController;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Visiosoft\CatsModule\Category\Traits\DeleteCategory;
class CategoryController extends AdminController
{
@ -17,6 +24,8 @@ class CategoryController extends AdminController
private $categoryEntryTranslationsModel;
private $str;
use DeleteCategory;
public function __construct(
CategoryRepositoryInterface $categoryRepository,
CatsCategoryEntryTranslationsModel $categoryEntryTranslationsModel,
@ -31,12 +40,6 @@ class CategoryController extends AdminController
public function index(CategoryTableBuilder $table, Request $request)
{
if ($this->request->action == "delete") {
$CategoriesModel = new CategoryModel();
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);
@ -54,9 +57,11 @@ class CategoryController extends AdminController
return $table->render();
}
public function create(CategoryFormBuilder $form, Request $request)
public function create(FileUploader $uploader, FolderRepositoryInterface $folderRepository, MountManager $manager)
{
if ($this->request->action == "save") {
$all = $this->request->all();
$id = $all['parent_category'];
$parent_id = $all['parent_category'];
@ -111,25 +116,32 @@ class CategoryController extends AdminController
}
}
if (empty($isMultiCat)) {
$this->categoryRepository->create(array_merge($translatableEntries, [
$category = $this->categoryRepository->create(array_merge($translatableEntries, [
'slug' => $all['slug'],
'parent_category' => $all['parent_category'] === "" ? null : $all['parent_category'],
'icon' => $all['icon'],
'seo_keyword' => $all['seo_keyword'],
'seo_description' => $all['seo_description'],
]));
$this->createIconFile($category->getId());
$this->dispatch(new CalculateCategoryLevel($category->getId()));
} else {
for ($i = 0; $i < count($isMultiCat[0]); $i++) {
foreach ($isMultiCat as $cat) {
$translatableEntries = array_merge($translatableEntries, $cat[$i]);
}
$this->categoryRepository->create(array_merge($translatableEntries, [
$category = $this->categoryRepository->create(array_merge($translatableEntries, [
'slug' => $this->str->slug(reset($translatableEntries)['name'], '_'),
'parent_category' => $all['parent_category'] === "" ? null : $all['parent_category'],
'icon' => $all['icon'],
'seo_keyword' => $all['seo_keyword'],
'seo_description' => $all['seo_description'],
]));
$this->createIconFile($category->getId());
$this->dispatch(new CalculateCategoryLevel($category->getId()));
}
};
@ -171,6 +183,9 @@ class CategoryController extends AdminController
if ($form->hasFormErrors()) {
return $this->redirect->back();
}
$this->createIconFile($id);
$parent = $request->parent_category;
if ($parent != "") {
return $this->redirect->to('/admin/cats?cat=' . $parent);
@ -182,32 +197,80 @@ class CategoryController extends AdminController
return $this->view->make('visiosoft.module.cats::cats/admin-cat')->with('id', $id);
}
public function delete(CategoryRepositoryInterface $categoryRepository, Request $request, CategoryModel $categoryModel, $id)
public function delete(CategoryRepositoryInterface $categoryRepository, $id)
{
$categoryRepository->DeleteCategories($id);
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.']);
if ($this->deleteCategory($id)) {
$this->messages->success(trans('streams::message.delete_success', ['count' => 1]));
}
if (!empty($parent = $this->request->parent)) {
if (count($categoryRepository->getCategoryById($parent))) {
return redirect('admin/cats?cat=' . $parent);
}
}
return redirect('admin/cats')->with('success', ['Category and related sub-categories deleted successfully.']);
return redirect('admin/cats');
}
public function cleanSubcats()
public function cleanSubCategories()
{
$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++;
$sub_c = 1;
for ($i = 0; $i <= $sub_c; $i++) {
$cats = $this->categoryRepository->getDeletedCategories();
$delete_category_keys = $cats->pluck('id')->all();
$query_delete = $this->categoryRepository->newQuery()->whereIn('parent_category_id', $delete_category_keys);
if ($query_delete->count()) {
$query_delete->delete();
$sub_c++;
}
}
return redirect('admin/cats')->with('success', [$deletedCatsCount . ' categories has been deleted.']);
return redirect('admin/cats');
}
public function adCountCalc()
{
$this->dispatch(new CalculateAdsCount());
$this->messages->success(trans('streams::message.edit_success', ['name' => trans('visiosoft.module.cats::addon.title')]));
return redirect('admin/cats');
}
public function catLevelCalc()
{
$this->dispatch(new CalculateCategoryLevel());
$this->messages->success(trans('streams::message.edit_success', ['name' => trans('visiosoft.module.cats::addon.title')]));
return redirect('admin/cats');
}
public function createIconFile($category_id)
{
$folderRepository = app(FolderRepositoryInterface::class);
$manager = app(MountManager::class);
if ($file = $this->request->file('icon') and $folder = $folderRepository->findBySlug('category_icon') and $category = $this->categoryRepository->find($category_id)) {
$type = explode('.', $file->getClientOriginalName());
$type = end($type);
$file_location = $folder->getDisk()->getSlug() . '://' . $folder->getSlug() . '/' . FileSanitizer::clean($category_id . "." . $type);
$file_url = '/files/' . $folder->getSlug() . '/' . FileSanitizer::clean($category_id . "." . $type);
if (Storage::exists($file_location)) {
Storage::delete($file_location);
}
try {
$manager->put($file_location, file_get_contents($file->getRealPath()));
$category->setCategoryIconUrl($file_url);
} catch (\Exception $exception) {
$this->messages->error([$exception->getMessage()]);
}
}
}
}

View File

@ -0,0 +1,22 @@
{
"name": "visiosoft/input_file-field_type",
"type": "streams-addon",
"authors": [
{
"name": "Visiosoft, LTD.",
"email": "support@visiosoft.com.tr",
"homepage": "https://visiosoft.com.tr/",
"role": "Owner"
},
{
"name": "Vedat Akdoğan",
"email": "vedat@visiosoft.com.tr",
"role": "Developer"
}
],
"autoload": {
"psr-4": {
"Visiosoft\\InputFileFieldType\\": "src/"
}
}
}

View File

@ -0,0 +1,7 @@
<?php
return [
'title' => 'Input File',
'name' => 'Input File Field Type',
'description' => ''
];

View File

@ -0,0 +1,5 @@
<?php
return [
'choose_file' => 'Choose File',
];

View File

@ -0,0 +1,5 @@
<div class="form-group pb-1">
<input type="file" id="input_file" name="{{ field_type.getInputName() }}" {{ html_attributes(field_type.attributes) }} {{ field_type.disabled ? 'disabled' }} {{ field_type.required ? 'required' }} {{ field_type.readonly ? 'readonly' }} accept="image/png">
</div>
{#Todo:: Check Accept Input File Field Type#}

View File

@ -0,0 +1,8 @@
<?php namespace Visiosoft\InputFileFieldType;
use Anomaly\Streams\Platform\Addon\FieldType\FieldType;
class InputFileFieldType extends FieldType
{
protected $inputView = 'visiosoft.field_type.input_file::input';
}

View File

@ -0,0 +1,19 @@
<?php namespace Visiosoft\InputFileFieldType;
use Anomaly\Streams\Platform\Addon\FieldType\FieldTypePresenter;
use Collective\Html\HtmlBuilder;
class InputFileFieldTypePresenter extends FieldTypePresenter
{
protected $html;
public function __construct(HtmlBuilder $html, $object)
{
$this->html = $html;
parent::__construct($object);
}
}

View File

@ -1,27 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="../../../../bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Addon Test Suite">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
</php>
</phpunit>

View File

@ -1,10 +0,0 @@
<?php namespace Visiosoft\JsonFieldType\Test\Feature;
class JsonFieldTypeTest extends \TestCase
{
public function testFeature()
{
$this->markTestSkipped('Not implemented.');
}
}

View File

@ -1,7 +1,7 @@
{% set adv = params.adv %}
{% if setting_value('visiosoft.module.location::detail_page_location') %}
{% if setting_value('visiosoft.module.location::detail_page_location') and adv.country_name %}
<div class="col-md-12 m-2 location-container">
<i class="fas fa-location-arrow text-primary"></i>
{{ adv.city_name }}, {{ adv.country_name }}
{{ (adv.city_name) ? adv.city_name~',' : '' }} {{ adv.country_name }}
</div>
{% endif %}

View File

@ -127,5 +127,5 @@
<script>
var null_msg = "{{ trans('visiosoft.module.location::message.null_msg') }}!"
var defaultCountry = "{{ defaultCountry }}"
var defaultCountry = "{{ defaultCountry }}";
</script>

View File

@ -1,10 +1,12 @@
<?php namespace Visiosoft\LocationModule\City;
use Anomaly\Streams\Platform\Entry\EntryCriteria;
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
class CityCriteria extends EntryCriteria
{
public function getSubCities($city) {
return $this->query->where('parent_country_id', $city)->get();
public function getCitiesByCountryId($country_id) {
$city_repository = app(CityRepositoryInterface::class);
return $city_repository->getCitiesByCountryId($country_id);
}
}

View File

@ -2,30 +2,8 @@
use Visiosoft\LocationModule\City\Contract\CityInterface;
use Anomaly\Streams\Platform\Model\Location\LocationCitiesEntryModel;
use Visiosoft\LocationModule\District\DistrictModel;
class CityModel extends LocationCitiesEntryModel implements CityInterface
{
public function getCities($id = null) {
if($id != null)
{
return CityModel::query()->where('location_cities.id', $id)->first();
}
return CityModel::all();
}
public function getSubCities($country) {
return $this->query()->where('parent_country_id', $country)->orderBy('order','ASC')->get();
}
public function deleteCitiesByCountry($id) {
$districts = new DistrictModel();
$city = $this->where('parent_country_id',$id);
$city_id = $city->orderBy('id','DESC')->get();
foreach ($city_id as $item)
{
$districts->deleteDistrictByCity($item->id);
}
return $city->delete();
}
}

View File

@ -30,11 +30,6 @@ class CityRepository extends EntryRepository implements CityRepositoryInterface
$this->citiesEntryTranslationsModel = $citiesEntryTranslationsModel;
}
public function findById($id)
{
return $this->model->orderBy('created_at', 'DESC')->where('location_cities.id', $id)->first();
}
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc')
{
return $this->citiesEntryTranslationsModel->newQuery()
@ -48,4 +43,11 @@ class CityRepository extends EntryRepository implements CityRepositoryInterface
->orderBy($orderBy, $direction)
->get();
}
public function getCitiesByCountryId($country_id) {
return $this->newQuery()
->where('parent_country_id', $country_id)
->orderBy('order','ASC')
->get();
}
}

View File

@ -4,5 +4,5 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
interface CityInterface extends EntryInterface
{
public function getCities();
}

View File

@ -4,7 +4,7 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
interface CityRepositoryInterface extends EntryRepositoryInterface
{
public function findById($id);
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc');
public function getCitiesByCountryId($country_id);
}

View File

@ -0,0 +1,17 @@
<?php namespace Visiosoft\LocationModule\City\Events;
class DeletedCities
{
private $cities;
public function __construct($cities)
{
$this->cities = $cities;
}
public function getCities()
{
return $this->cities;
}
}

View File

@ -0,0 +1,28 @@
<?php namespace Visiosoft\LocationModule\City\Listeners;
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
use Visiosoft\LocationModule\City\Events\DeletedCities;
class DeletedCountry
{
public $cityRepository;
public function __construct(CityRepositoryInterface $cityRepository)
{
$this->cityRepository = $cityRepository;
}
public function handle(\Visiosoft\LocationModule\Country\Events\DeletedCountry $event)
{
$country = $event->getCountry();
$query = $this->cityRepository->newQuery()
->where('parent_country_id', $country->id);
if (count($cities = $query->get())) {
$query->delete();
event(new DeletedCities($cities));
}
}
}

View File

@ -1,6 +1,7 @@
<?php namespace Visiosoft\LocationModule\City\Table;
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
use Visiosoft\LocationModule\City\Table\Handler\Delete;
class CityTableBuilder extends TableBuilder
{
@ -60,7 +61,9 @@ class CityTableBuilder extends TableBuilder
* @var array|string
*/
protected $actions = [
'delete'
'delete' => [
'handler' => Delete::class,
],
];
/**

View File

@ -0,0 +1,24 @@
<?php namespace Visiosoft\LocationModule\City\Table\Handler;
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
use Visiosoft\LocationModule\City\Contract\CityRepositoryInterface;
use Visiosoft\LocationModule\City\Events\DeletedCities;
class Delete extends ActionHandler
{
public function handle(CityRepositoryInterface $repository, array $selected)
{
$query = $repository->newQuery()->whereIn('location_cities.id', $selected);
if ($count = count($cities = $query->get())) {
$query->delete();
event(new DeletedCities($cities));
}
if ($selected && $count > 0) {
$this->messages->success(trans('streams::message.delete_success', compact('count')));
}
}
}

View File

@ -4,5 +4,5 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryInterface;
interface CountryInterface extends EntryInterface
{
public function getCountry($id);
}

View File

@ -4,9 +4,5 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
interface CountryRepositoryInterface extends EntryRepositoryInterface
{
public function findById($id);
public function viewAll();
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc');
}

View File

@ -5,8 +5,5 @@ use Anomaly\Streams\Platform\Model\Location\LocationCountriesEntryModel;
class CountryModel extends LocationCountriesEntryModel implements CountryInterface
{
public function getCountry($id)
{
return CountryModel::query()->where('location_countries.id', $id)->first();
}
}

View File

@ -32,14 +32,6 @@ class CountryRepository extends EntryRepository implements CountryRepositoryInte
$this->model = $model;
$this->countriesEntryTranslationsModel = $countriesEntryTranslationsModel;
}
public function findById($id)
{
return $this->model->orderBy('created_at', 'DESC')->where('location_countries.id', $id)->first();
}
public function viewAll(){
return $this->model->get();
}
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc')
{

View File

@ -0,0 +1,17 @@
<?php namespace Visiosoft\LocationModule\Country\Events;
class DeletedCountry
{
private $country;
public function __construct($country)
{
$this->country = $country;
}
public function getCountry()
{
return $this->country;
}
}

View File

@ -1,6 +1,7 @@
<?php namespace Visiosoft\LocationModule\Country\Table;
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
use Visiosoft\LocationModule\Country\Table\Handler\Delete;
class CountryTableBuilder extends TableBuilder
{
@ -60,7 +61,9 @@ class CountryTableBuilder extends TableBuilder
* @var array|string
*/
protected $actions = [
'delete'
'delete' => [
'handler' => Delete::class,
],
];
/**

View File

@ -0,0 +1,49 @@
<?php namespace Visiosoft\LocationModule\Country\Table\Handler;
use Anomaly\Streams\Platform\Model\EloquentModel;
use Anomaly\Streams\Platform\Ui\Table\Component\Action\ActionHandler;
use Anomaly\Streams\Platform\Ui\Table\TableBuilder;
use Visiosoft\LocationModule\Country\Events\DeletedCountry;
class Delete extends ActionHandler
{
public function handle(TableBuilder $builder, array $selected)
{
$count = 0;
$model = $builder->getTableModel();
/* @var EloquentModel $entry */
foreach ($selected as $id) {
$entry = $model->find($id);
$deletable = true;
if ($entry instanceof EloquentModel) {
$deletable = $entry->isDeletable();
}
if ($entry && $deletable && $entry->delete()) {
$builder->fire('row_deleted', compact('builder', 'model', 'entry'));
event(new DeletedCountry($entry));
$count++;
}
}
if ($count) {
$builder->fire('rows_deleted', compact('count', 'builder', 'model'));
}
if ($selected && $count > 0) {
$this->messages->success(trans('streams::message.delete_success', compact('count')));
}
if ($selected && $count === 0) {
$this->messages->warning(trans('streams::message.delete_success', compact('count')));
}
}
}

View File

@ -5,4 +5,6 @@ use Anomaly\Streams\Platform\Entry\Contract\EntryRepositoryInterface;
interface DistrictRepositoryInterface extends EntryRepositoryInterface
{
public function getByEntryIDsAndOrderByTransCol($entryIDs, $orderBy, $direction = 'asc');
public function getDistrictByCityId($city);
}

Some files were not shown because too many files have changed in this diff Show More