/** * UserListType constructor. * * @param UserModel $model */ public function __construct(UserModel $model) { $choices = $model->getRepository()->getEntities(['filter' => ['force' => [['column' => 'u.isPublished', 'expr' => 'eq', 'value' => true]]]]); foreach ($choices as $choice) { $this->choices[$choice->getId()] = $choice->getName(true); } //sort by language ksort($this->choices); }
/** * Populates namespace, bundle, controller, and action into request to be used throughout application. * * @param FilterControllerEvent $event */ public function onKernelController(FilterControllerEvent $event) { $controller = $event->getController(); if (!is_array($controller)) { return; } //only affect Mautic controllers if ($controller[0] instanceof MauticController) { $request = $event->getRequest(); //also set the request for easy access throughout controllers $controller[0]->setRequest($request); // set the factory for easy use access throughout the controllers // @deprecated To be removed in 3.0 $controller[0]->setFactory($this->factory); // set the user as well $controller[0]->setUser($this->userHelper->getUser()); // and the core parameters helper $controller[0]->setCoreParametersHelper($this->coreParametersHelper); // and the dispatcher $controller[0]->setDispatcher($this->dispatcher); // and the translator $controller[0]->setTranslator($this->translator); //run any initialize functions $controller[0]->initialize($event); //update the user's activity marker if (!$controller[0] instanceof InstallController && !defined('MAUTIC_ACTIVITY_CHECKED') && !defined('MAUTIC_INSTALLER')) { //prevent multiple updates $user = $this->userHelper->getUser(); //slight delay to prevent too many updates //note that doctrine will return in current timezone so we do not have to worry about that $delay = new \DateTime(); $delay->setTimestamp(strtotime('2 minutes ago')); if ($user instanceof User && $user->getLastActive() < $delay && $user->getId()) { $this->userModel->getRepository()->setLastActive($user); } $session = $request->getSession(); if ($session) { $delay = new \DateTime(); $delay->setTimestamp(strtotime('15 minutes ago')); $lastOnlineStatusCleanup = $session->get('mautic.online.status.cleanup', $delay); if ($lastOnlineStatusCleanup <= $delay) { $this->userModel->getRepository()->updateOnlineStatuses(); $session->set('mautic.online.status.cleanup', new \DateTime()); } define('MAUTIC_ACTIVITY_CHECKED', 1); } } } }
/** * Add available tables and columns to the report builder lookup. * * @param ReportBuilderEvent $event */ public function onReportBuilder(ReportBuilderEvent $event) { $leadContexts = ['leads', 'lead.pointlog', 'contact.attribution.multi', 'contact.attribution.first', 'contact.attribution.last']; if ($event->checkContext($leadContexts)) { $columns = ['l.id' => ['label' => 'mautic.lead.report.contact_id', 'type' => 'int', 'link' => 'mautic_contact_action'], 'i.ip_address' => ['label' => 'mautic.core.ipaddress', 'type' => 'text'], 'l.date_identified' => ['label' => 'mautic.lead.report.date_identified', 'type' => 'datetime'], 'l.points' => ['label' => 'mautic.lead.points', 'type' => 'int'], 'l.owner_id' => ['label' => 'mautic.lead.report.owner_id', 'type' => 'int', 'link' => 'mautic_user_action'], 'u.first_name' => ['label' => 'mautic.lead.report.owner_firstname', 'type' => 'string'], 'u.last_name' => ['label' => 'mautic.lead.report.owner_lastname', 'type' => 'string']]; $leadFields = $this->fieldModel->getEntities(); $fieldColumns = []; foreach ($leadFields as $f) { switch ($f->getType()) { case 'boolean': $type = 'bool'; break; case 'date': $type = 'date'; break; case 'datetime': $type = 'datetime'; break; case 'time': $type = 'time'; break; case 'url': $type = 'url'; break; case 'email': $type = 'email'; break; case 'number': $type = 'float'; break; default: $type = 'string'; break; } $fieldColumns['l.' . $f->getAlias()] = ['label' => $f->getLabel(), 'type' => $type]; } $filters = $columns = array_merge($columns, $fieldColumns); // Append segment filters $userSegments = $this->listModel->getUserLists(); $list = []; foreach ($userSegments as $segment) { $list[$segment['id']] = $segment['name']; } $filters['s.leadlist_id'] = ['alias' => 'segment_id', 'label' => 'mautic.core.filter.lists', 'type' => 'select', 'list' => $list, 'operators' => ['eq' => 'mautic.core.operator.equals']]; $filters['l.owner_id'] = ['label' => 'mautic.lead.list.filter.owner', 'type' => 'select', 'list' => $this->userModel->getRepository()->getUserList('', 0)]; $data = ['display_name' => 'mautic.lead.leads', 'columns' => $columns, 'filters' => $filters]; $event->addTable('leads', $data, 'contacts'); $attributionTypes = ['contact.attribution.multi', 'contact.attribution.first', 'contact.attribution.last']; if ($event->checkContext($attributionTypes)) { $context = $event->getContext(); foreach ($attributionTypes as $attributionType) { if (empty($context) || $event->checkContext($attributionType)) { $type = str_replace('contact.attribution.', '', $attributionType); $this->injectAttributionReportData($event, $columns, $type); } } } if ($event->checkContext(['leads', 'lead.pointlog'])) { // Add shared graphs $event->addGraph('leads', 'line', 'mautic.lead.graph.line.leads'); if ($event->checkContext('lead.pointlog')) { $this->injectPointsReportData($event, $columns); } } } }