src/Controller/DefaultController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Pimcore\Controller\FrontendController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use \Pimcore\Model\DataObject\City;
  9. use \Pimcore\Model\DataObject\Ward;
  10. use \Pimcore\Model\DataObject\District;
  11. use Pimcore\Model\DataObject\Service as DataObjectService;
  12. use Pimcore\Model\DataObject;
  13. use Pimcore\Model\Notification\Service\NotificationService;
  14. use Pimcore\Db;
  15. class DefaultController extends BaseController
  16. {    
  17.     private $notificationService;
  18.     public function __construct(
  19.         NotificationService $notificationService
  20.     )
  21.     {
  22.         $this->notificationService $notificationService;
  23.     }
  24.     /**
  25.      * @Route("/notifications", name="notifications")
  26.      */
  27.     public function notifications(Request $request)
  28.     {
  29.         $queryBuilder  Db::getConnection()->createQueryBuilder();
  30.             
  31.         $queryBuilder->addSelect([
  32.             'count(notifications.id) as total'
  33.         ]);
  34.         
  35.         $queryBuilder->from('notifications''notifications');
  36.         $queryBuilder->andWhere('notifications.read = 0');
  37.         $result $queryBuilder->execute()->fetchAll();
  38.         
  39.         $data=0;
  40.         foreach($result as $value){
  41.             $data $value['total'];
  42.         }
  43.         
  44.         return $this->sendResponse(['total' => $data]);
  45.     }
  46.      /**
  47.      * @Template
  48.      * @param Request $request
  49.      * @return array
  50.      */
  51.     public function defaultAction(Request $request)
  52.     {
  53.         return [];
  54.     }
  55. }