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
Parziphal 12e3a57053 more changes related to advertisements.
added position to advertisements. with it, one can choose to either show an horizontal add only at top, bottom or both.
removed can_see_ads check from AdvertisementsHelper::print_advertisement() because it's already checked before calling it.
horizontal-bottom ads in post#index are centered.
removed "Reset hit count" checkbox in ads#edit.
Width and Height in ads form are now "number" fields.
Width and Height must now be set also for "Html" ads.
made ads#show a little nicer.
ads#create and ads#update redirect to ads#index if success.
some other related changes.

made ad#show a little nicer
2013-12-05 15:09:26 -05:00

88 lines
2.4 KiB
PHP
Executable File

<?php
class AdvertisementsController extends ApplicationController
{
protected function filters()
{
return [
'before' => [
'admin_only' => ['except' => ['redirect']]
]
];
}
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');
} 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');
} 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);
}
}