mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
optimized query && category icon
This commit is contained in:
parent
94323aaac1
commit
5473dd7006
@ -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',
|
||||
];
|
||||
}
|
||||
@ -223,17 +223,17 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
}
|
||||
|
||||
|
||||
public function getAdvDetailLinkByModel($object, $type = null)
|
||||
{
|
||||
if ($type != null) {
|
||||
$id = $object->id;
|
||||
$seo = $object->slug;
|
||||
return \route('adv_detail_seo', [$seo, $id]);
|
||||
}
|
||||
$id = $object->getObject()->id;
|
||||
$seo = $object->getObject()->slug;
|
||||
return \route('adv_detail_seo', [$seo, $id]);
|
||||
}
|
||||
public function getAdvDetailLinkByModel($object, $type = null)
|
||||
{
|
||||
if ($type != null) {
|
||||
$id = $object->id;
|
||||
$seo = $object->slug;
|
||||
return \route('adv_detail_seo', [$seo, $id]);
|
||||
}
|
||||
$id = $object->getObject()->id;
|
||||
$seo = $object->getObject()->slug;
|
||||
return \route('adv_detail_seo', [$seo, $id]);
|
||||
}
|
||||
|
||||
public function getAdvDetailLinkByAdId($id)
|
||||
{
|
||||
@ -394,7 +394,7 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
|
||||
public function getProductOptionsValues()
|
||||
{
|
||||
return $this->product_options_value;
|
||||
return $this->product_options_value;
|
||||
}
|
||||
|
||||
public function getStatus()
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -0,0 +1,17 @@
|
||||
<?php namespace Visiosoft\AdvsModule\Adv\Event;
|
||||
|
||||
class DeletedAd
|
||||
{
|
||||
private $ad;
|
||||
|
||||
public function __construct($ad)
|
||||
{
|
||||
$this->ad = $ad;
|
||||
}
|
||||
|
||||
public function getAdDetail()
|
||||
{
|
||||
return $this->ad;
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,9 @@ class AdvTableBuilder extends TableBuilder
|
||||
* @var array|string
|
||||
*/
|
||||
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'
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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')));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -957,7 +957,9 @@ class AdvsController extends PublicController
|
||||
}
|
||||
|
||||
$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') {
|
||||
|
||||
@ -1,7 +1,10 @@
|
||||
<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">
|
||||
<img src="{{ catIcon(main_category.icon.path) }}" alt="{{ main_category.name }}" class="img-responsive">
|
||||
{% set icon = img(url('local://category_icon/'~main_category.id~'.png')) %}
|
||||
{% set categoryIcon = (icon.data()) ? icon.url() : 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">
|
||||
{% for subcats in cats.subcats %}
|
||||
|
||||
@ -1,6 +1,10 @@
|
||||
<ul class="categories-list p-0 d-none d-sm-block">
|
||||
<li class="categories-list-li category-icon category-{{ main_category.slug }}">
|
||||
<img src="{{ catIcon(main_category.icon.path) }}" alt="{{ main_category.name }}" class="img-responsive">
|
||||
|
||||
{% set icon = img(url('local://category_icon/'~main_category.id~'.png')) %}
|
||||
{% set categoryIcon = (icon.data()) ? icon.url() : 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 %}
|
||||
|
||||
@ -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 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>
|
||||
<div class="card-body">
|
||||
{% if count(table.rows) %}
|
||||
{% 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>
|
||||
|
||||
@ -25,9 +25,7 @@ class CalculateAdsCount
|
||||
$query = DB::table('cats_category')
|
||||
->select('id', 'level');
|
||||
|
||||
if ($this->category_id) {
|
||||
$category = $query->where('id', $this->category_id)->first();
|
||||
|
||||
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)
|
||||
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
@ -1,13 +1,13 @@
|
||||
<?php namespace Visiosoft\CatsModule\Category\Listener;
|
||||
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Visiosoft\AdvsModule\Adv\Event\CreatedAd;
|
||||
use Visiosoft\CatsModule\Category\Command\CalculateAdsCount;
|
||||
use Visiosoft\CatsModule\Category\Contract\CategoryRepositoryInterface;
|
||||
use Visiosoft\CatsModule\Category\Listener\Traits\CalculateAdTrait;
|
||||
|
||||
class CalculatedTotalForNewAd
|
||||
{
|
||||
use DispatchesJobs;
|
||||
use CalculateAdTrait;
|
||||
|
||||
protected $categoryRepository;
|
||||
|
||||
public function __construct(CategoryRepositoryInterface $categoryRepository)
|
||||
@ -19,17 +19,6 @@ class CalculatedTotalForNewAd
|
||||
{
|
||||
$ad_detail = $event->getAdDetail()->toArray();
|
||||
|
||||
$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));
|
||||
}
|
||||
$this->calculateAdAction($ad_detail);
|
||||
}
|
||||
}
|
||||
@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,15 +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
|
||||
{
|
||||
@ -103,6 +108,12 @@ class CatsModuleServiceProvider extends AddonServiceProvider
|
||||
EditedAdCategory::class => [
|
||||
CalculatedTotalForEditedAdCategory::class,
|
||||
],
|
||||
ChangedStatusAd::class => [
|
||||
CalculatedTotalForChangedAdStatus::class,
|
||||
],
|
||||
DeletedAd::class => [
|
||||
CalculatedTotalForDeletedAd::class,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
@ -1,8 +1,13 @@
|
||||
<?php namespace Visiosoft\CatsModule\Http\Controller\Admin;
|
||||
|
||||
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 League\Flysystem\MountManager;
|
||||
use Visiosoft\CatsModule\Category\CategoryModel;
|
||||
use Visiosoft\CatsModule\Category\Command\CalculateAdsCount;
|
||||
use Visiosoft\CatsModule\Category\Command\CalculateCategoryLevel;
|
||||
@ -54,9 +59,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'];
|
||||
@ -114,13 +121,13 @@ class CategoryController extends AdminController
|
||||
$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->id));
|
||||
$this->dispatch(new CalculateCategoryLevel($category->getId()));
|
||||
|
||||
} else {
|
||||
for ($i = 0; $i < count($isMultiCat[0]); $i++) {
|
||||
@ -130,12 +137,13 @@ class CategoryController extends AdminController
|
||||
$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->dispatch(new CalculateCategoryLevel($category->id));
|
||||
$this->createIconFile($category->getId());
|
||||
|
||||
$this->dispatch(new CalculateCategoryLevel($category->getId()));
|
||||
}
|
||||
};
|
||||
|
||||
@ -177,6 +185,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);
|
||||
@ -232,4 +243,24 @@ class CategoryController extends AdminController
|
||||
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')) {
|
||||
|
||||
$type = explode('.', $file->getClientOriginalName());
|
||||
$type = end($type);
|
||||
|
||||
$file_location = $folder->getDisk()->getSlug() . '://' . $folder->getSlug() . '/' . FileSanitizer::clean($category_id . "." . $type);
|
||||
|
||||
if (Storage::exists($file_location)) {
|
||||
Storage::delete($file_location);
|
||||
}
|
||||
|
||||
$manager->put($file_location, file_get_contents($file->getRealPath()));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
22
addons/default/visiosoft/input_file-field_type/composer.json
Normal file
22
addons/default/visiosoft/input_file-field_type/composer.json
Normal 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/"
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,7 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'title' => 'Input File',
|
||||
'name' => 'Input File Field Type',
|
||||
'description' => ''
|
||||
];
|
||||
@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'choose_file' => 'Choose 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#}
|
||||
@ -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';
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@ -190,5 +190,20 @@ class DatabaseSeeder extends Seeder
|
||||
],
|
||||
]);
|
||||
};
|
||||
|
||||
|
||||
//Create Category Icon Folder
|
||||
if (!$this->folders->findBySlug('category_icon')) {
|
||||
$disk = $this->disks->findBySlug('local');
|
||||
|
||||
$this->folders->create([
|
||||
'en' => [
|
||||
'name' => 'Category Icon',
|
||||
'description' => 'A folder for Category Icon.',
|
||||
],
|
||||
'slug' => 'category_icon',
|
||||
'disk' => $disk
|
||||
]);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user