#2474 e-madencilik ads number bug

This commit is contained in:
Diatrex 2020-10-28 15:40:39 +03:00
parent 35b0e80fee
commit cabe49f00d
3 changed files with 29 additions and 7 deletions

View File

@ -84,9 +84,14 @@ class AdvCriteria extends EntryCriteria
return $ads; return $ads;
} }
public function findAdsByCategoryId($catId, $level = 1) public function findAdsByCategoryId($catId, $level = 1, $limit = 20)
{ {
return $this->advRepository->getByCat($catId, $level); return $this->advRepository->getByCat($catId, $level, $limit);
}
public function countAdsByCategoryId($catId, $level = 1)
{
return $this->advRepository->countByCat($catId, $level);
} }
public function getCurrentLocale() public function getCurrentLocale()

View File

@ -4,6 +4,7 @@ use Anomaly\FilesModule\File\Contract\FileRepositoryInterface;
use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface; use Anomaly\FilesModule\Folder\Contract\FolderRepositoryInterface;
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;
@ -377,15 +378,19 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
return $ads; return $ads;
} }
public function getByCat($catID, $level = 1) public function getByCat($catID, $level = 1, $limit = 20)
{ {
$advs = $this->model $advs = $this->model
->whereDate('finish_at', '>=', date("Y-m-d H:i:s")) ->whereDate('finish_at', '>=', date("Y-m-d H:i:s"))
->where('status', 'approved') ->where('status', 'approved')
->where('slug', '!=', '') ->where('slug', '!=', '')
->where('cat' . $level, $catID) ->where('cat' . $level, $catID);
->limit(20)
->get(); if ($limit) {
$advs = $advs->limit($limit);
}
$advs = $advs->get();
$ads = $this->model->getLocationNames($advs); $ads = $this->model->getLocationNames($advs);
@ -397,6 +402,16 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
return $ads; return $ads;
} }
public function countByCat($catID, $level = 1)
{
return DB::table('advs_advs')
->whereDate('finish_at', '>=', date("Y-m-d H:i:s"))
->where('status', 'approved')
->where('slug', '!=', '')
->where('cat' . $level, $catID)
->count();
}
public function getCategoriesWithAdID($id) public function getCategoriesWithAdID($id)
{ {
$adv = $this->model->find($id); $adv = $this->model->find($id);

View File

@ -35,7 +35,9 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
public function latestAds(); public function latestAds();
public function getByCat($catID, $level = 1); public function getByCat($catID, $level = 1, $limit = 20);
public function countByCat($catID, $level = 1);
public function getCategoriesWithAdID($id); public function getCategoriesWithAdID($id);