示例#1
0
 /**
  * @param MauticEvents\GlobalSearchEvent $event
  */
 public function onGlobalSearch(MauticEvents\GlobalSearchEvent $event)
 {
     $str = $event->getSearchString();
     if (empty($str)) {
         return;
     }
     $filter = ['string' => $str, 'force' => []];
     $permissions = $this->security->isGranted(['report:reports:viewown', 'report:reports:viewother'], 'RETURN_ARRAY');
     if ($permissions['report:reports:viewown'] || $permissions['report:reports:viewother']) {
         if (!$permissions['report:reports:viewother']) {
             $filter['force'][] = ['column' => 'IDENTITY(r.createdBy)', 'expr' => 'eq', 'value' => $this->userHelper->getUser()->getId()];
         }
         $items = $this->reportModel->getEntities(['limit' => 5, 'filter' => $filter]);
         $count = count($items);
         if ($count > 0) {
             $results = [];
             foreach ($items as $item) {
                 $results[] = $this->templating->renderResponse('MauticReportBundle:SubscribedEvents\\Search:global.html.php', ['item' => $item])->getContent();
             }
             if ($count > 5) {
                 $results[] = $this->templating->renderResponse('MauticReportBundle:SubscribedEvents\\Search:global.html.php', ['showMore' => true, 'searchString' => $str, 'remaining' => $count - 5])->getContent();
             }
             $results['count'] = $count;
             $event->addResults('mautic.report.reports', $results);
         }
     }
 }