mirror of
https://github.com/openclassify/openclassify.git
synced 2026-01-11 18:01:10 -06:00
Merge pull request #851 from openclassify/dia
#2336 redirect ad detail link if slug is different
This commit is contained in:
commit
b04abde541
@ -218,13 +218,11 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
{
|
||||
if ($type != null) {
|
||||
$id = $object->id;
|
||||
$seo = str_slug($object->name);
|
||||
$seo = str_replace('_', '-', $seo);
|
||||
$seo = $object->slug;
|
||||
return \route('adv_detail_seo', [$seo, $id]);
|
||||
}
|
||||
$id = $object->getObject()->id;
|
||||
$seo = str_slug($object->getObject()->name);
|
||||
$seo = str_replace('_', '-', $seo);
|
||||
$seo = $object->getObject()->slug;
|
||||
return \route('adv_detail_seo', [$seo, $id]);
|
||||
}
|
||||
|
||||
@ -233,8 +231,7 @@ class AdvModel extends AdvsAdvsEntryModel implements AdvInterface
|
||||
$adv = $this->find($id);
|
||||
if ($adv != null) {
|
||||
$id = $adv->id;
|
||||
$seo = str_slug($adv->name);
|
||||
$seo = str_replace('_', '-', $seo);
|
||||
$seo = $adv->slug;
|
||||
return \route('adv_detail_seo', [$seo, $id]);
|
||||
}
|
||||
}
|
||||
|
||||
@ -244,6 +244,20 @@ class AdvRepository extends EntryRepository implements AdvRepositoryInterface
|
||||
return $adv;
|
||||
}
|
||||
|
||||
public function findByIDAndSlug($id, $slug)
|
||||
{
|
||||
$adv = $this->newQuery()
|
||||
->where('advs_advs.id', $id)
|
||||
->where('slug', $slug)
|
||||
->first();
|
||||
|
||||
if ($adv) {
|
||||
$adv = $this->getLocationNames($adv);
|
||||
}
|
||||
|
||||
return $adv;
|
||||
}
|
||||
|
||||
public function getListItemAdv($id)
|
||||
{
|
||||
$adv = $this->model
|
||||
|
||||
@ -21,6 +21,8 @@ interface AdvRepositoryInterface extends EntryRepositoryInterface
|
||||
|
||||
public function getCatNames($adv);
|
||||
|
||||
public function findByIDAndSlug($id, $slug);
|
||||
|
||||
public function cover_image_update($adv);
|
||||
|
||||
public function getRecommendedAds($id);
|
||||
|
||||
@ -135,10 +135,6 @@ class AdvsController extends PublicController
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Contracts\View\View|mixed
|
||||
*/
|
||||
public function index($category = null, $city = null)
|
||||
{
|
||||
$customParameters = array();
|
||||
@ -481,9 +477,12 @@ class AdvsController extends PublicController
|
||||
|
||||
public function view($seo, $id = null)
|
||||
{
|
||||
$id = is_null($id) ? $seo : $id;
|
||||
|
||||
$adv = $this->adv_repository->getListItemAdv($id);
|
||||
if ($id) {
|
||||
$adv = $this->adv_repository->findByIDAndSlug($id, $seo);
|
||||
} else {
|
||||
$id = $seo;
|
||||
$adv = $this->adv_repository->getListItemAdv($id);
|
||||
}
|
||||
|
||||
if ($adv && ((!$adv->expired() && $adv->getStatus() === 'approved') || $adv->created_by_id === \auth()->id())) {
|
||||
// Check if created by exists
|
||||
|
||||
@ -176,15 +176,16 @@ class CategoryModel extends CatsCategoryEntryModel implements CategoryInterface
|
||||
$categories = array();
|
||||
$z = 1;
|
||||
for ($i = 1; $i <= $z; $i++) {
|
||||
$main = $this->newQuery()->where('id', $id)->first();
|
||||
$new = array();
|
||||
$new['id'] = $main->id;
|
||||
$new['val'] = $main->name;
|
||||
$new['slug'] = $main->slug;
|
||||
$categories[] = $new;
|
||||
if ($main->parent_category_id != null) {
|
||||
$id = $main->parent_category_id;
|
||||
$z++;
|
||||
if ($main = $this->newQuery()->where('id', $id)->first()) {
|
||||
$new = array();
|
||||
$new['id'] = $main->id;
|
||||
$new['val'] = $main->name;
|
||||
$new['slug'] = $main->slug;
|
||||
$categories[] = $new;
|
||||
if ($main->parent_category_id != null) {
|
||||
$id = $main->parent_category_id;
|
||||
$z++;
|
||||
}
|
||||
}
|
||||
}
|
||||
$categories = array_reverse($categories);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user