assetsController = $assetsController; $this->pageRenderer = $pageRenderer; $this->automationStorage = $automationStorage; $this->automationMapper = $automationMapper; $this->registry = $registry; $this->wp = $wp; } public function render() { $this->assetsController->setupAutomationAnalyticsDependencies(); $id = isset($_GET['id']) ? (int)$_GET['id'] : null; $automation = $id ? $this->automationStorage->getAutomation($id) : null; if (!$automation) { $notice = new WPNotice( WPNotice::TYPE_ERROR, __('Automation not found.', 'mailpoet') ); $notice->displayWPNotice(); $this->pageRenderer->displayPage('blank.html'); return; } $this->pageRenderer->displayPage('automation/analytics.html', [ 'registry' => $this->buildRegistry(), 'context' => $this->buildContext(), 'automation' => $this->automationMapper->buildAutomation($automation), 'locale_full' => $this->wp->getLocale(), 'api' => [ 'root' => rtrim($this->wp->escUrlRaw($this->wp->restUrl()), '/'), 'nonce' => $this->wp->wpCreateNonce('wp_rest'), ], 'jsonapi' => [ 'root' => rtrim($this->wp->escUrlRaw(admin_url('admin-ajax.php')), '/'), ], ]); } private function buildRegistry(): array { $steps = []; foreach ($this->registry->getSteps() as $key => $step) { $steps[$key] = [ 'key' => $step->getKey(), 'name' => $step->getName(), 'args_schema' => $step->getArgsSchema()->toArray(), ]; } $subjects = []; foreach ($this->registry->getSubjects() as $key => $subject) { $subjects[$key] = [ 'key' => $subject->getKey(), 'name' => $subject->getName(), 'args_schema' => $subject->getArgsSchema()->toArray(), 'field_keys' => array_map(function ($field) { return $field->getKey(); }, $subject->getFields()), ]; } return [ 'steps' => $steps, 'subjects' => $subjects, ]; } private function buildContext(): array { $data = []; foreach ($this->registry->getContextFactories() as $key => $factory) { $data[$key] = $factory(); } return $data; } }