src/Controller/Admin/AccountController.php line 16

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: Grigor
  5.  * Date: 6/30/20
  6.  * Time: 5:42 PM
  7.  */
  8. namespace App\Controller\Admin;
  9. use App\Entity\Account;
  10. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  11. use Sonata\AdminBundle\Controller\CRUDController as Controller;
  12. use Symfony\Component\HttpFoundation\RedirectResponse;
  13. class AccountController extends Controller
  14. {
  15.     public function enableViewsAction()
  16.     {
  17.         /**
  18.          * @var Account $object
  19.          */
  20.         $object $this->admin->getSubject();
  21.         if (!$object) {
  22.             throw new NotFoundHttpException('Unable to find the object');
  23.         }
  24.         try {
  25.             $object->setDisableViews(false);
  26.             $this->admin->update($object);
  27.             $this->addFlash('sonata_flash_success'sprintf('For %s view calculating has been enabled'$object->getPublicKey()));
  28.         } catch (\Exception $e) {
  29.             $errorMessage $e->getMessage();
  30.             $this->addFlash('sonata_flash_error'$errorMessage);
  31.         }
  32.         return new RedirectResponse($this->admin->generateUrl('list'));
  33.     }
  34.     public function disableViewsAction()
  35.     {
  36.         /**
  37.          * @var Account $object
  38.          */
  39.         $object $this->admin->getSubject();
  40.         if (!$object) {
  41.             throw new NotFoundHttpException('Unable to find the object');
  42.         }
  43.         try {
  44.             $object->setDisableViews(true);
  45.             $this->admin->update($object);
  46.             $this->addFlash('sonata_flash_success'sprintf('For %s view calculating has been disabled'$object->getPublicKey()));
  47.         } catch (\Exception $e) {
  48.             $errorMessage $e->getMessage();
  49.             $this->addFlash('sonata_flash_error'$errorMessage);
  50.         }
  51.         return new RedirectResponse($this->admin->generateUrl('list'));
  52.     }
  53. }