* @copyright Since 2007 PrestaShop SA and Contributors * @license https://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) */ namespace PrestaShopBundle\Controller\Admin\Configure; use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Command\CloseShowcaseCardCommand; use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Exception\InvalidShowcaseCardNameException; use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\ValueObject\ShowcaseCard; use PrestaShopBundle\Controller\Admin\FrameworkBundleAdminController; use PrestaShopBundle\Security\Annotation\AdminSecurity; use PrestaShopBundle\Security\Annotation\DemoRestricted; use Symfony\Component\HttpFoundation\JsonResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; /** * @todo Move this to API */ class ShowcaseCardController extends FrameworkBundleAdminController { /** * Saves the user preference of closing the showcase card. * * This action should be performed via POST, and expects two parameters: * - int $close=1 * - string $name Name of the showcase card to close * * @see ShowcaseCard * * @AdminSecurity( * "is_granted('create', 'CONFIGURE') && is_granted('update', 'CONFIGURE')" * ) * @DemoRestricted(redirectRoute="admin_metas_index") * * @return JsonResponse */ public function closeShowcaseCardAction(Request $request) { // check prerequisites if (!$request->isMethod('post') || !$request->request->get('close')) { return $this->json( [ 'success' => false, 'message' => '', ], Response::HTTP_BAD_REQUEST ); } try { $employeeId = $this->getContext()->employee->id; $closeShowcaseCard = new CloseShowcaseCardCommand($employeeId, $request->request->get('name')); $this->getCommandBus()->handle($closeShowcaseCard); return $this->json( [ 'success' => true, 'message' => '', ] ); } catch (\Exception $e) { return $this->json( [ 'success' => false, 'message' => $e->getMessage(), ], ($e instanceof InvalidShowcaseCardNameException) ? Response::HTTP_BAD_REQUEST : Response::HTTP_INTERNAL_SERVER_ERROR ); } } }