Ejemplo n.º 1
0
    /**
     * Utility function that returns HTML that displays Goal information for reports. This
     * is the HTML that is at the bottom of every goals page.
     *
     * @param int $conversions The number of conversions for this goal (or all goals
     *                         in case of the overview).
     * @param bool $ecommerce Whether to show ecommerce reports or not.
     * @param bool $cartNbConversions Whether there are cart conversions or not for this
     *                                goal.
     * @return string
     */
    private function getGoalReportsByDimensionTable($conversions, $ecommerce = false, $cartNbConversions = false)
    {
        $preloadAbandonedCart = $cartNbConversions !== false && $conversions == 0;

        $goalReportsByDimension = new ReportsByDimension('Goals');

        // add ecommerce reports
        $ecommerceCustomParams = array();
        if ($ecommerce) {
            if ($preloadAbandonedCart) {
                $ecommerceCustomParams['abandonedCarts'] = '1';
            } else {
                $ecommerceCustomParams['abandonedCarts'] = '0';
            }
        }

        if ($conversions > 0 || $ecommerce) {
            // for non-Goals reports, we show the goals table
            $customParams = $ecommerceCustomParams + array('documentationForGoalsPage' => '1');

            if (Common::getRequestVar('idGoal', '') === '') // if no idGoal, use 0 for overview
            {
                $customParams['idGoal'] = '0'; // NOTE: Must be string! Otherwise Piwik_View_HtmlTable_Goals fails.
            }

            $allReports = Goals::getReportsWithGoalMetrics();
            foreach ($allReports as $category => $reports) {
                if ($ecommerce) {
                    $categoryText = $this->translationHelper->translateEcommerceMetricCategory($category);
                } else {
                    $categoryText = $this->translationHelper->translateGoalMetricCategory($category);
                }

                foreach ($reports as $report) {
                    if (empty($report['viewDataTable'])
                        && empty($report['abandonedCarts'])
                    ) {
                        $report['viewDataTable'] = 'tableGoals';
                    }
                    $customParams['viewDataTable'] = $report['viewDataTable'];

                    $goalReportsByDimension->addReport(
                        $categoryText, $report['name'], $report['module'] . '.' . $report['action'], $customParams);
                }
            }
        }

        return $goalReportsByDimension->render();
    }
Ejemplo n.º 2
0
 private function buildGoalByDimensionView($idGoal, WidgetContainerConfig $container)
 {
     $container->setLayout('ByDimension');
     $ecommerce = $idGoal == Piwik::LABEL_ID_GOAL_IS_ECOMMERCE_ORDER;
     // for non-Goals reports, we show the goals table
     $customParams = array('documentationForGoalsPage' => '1');
     if ($idGoal === '') {
         // if no idGoal, use 0 for overview. Must be string! Otherwise Piwik_View_HtmlTable_Goals fails.
         $customParams['idGoal'] = '0';
     } else {
         $customParams['idGoal'] = $idGoal;
     }
     $translationHelper = new TranslationHelper();
     foreach ($this->allReports as $category => $reports) {
         $order = $this->getSortOrderOfCategory($category) * 100;
         if ($ecommerce) {
             $categoryText = $translationHelper->translateEcommerceMetricCategory($category);
         } else {
             $categoryText = $translationHelper->translateGoalMetricCategory($category);
         }
         foreach ($reports as $report) {
             $order++;
             if (empty($report['viewDataTable']) && empty($report['abandonedCarts'])) {
                 $report['viewDataTable'] = 'tableGoals';
             }
             if (!empty($report['parameters'])) {
                 $params = array_merge($customParams, $report['parameters']);
             } else {
                 $params = $customParams;
             }
             $widget = $this->createWidgetForReport($report['module'], $report['action']);
             if (!empty($report['name'])) {
                 $widget->setName($report['name']);
             }
             $widget->setParameters($params);
             $widget->setCategoryId($categoryText);
             $widget->setSubcategoryId($categoryText);
             $widget->setOrder($order);
             $widget->setIsNotWidgetizable();
             if (!empty($report['viewDataTable'])) {
                 $widget->forceViewDataTable($report['viewDataTable']);
             }
             $container->addWidgetConfig($widget);
         }
     }
 }