Merge pull request #1024 from openclassify/vedatakd

update getUserAds
This commit is contained in:
Fatih Alp 2021-04-11 16:43:48 +03:00 committed by GitHub
commit 02f21e8e3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 14 deletions

View File

@ -79,13 +79,13 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
$query = $query->whereIn('city', explode(',', array_first($param['city']))); $query = $query->whereIn('city', explode(',', array_first($param['city'])));
} }
if (isset($param['district']) and !empty(array_filter($param['district']))) { if (isset($param['district']) and !empty(array_filter($param['district']))) {
$query = $query->whereIn('district', explode(',',array_first($param['district']))); $query = $query->whereIn('district', explode(',', array_first($param['district'])));
} }
if (isset($param['neighborhood']) and !empty(array_filter($param['neighborhood']))) { if (isset($param['neighborhood']) and !empty(array_filter($param['neighborhood']))) {
$query = $query->whereIn('neighborhood', explode(',',array_first($param['neighborhood']))); $query = $query->whereIn('neighborhood', explode(',', array_first($param['neighborhood'])));
} }
if (isset($param['village']) and !empty(array_filter($param['village']))) { if (isset($param['village']) and !empty(array_filter($param['village']))) {
$query = $query->whereIn('village', explode(',',array_first($param['village']))); $query = $query->whereIn('village', explode(',', array_first($param['village'])));
} }
} }
if ($category) { if ($category) {
@ -147,6 +147,10 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
$query = $query->where('is_get_adv', 1); $query = $query->where('is_get_adv', 1);
} }
if (!empty($param['created_at'])) {
$query = $query->whereDate('advs_advs.created_at', $param['created_at']);
}
foreach ($param as $para => $value) { foreach ($param as $para => $value) {
if (substr($para, 0, 3) === "cf_") { if (substr($para, 0, 3) === "cf_") {
$id = substr($para, 3); $id = substr($para, 3);
@ -420,7 +424,7 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
foreach ($ads as $index => $ad) { foreach ($ads as $index => $ad) {
$ads[$index]->detail_url = $this->model->getAdvDetailLinkByModel($ad, 'list'); $ads[$index]->detail_url = $this->model->getAdvDetailLinkByModel($ad, 'list');
$ads[$index]->currency_price = app(Currency::class)->format($ad->price,$ad->currency); $ads[$index]->currency_price = app(Currency::class)->format($ad->price, $ad->currency);
$ads[$index] = $this->model->AddAdsDefaultCoverImage($ad); $ads[$index] = $this->model->AddAdsDefaultCoverImage($ad);
} }
@ -519,13 +523,17 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
return $ads; return $ads;
} }
public function getUserAds($userID = null) public function getUserAds($userID = null, $status = "approved")
{ {
$userID = auth_id_if_null($userID); $userID = auth_id_if_null($userID);
return $this->newQuery()
->where('advs_advs.created_by_id', $userID) $query = $this->newQuery()
->where('status', 'approved') ->where('advs_advs.created_by_id', $userID);
->where('finish_at', '>', date('Y-m-d H:i:s'))
if ($status) {
$query = $query->where('status', $status);
}
return $query->where('finish_at', '>', date('Y-m-d H:i:s'))
->get(); ->get();
} }
} }

View File

@ -5,14 +5,16 @@ use Visiosoft\AdvsModule\Adv\Contract\AdvRepositoryInterface;
class GetUserAds class GetUserAds
{ {
protected $userID; protected $userID;
protected $status;
public function __construct($userID) public function __construct($userID, $status = "approved")
{ {
$this->userID = $userID; $this->userID = $userID;
$this->status = $status;
} }
public function handle(AdvRepositoryInterface $advRepository) public function handle(AdvRepositoryInterface $advRepository)
{ {
return $advRepository->getUserAds($this->userID); return $advRepository->getUserAds($this->userID, $this->status);
} }
} }

View File

@ -53,5 +53,5 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
public function approveAds($adsIDs); public function approveAds($adsIDs);
public function getUserAds($userID = null); public function getUserAds($userID = null, $status = "approved");
} }

View File

@ -73,8 +73,8 @@ class AdvsModulePlugin extends Plugin
), ),
new \Twig_SimpleFunction( new \Twig_SimpleFunction(
'getUserAds', 'getUserAds',
function ($userID = null) { function ($userID = null, $status = "approved") {
return $this->dispatch(new GetUserAds($userID)); return $this->dispatch(new GetUserAds($userID, $status));
} }
), ),
new \Twig_SimpleFunction( new \Twig_SimpleFunction(