This repository has been archived on 2024-10-25. You can view files and clone it, but cannot push or open issues or pull requests.
Sequenzia/app/controllers/AdvertisementsController.php

88 lines
2.4 KiB
PHP
Raw Normal View History

2013-11-21 20:08:11 +01:00
<?php
class AdvertisementsController extends ApplicationController
{
protected function filters()
{
return [
2013-11-30 00:13:31 +01:00
'before' => [
'admin_only' => ['except' => ['redirect']]
]
2013-11-21 20:08:11 +01:00
];
}
public function index()
{
$this->ads = Advertisement::paginate($this->page_number(), 100);
}
public function show()
{
$this->ad = Advertisement::find($this->params()->id);
}
public function blank()
{
$this->ad = new Advertisement();
}
public function create()
{
$this->ad = new Advertisement($this->params()->advertisement);
if ($this->ad->save()) {
$this->notice('Advertisement added');
$this->redirectTo('#index');
2013-11-21 20:08:11 +01:00
} else {
$this->render('blank');
}
}
public function edit()
{
$this->ad = Advertisement::find($this->params()->id);
}
public function update()
{
$this->ad = Advertisement::find($this->params()->id);
if ($this->ad->updateAttributes($this->params()->advertisement)) {
$this->notice('Advertisement updated');
$this->redirectTo('#index');
2013-11-21 20:08:11 +01:00
} else {
$this->render('blank');
}
}
public function updateMultiple()
{
if ($this->params()->advertisement_ids) {
$ids = array_map(function($a) { return (int)$a; }, $this->params()->advertisement_ids);
} else {
$this->notice('No advertisement selected');
$this->redirectTo($this->advertisementsPath());
return;
}
if ($this->params()->do_delete) {
Advertisement::destroyAll(['id' => $ids]);
} elseif ($this->params()->do_reset_hit_count) {
Advertisement::reset_hit_count($ids);
}
$this->notice('Advertisements updated');
$this->redirectTo($this->advertisementsPath());
}
public function destroy()
{
$ad = Advertisement::find($this->params()->id);
$ad->destroy();
$this->notice('Deleted advertisement ' . $ad->id);
$this->redirectTo($this->advertisementsPath());
}
public function redirect()
{
$ad = Advertisement::find($this->params()->id);
$ad->increment('hit_count');
$this->redirectTo($ad->referral_url);
}
}