Skip to content
Code-Schnipsel Gruppen Projekte
getList.php 1,26 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_getList
     */
    
    use QUI\ERP\Coupons\Handler;
    use QUI\Utils\Security\Orthos;
    use QUI\Utils\Grid;
    use QUI\Permissions\Permission;
    
    /**
     * Get list of CouponCodes
     *
     * @param array $searchParams
     * @return array
     */
    QUI::$Ajax->registerFunction(
        'package_quiqqer_coupons_ajax_getList',
        function ($searchParams) {
            Permission::hasPermission(Handler::PERMISSION_VIEW);
    
            $searchParams = Orthos::clearArray(json_decode($searchParams, true));
            $inviteCodes  = array();
    
            try {
                foreach (Handler::search($searchParams) as $InviteCode) {
                    $inviteCodes[] = $InviteCode->toArray();
                }
            } catch (\Exception $Exception) {
                QUI\System\Log::writeException($Exception);
    
                QUI::getMessagesHandler()->addSuccess(
                    QUI::getLocale()->get(
                        'quiqqer/invitecode',
                        'message.ajax.general_error'
                    )
                );
    
                return false;
            }
    
            $Grid = new Grid($searchParams);
    
            return $Grid->parseResult(
                $inviteCodes,
                Handler::search($searchParams, true)
            );
        },
        array('searchParams'),
        'Permission::checkAdminUser'
    );