mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
#360 merge two extend functions
This commit is contained in:
parent
7aff323e3a
commit
e3d552219a
@ -26,4 +26,5 @@ return [
|
||||
'delete_author_error' => 'You cannot delete a post that does not belong to you',
|
||||
'success_delete' => 'Ad Deleted',
|
||||
'pending_ad_status' => 'Your ad is pending approval by the Editor.',
|
||||
'extended' => ':number ad(s) has been extended successfully.',
|
||||
];
|
||||
|
||||
@ -363,5 +363,18 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public function extendAds($allAds, $isAdmin = false)
|
||||
{
|
||||
if (!is_numeric($allAds)) {
|
||||
if ($isAdmin && auth()->user()->hasRole('admin')) {
|
||||
$advs = $this->newQuery();
|
||||
} else {
|
||||
$advs = $this->newQuery()->where('created_by_id', auth()->id());
|
||||
}
|
||||
} else {
|
||||
$advs = $this->newQuery()->where('id', $allAds);
|
||||
}
|
||||
$newDate = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . setting_value('visiosoft.module.advs::default_published_time') . ' day'));
|
||||
return $advs->update(['finish_at' => $newDate]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,4 +36,5 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
|
||||
|
||||
public function getCategoriesWithAdID($id);
|
||||
|
||||
public function extendAds($allAds, $isAdmin = false);
|
||||
}
|
||||
|
||||
@ -976,23 +976,15 @@ class AdvsController extends PublicController
|
||||
|
||||
public function extendAll($isAdmin = null)
|
||||
{
|
||||
if ($isAdmin && auth()->user()->hasRole('admin')) {
|
||||
$advs = $this->adv_model->newQuery();
|
||||
} else {
|
||||
$advs = $this->adv_model->newQuery()->where('created_by_id', auth()->id());
|
||||
}
|
||||
$newDate = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . setting_value('visiosoft.module.advs::default_published_time') . ' day'));
|
||||
$advs->update(['finish_at' => $newDate]);
|
||||
$this->messages->success(trans('visiosoft.module.advs::field.extended'));
|
||||
$adsExtended = $this->adv_repository->extendAds(true, $isAdmin);
|
||||
$this->messages->success(trans('visiosoft.module.advs::message.extended', ['number' => $adsExtended]));
|
||||
return $this->redirect->back();
|
||||
}
|
||||
|
||||
public function extendSingle($adId)
|
||||
{
|
||||
$advs = $this->adv_model->newQuery()->where('id', $adId);
|
||||
$newDate = date('Y-m-d H:i:s', strtotime(date('Y-m-d H:i:s') . ' + ' . setting_value('visiosoft.module.advs::default_published_time') . ' day'));
|
||||
$advs->update(['finish_at' => $newDate]);
|
||||
$this->messages->success(trans('visiosoft.module.advs::field.extended'));
|
||||
$adsExtended = $this->adv_repository->extendAds($adId);
|
||||
$this->messages->success(trans('visiosoft.module.advs::message.extended', ['number' => $adsExtended]));
|
||||
return $this->redirect->back();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user