coreParametersHelper->get('cached_data_timeout'); if ('view' == $action) { /** @var Focus $item */ $item = $args['viewParameters']['item']; // For line graphs in the view $dateRangeValues = $this->getCurrentRequest()->get('daterange', []); $dateRangeForm = $this->formFactory->create( DateRangeType::class, $dateRangeValues, [ 'action' => $this->generateUrl( 'mautic_focus_action', [ 'objectAction' => 'view', 'objectId' => $item->getId(), ] ), ] ); $statsDateFrom = new \DateTime($dateRangeForm->get('date_from')->getData()); $statsDateTo = new \DateTime($dateRangeForm->get('date_to')->getData()); $cacheKey = "focus.viewArguments.{$item->getId()}.{$statsDateFrom->getTimestamp()}.{$statsDateTo->getTimestamp()}"; $cacheItem = $this->cacheProvider->getItem($cacheKey); if ($cacheItem->isHit()) { [$stats, $trackables] = $cacheItem->get(); } else { // invalidate cache for entire focus item to keep AJAX loaded data consistent $this->cacheProvider->invalidateTags(["focus.{$item->getId()}"]); /** @var FocusModel $model */ $model = $this->getModel('focus'); $stats = $model->getStats( $item, null, $statsDateFrom, $statsDateTo ); if ('link' === $item->getType()) { $trackableModel = $this->getModel('page.trackable'); \assert($trackableModel instanceof TrackableModel); $trackables = $trackableModel->getTrackableList('focus', $item->getId()); $cacheItem->set([$stats, $trackables]); $cacheItem->expiresAfter($cacheTimeout * 60); $cacheItem->tag("focus.{$item->getId()}"); $this->cacheProvider->save($cacheItem); } } $args['viewParameters']['stats'] = $stats; $args['viewParameters']['dateRangeForm'] = $dateRangeForm->createView(); $args['viewParameters']['showConversionRate'] = true; if (isset($trackables)) { $args['viewParameters']['trackables'] = $trackables; } } return $args; } /** * @return mixed[] */ protected function getPostActionRedirectArguments(array $args, $action): array { $focus = $this->getCurrentRequest()->request->get('focus') ?? []; $updateSelect = 'POST' === $this->getCurrentRequest()->getMethod() ? ($focus['updateSelect'] ?? false) : $this->getCurrentRequest()->get('updateSelect', false); if ($updateSelect) { switch ($action) { case 'new': case 'edit': $passthrough = $args['passthroughVars']; $passthrough = array_merge( $passthrough, [ 'updateSelect' => $updateSelect, 'id' => $args['entity']->getId(), 'name' => $args['entity']->getName(), ] ); $args['passthroughVars'] = $passthrough; break; } } return $args; } /** * @return array */ protected function getEntityFormOptions() { $focus = $this->getCurrentRequest()->request->get('focus') ?? []; $updateSelect = 'POST' === $this->getCurrentRequest()->getMethod() ? ($focus['updateSelect'] ?? false) : $this->getCurrentRequest()->get('updateSelect', false); if ($updateSelect) { return ['update_select' => $updateSelect]; } } /** * Return array of options update select response. * * @param string $updateSelect HTML id of the select * @param object $entity * @param string $nameMethod name of the entity method holding the name * @param string $groupMethod name of the entity method holding the select group */ protected function getUpdateSelectParams($updateSelect, $entity, $nameMethod = 'getName', $groupMethod = 'getLanguage'): array { return [ 'updateSelect' => $updateSelect, 'id' => $entity->getId(), 'name' => $entity->$nameMethod(), ]; } }