Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make banners deletable. #926

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions src/Classes/ServiceAPI/MyRadio_Banner.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public function toDataSource()
'title' => 'Click here to view the Campaigns for this Banner',
'url' => URLUtils::makeURL('Website', 'campaigns', ['bannerid' => $this->getBannerID()]),
],
'delete_link' => [
'display' => 'icon',
'value' => 'trash',
'title' => 'Click here to delete this Banner',
'url' => URLUtils::makeURL('Website', 'deleteBanner', ['bannerid' => $this->getBannerID()]),
],
];

return array_merge(parent::toDataSource(), $data);
Expand Down Expand Up @@ -331,6 +337,22 @@ public static function getBannerTypes()
return self::$db->fetchAll('SELECT banner_type_id, description FROM website.banner_type');
}

/**
* Delete's a banner and it's campaigns.
*
* @param int $banner_id
*
* @return TODO
*/
public function deleteBanner()
{
self::$db->query('BEGIN');
self::$db->query('DELETE FROM website.banner WHERE banner_id=$1', [$this->getBannerID()], true);

self::$db->query('COMMIT');
$this->updateCacheObject();
}

/**
* Generates the form used to Create and Edit Banners.
*
Expand Down Expand Up @@ -395,4 +417,37 @@ function ($x) {
)
);
}

/**
* Generates the form used to Delete Banners.
*
* @return MyRadio_Form
*/
public static function getDeleteForm()
{
return (
new MyRadioForm(
'deleteBannerfrm',
'Website',
'deleteBanner',
[
'debug' => false,
'title' => 'Delete Banner',
]
)
)->addField(
new MyRadioFormField('bannerid', MyRadioFormField::TYPE_HIDDEN)
)->addField(
new MyRadioFormField(
'confirm',
MyRadioFormField::TYPE_CHECK,
[
'label' => 'Are you sure?',
'options' => ['checked' => true],
'required' => true,
'explanation' => 'You are about to delete this banner. Please confirm.'
]
)
);
}
}
37 changes: 37 additions & 0 deletions src/Controllers/Website/deleteBanner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* Edit a Banner.
*/
use \MyRadio\MyRadio\URLUtils;
use \MyRadio\ServiceAPI\MyRadio_Banner;
use \MyRadio\MyRadioException;


if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$data = MyRadio_Banner::getDeleteForm()->readValues();
if (isset($data['bannerid'])) {
MyRadio_Banner::getInstance($data['bannerid'])
->deleteBanner();

//shouldn't be doing this.'
URLUtils::backWithMessage('Banner Deleted! (Not really)');
} else {
//create form
throw new MyRadioException('A Banner ID was not provided by the form for deletion. Please try again.', 'w');
}

} else {
//Not Submitted
if (isset($_REQUEST['bannerid'])) {

//delete form
$banner = MyRadio_Banner::getInstance($_REQUEST['bannerid']);

MyRadio_Banner::getDeleteForm()
->setFieldValue('bannerid', $banner->getBannerID())
->render();
} else {
//create form
throw new MyRadioException('A Banner ID was not provided for deletion. Please try again.', 'w');
}
}
4 changes: 4 additions & 0 deletions src/Public/js/myradio.website.bannerlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ $('.twig-datatable').dataTable(
//campaigns_link
{
sTitle: "View Campaigns"
},
//delete_link
{
sTitle: "Delete Banner"
}
],
"bPaginate": false,
Expand Down