Skip to content
Code-Schnipsel Gruppen Projekte
delete.php 1,62 KiB
Newer Older
  • Learn to ignore specific revisions
  • Patrick Müller's avatar
    Patrick Müller committed
    <?php
    
    /**
     * This file contains package_quiqqer_coupons_ajax_delete
     */
    
    use QUI\ERP\Coupons\Handler;
    use QUI\Utils\Security\Orthos;
    
    /**
    
     * Delete CouponCodes
    
    Patrick Müller's avatar
    Patrick Müller committed
     *
    
     * @param array $ids - CouponCode IDs
    
    Patrick Müller's avatar
    Patrick Müller committed
     * @return bool - success
     */
    QUI::$Ajax->registerFunction(
        'package_quiqqer_coupons_ajax_delete',
        function ($ids) {
    
            $ids = Orthos::clearArray(\json_decode($ids, true));
    
    Patrick Müller's avatar
    Patrick Müller committed
    
            try {
                foreach ($ids as $id) {
                    $CouponCode = Handler::getCouponCode((int)$id);
                    $CouponCode->delete();
                }
            } catch (\QUI\ERP\Coupons\CouponCodeException $Exception) {
                QUI::getMessagesHandler()->addError(
                    QUI::getLocale()->get(
    
                        'quiqqer/coupons',
    
    Patrick Müller's avatar
    Patrick Müller committed
                        'message.ajax.delete.error',
    
    Patrick Müller's avatar
    Patrick Müller committed
                            'error' => $Exception->getMessage()
    
    Patrick Müller's avatar
    Patrick Müller committed
                    )
                );
    
                return false;
            } catch (QUI\Permissions\Exception $Exception) {
                throw $Exception;
            } catch (\Exception $Exception) {
                QUI\System\Log::writeException($Exception);
    
                QUI::getMessagesHandler()->addError(
                    QUI::getLocale()->get(
    
                        'quiqqer/coupons',
    
    Patrick Müller's avatar
    Patrick Müller committed
                        'message.ajax.general_error'
                    )
                );
    
                return false;
            }
    
            QUI::getMessagesHandler()->addSuccess(
                QUI::getLocale()->get(
    
                    'quiqqer/coupons',
    
    Patrick Müller's avatar
    Patrick Müller committed
                    'message.ajax.delete.success'
                )
            );
    
            return true;
        },
    
    Patrick Müller's avatar
    Patrick Müller committed
        'Permission::checkAdminUser'
    );