Merge pull request #687 from openclassify/dia

#2221 Top category showcase doesn't works
This commit is contained in:
spektra2147 2020-09-30 11:50:18 +03:00 committed by GitHub
commit 7b81c1cd76
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 38 deletions

View File

@ -2,7 +2,7 @@
{% for adv in advs %} {% for adv in advs %}
<div class="col-md-12 mb-2 list-classified bg-light"> <div class="col-md-12 mb-2 list-classified bg-light">
<a href="{{ adv.detail_url }}" class="text-dark"> <a href="{{ adv.detail_url }}" class="text-dark">
<div class="row{% if adv.doping != null %} doping_type4 {% endif %}"> <div class="row{{ adv.doping_type ? ' doping_type' ~ adv.doping_type }}">
<div class="col-md-2 justify-content-center align-self-center text-center border-right border-white"> <div class="col-md-2 justify-content-center align-self-center text-center border-right border-white">
<img class="img-thumbnail lazy" src="{{ img('visiosoft.theme.base::images/no-image.png').url }}" <img class="img-thumbnail lazy" src="{{ img('visiosoft.theme.base::images/no-image.png').url }}"
data-src="{{ adv.cover_photo }}" alt="{{ adv.name }}" data-src="{{ adv.cover_photo }}" alt="{{ adv.name }}"

View File

@ -2,67 +2,41 @@
use Anomaly\FilesModule\File\Contract\FileRepositoryInterface; use Anomaly\FilesModule\File\Contract\FileRepositoryInterface;
use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface; use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface;
use Anomaly\SettingsModule\Setting\Contract\SettingRepositoryInterface;
use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel; use Anomaly\Streams\Platform\Model\Advs\AdvsAdvsEntryModel;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\DB;
use Intervention\Image\Facades\Image; use Intervention\Image\Facades\Image;
use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface; use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
use Anomaly\Streams\Platform\Entry\EntryRepository; use Anomaly\Streams\Platform\Entry\EntryRepository;
use Visiosoft\CatsModule\Category\CategoryModel; use Visiosoft\CatsModule\Category\CategoryModel;
use Visiosoft\AdvsModule\Category\Contract\CategoryRepositoryInterface;
use Visiosoft\LocationModule\City\CityModel; use Visiosoft\LocationModule\City\CityModel;
use Visiosoft\LocationModule\Country\CountryModel; use Visiosoft\LocationModule\Country\CountryModel;
class AdvRepository extends EntryRepository implements AdvRepositoryInterface class AdvRepository extends EntryRepository implements AdvRepositoryInterface
{ {
/**
* The entry model.
*
* @var AdvModel
*/
protected $model; protected $model;
/**
* @var FileRepositoryInterface
*/
private $fileRepository; private $fileRepository;
/**
* @var FolderRepositoryInterface
*/
private $folderRepository; private $folderRepository;
/**
* Create a new AdvRepository instance.
*
* @param AdvModel $model
*/
public function __construct( public function __construct(
AdvModel $model, AdvModel $model,
SettingRepositoryInterface $settings,
FileRepositoryInterface $fileRepository, FileRepositoryInterface $fileRepository,
FolderRepositoryInterface $folderRepository FolderRepositoryInterface $folderRepository
) )
{ {
$this->model = $model; $this->model = $model;
$this->settings = $settings;
$this->fileRepository = $fileRepository; $this->fileRepository = $fileRepository;
$this->folderRepository = $folderRepository; $this->folderRepository = $folderRepository;
} }
/**
* Resolve the advs.
*
* @return AdvsInterface|null
*/
public function findById($id) public function findById($id)
{ {
return $this->model->orderBy('created_at', 'DESC')->where('advs_advs.id', $id)->first(); return $this->model->orderBy('created_at', 'DESC')->where('advs_advs.id', $id)->first();
} }
public function searchAdvs($type, $param = null, $customParameters = null, $limit = null, $category = null, $city = null) public function searchAdvs(
$type, $param = null, $customParameters = null,
$limit = null, $category = null, $city = null, $paginate = true
)
{ {
$isActiveDopings = new AdvModel(); $isActiveDopings = new AdvModel();
$isActiveDopings = $isActiveDopings->is_enabled('dopings'); $isActiveDopings = $isActiveDopings->is_enabled('dopings');
@ -239,7 +213,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
} }
if ($type == "list") { if ($type == "list") {
return $query->paginate($this->settings->value('streams::per_page')); return $paginate ? $query->paginate(setting_value('streams::per_page')) : $query;
} else { } else {
return $query->get(); return $query->get();
} }

View File

@ -6,7 +6,10 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
{ {
public function findById($id); public function findById($id);
public function searchAdvs($type, $param = null, $customParameters = null, $limit = null, $category = null, $city = null); public function searchAdvs(
$type, $param = null, $customParameters = null,
$limit = null, $category = null, $city = null, $paginate = true
);
public function softDeleteAdv($id); public function softDeleteAdv($id);

View File

@ -229,7 +229,17 @@ class AdvsController extends PublicController
} }
$isActiveCustomFields = $this->adv_model->is_enabled('customfields'); $isActiveCustomFields = $this->adv_model->is_enabled('customfields');
$advs = $this->adv_repository->searchAdvs('list', $param, $customParameters, null, $categoryId, $cityId); $advs = $this->adv_repository->searchAdvs(
'list', $param, $customParameters, null, $categoryId, $cityId, false
);
if ($isActiveDopings) {
$featuredAdvsQuery = clone $advs;
$advs = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')
->listFeatures($featuredAdvsQuery)->union($advs);
}
$advs = $advs->paginate(setting_value('streams::per_page'));
$advs = $this->adv_repository->addAttributes($advs); $advs = $this->adv_repository->addAttributes($advs);
if ($advs->currentPage() > $advs->lastPage()) { if ($advs->currentPage() > $advs->lastPage()) {
@ -241,10 +251,6 @@ class AdvsController extends PublicController
), 301); ), 301);
} }
if ($isActiveDopings and $param != null) {
$featured_advs = app('Visiosoft\DopingsModule\Http\Controller\DopingsController')->listFeatures($advs);
}
$seenList = null; $seenList = null;
foreach ($advs as $index => $ad) { foreach ($advs as $index => $ad) {
$advs[$index]->detail_url = $this->adv_model->getAdvDetailLinkByModel($ad, 'list'); $advs[$index]->detail_url = $this->adv_model->getAdvDetailLinkByModel($ad, 'list');