Ejemplo n.º 1
0
 /**
  * Set a widget detail when needed 
  *
  * @param WidgetDetailEvent $event
  *
  * @return void
  */
 public function onWidgetDetailGenerate(WidgetDetailEvent $event)
 {
     if ($event->getType() == 'recent.activity') {
         if (!$event->isCached()) {
             $model = $this->factory->getModel('core.auditLog');
             $height = $event->getWidget()->getHeight();
             $limit = round(($height - 80) / 75);
             $logs = $model->getLogForObject(null, null, null, $limit);
             // Get names of log's items
             $router = $this->factory->getRouter();
             foreach ($logs as $key => &$log) {
                 if (!empty($log['bundle']) && !empty($log['object']) && !empty($log['objectId'])) {
                     try {
                         $model = $this->factory->getModel($log['bundle'] . '.' . $log['object']);
                         $item = $model->getEntity($log['objectId']);
                         if (method_exists($item, $model->getNameGetter())) {
                             $log['objectName'] = $item->{$model->getNameGetter()}();
                             if ($log['bundle'] == 'lead' && $log['objectName'] == 'mautic.lead.lead.anonymous') {
                                 $log['objectName'] = $this->factory->getTranslator()->trans('mautic.lead.lead.anonymous');
                             }
                         } else {
                             $log['objectName'] = '';
                         }
                         $routeName = 'mautic_' . $log['bundle'] . '_action';
                         if ($router->getRouteCollection()->get($routeName) !== null) {
                             $log['route'] = $router->generate('mautic_' . $log['bundle'] . '_action', array('objectAction' => 'view', 'objectId' => $log['objectId']));
                         } else {
                             $log['route'] = false;
                         }
                     } catch (\Exception $e) {
                         unset($logs[$key]);
                     }
                 }
             }
             $iconEvent = new IconEvent($this->factory->getSecurity());
             $this->factory->getDispatcher()->dispatch(CoreEvents::FETCH_ICONS, $iconEvent);
             $event->setTemplateData(array('logs' => $logs, 'icons' => $iconEvent->getIcons()));
         }
         $event->setTemplate('MauticDashboardBundle:Dashboard:recentactivity.html.php');
         $event->stopPropagation();
     }
 }
Ejemplo n.º 2
0
 /**
  * Set a widget detail when needed 
  *
  * @param WidgetDetailEvent $event
  *
  * @return void
  */
 public function checkPermissions(WidgetDetailEvent $event)
 {
     $widgetTypes = array_keys($this->types);
     if ($this->permissions && !$event->hasPermissions($this->permissions) && in_array($event->getType(), $widgetTypes)) {
         $translator = $event->getTranslator();
         $event->setErrorMessage($translator->trans('mautic.dashboard.missing.permission', array('%section%' => $this->bundle)));
         $event->stopPropagation();
         return;
     }
 }