diff --git a/src/Classes/ServiceAPI/MyRadio_Banner.php b/src/Classes/ServiceAPI/MyRadio_Banner.php index 21f3e0916..f023819bd 100755 --- a/src/Classes/ServiceAPI/MyRadio_Banner.php +++ b/src/Classes/ServiceAPI/MyRadio_Banner.php @@ -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); @@ -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. * @@ -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.' + ] + ) + ); + } } diff --git a/src/Controllers/Website/deleteBanner.php b/src/Controllers/Website/deleteBanner.php new file mode 100644 index 000000000..d1d66711a --- /dev/null +++ b/src/Controllers/Website/deleteBanner.php @@ -0,0 +1,37 @@ +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'); + } + } diff --git a/src/Public/js/myradio.website.bannerlist.js b/src/Public/js/myradio.website.bannerlist.js index 8dfe00a77..d831bd84a 100644 --- a/src/Public/js/myradio.website.bannerlist.js +++ b/src/Public/js/myradio.website.bannerlist.js @@ -49,6 +49,10 @@ $('.twig-datatable').dataTable( //campaigns_link { sTitle: "View Campaigns" + }, + //delete_link + { + sTitle: "Delete Banner" } ], "bPaginate": false,