/** * @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(['email:emails:viewown', 'email:emails:viewother'], 'RETURN_ARRAY'); if ($permissions['email:emails:viewown'] || $permissions['email:emails:viewother']) { if (!$permissions['email:emails:viewother']) { $filter['force'][] = ['column' => 'IDENTITY(e.createdBy)', 'expr' => 'eq', 'value' => $this->userHelper->getUser()->getId()]; } $emails = $this->emailModel->getEntities(['limit' => 5, 'filter' => $filter]); if (count($emails) > 0) { $emailResults = []; foreach ($emails as $email) { $emailResults[] = $this->templating->renderResponse('MauticEmailBundle:SubscribedEvents\\Search:global.html.php', ['email' => $email])->getContent(); } if (count($emails) > 5) { $emailResults[] = $this->templating->renderResponse('MauticEmailBundle:SubscribedEvents\\Search:global.html.php', ['showMore' => true, 'searchString' => $str, 'remaining' => count($emails) - 5])->getContent(); } $emailResults['count'] = count($emails); $event->addResults('mautic.email.emails', $emailResults); } } }