public function index() { $view = new View('@Widgetize/index'); $view->availableWidgets = Common::json_encode(WidgetsList::get()); $this->setGeneralVariablesView($view); return $view->render(); }
public function test_AvailableWidgetListIsUpToDate() { $namesOfWidgetsThatAreAPI = $this->getWidgetNames($this->getWidgetsThatAreAPI()); Piwik::postEvent('Platform.initialized'); // userCountryMap defines it's Widgets via this event currently $currentWidgetNames = array(); foreach (WidgetsList::get() as $widgets) { $currentWidgetNames = array_merge($this->getWidgetNames($widgets), $currentWidgetNames); } $allWidgetNames = array_merge($namesOfWidgetsThatAreAPI, $currentWidgetNames); $regressedWidgetNames = array_diff($allWidgetNames, $currentWidgetNames); $this->assertEmpty($regressedWidgetNames, 'The widgets list is no longer up to date. If you added, removed or renamed a widget please update `getAvailableWidgets()` otherwise you will need to fix it. Different names: ' . var_export($regressedWidgetNames, 1)); }
/** Creates two dashboards that split the widgets up into different groups. */ public function setupDashboards() { $dashboardColumnCount = 3; $dashboardCount = 4; $layout = array(); for ($j = 0; $j != $dashboardColumnCount; ++$j) { $layout[] = array(); } $dashboards = array(); for ($i = 0; $i != $dashboardCount; ++$i) { $dashboards[] = $layout; } $oldGet = $_GET; $_GET['idSite'] = 1; $_GET['token_auth'] = Fixture::getTokenAuth(); // collect widgets & sort them so widget order is not important $allWidgets = array(); foreach (WidgetsList::get() as $category => $widgets) { $allWidgets = array_merge($allWidgets, $widgets); } usort($allWidgets, function ($lhs, $rhs) { return strcmp($lhs['uniqueId'], $rhs['uniqueId']); }); $widgetsPerDashboard = ceil(count($allWidgets) / $dashboardCount); // group widgets so they will be spread out across 3 dashboards $groupedWidgets = array(); $dashboard = 0; foreach ($allWidgets as $widget) { if ($widget['uniqueId'] == 'widgetSEOgetRank' || $widget['uniqueId'] == 'widgetReferrersgetKeywordsForPage' || $widget['uniqueId'] == 'widgetLivegetVisitorProfilePopup' || $widget['uniqueId'] == 'widgetActionsgetPageTitles' || strpos($widget['uniqueId'], 'widgetExample') === 0) { continue; } $widgetEntry = array('uniqueId' => $widget['uniqueId'], 'parameters' => $widget['parameters']); // dashboard images must have height of less than 4000px to avoid odd discoloration of last line of image $widgetEntry['parameters']['filter_limit'] = 5; $groupedWidgets[$dashboard][] = $widgetEntry; if (count($groupedWidgets[$dashboard]) >= $widgetsPerDashboard) { $dashboard = $dashboard + 1; } // sanity check if ($dashboard >= $dashboardCount) { throw new Exception("Unexpected error: Incorrect dashboard widget placement logic. Something's wrong w/ the code."); } } // distribute widgets in each dashboard $column = 0; foreach ($groupedWidgets as $dashboardIndex => $dashboardWidgets) { foreach ($dashboardWidgets as $widget) { $column = ($column + 1) % $dashboardColumnCount; $dashboards[$dashboardIndex][$column][] = $widget; } } foreach ($dashboards as $id => $layout) { if ($id == 0) { $_GET['name'] = self::makeXssContent('dashboard name' . $id); } else { $_GET['name'] = 'dashboard name' . $id; } $_GET['layout'] = json_encode($layout); $_GET['idDashboard'] = $id + 1; FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout'); } // create empty dashboard $dashboard = array(array(array('uniqueId' => "widgetVisitsSummarygetEvolutionGraphcolumnsArray", 'parameters' => array('module' => 'VisitsSummary', 'action' => 'getEvolutionGraph', 'columns' => 'nb_visits'))), array(), array()); $_GET['name'] = 'D4'; $_GET['layout'] = json_encode($dashboard); $_GET['idDashboard'] = 5; $_GET['idSite'] = 2; FrontController::getInstance()->fetchDispatch('Dashboard', 'saveLayout'); $_GET = $oldGet; }
public function test_configureWidget_shouldMixinWidgetParametersIfSet() { $widgets = WidgetsList::get(); $this->assertCount(0, $widgets); $this->advancedReport->set('widgetParams', array('foo' => 'bar')); $this->advancedReport->configureWidget(WidgetsList::getInstance()); $widgets = WidgetsList::get(); $this->assertCount(1, $widgets); $this->assertEquals(array('module' => 'TestPlugin', 'action' => 'getAdvancedReport', 'foo' => 'bar'), $widgets['Goals_Goals'][0]['parameters']); }
public function getAvailableWidgets() { $this->checkTokenInUrl(); Json::sendHeaderJSON(); return Common::json_encode(WidgetsList::get()); }
/** * @group Core */ public function testRemove() { // setup the access layer $pseudoMockAccess = new FakeAccess(); FakeAccess::$superUser = true; Access::setSingletonInstance($pseudoMockAccess); Fixture::createWebsite('2009-01-04 00:11:42', true); API::getInstance()->addGoal(1, 'Goal 1 - Thank you', 'title', 'Thank you', 'contains', $caseSensitive = false, $revenue = 10, $allowMultipleConversions = 1); $_GET['idSite'] = 1; WidgetsList::_reset(); $widgets = WidgetsList::get(); $this->assertCount(14, $widgets); WidgetsList::remove('SEO', 'NoTeXiStInG'); $widgets = WidgetsList::get(); $this->assertCount(14, $widgets); $this->assertArrayHasKey('SEO', $widgets); $this->assertCount(2, $widgets['SEO']); WidgetsList::remove('SEO', 'SEO_SeoRankings'); $widgets = WidgetsList::get(); $this->assertCount(1, $widgets['SEO']); WidgetsList::remove('SEO'); $widgets = WidgetsList::get(); $this->assertArrayNotHasKey('SEO', $widgets); WidgetsList::_reset(); }
?> " scrolling="no" frameborder="0" marginheight="0" marginwidth="0"></iframe> </div> <br/> <?php $_GET['idSite'] = $idSite; define('PIWIK_INCLUDE_PATH', '../..'); define('PIWIK_ENABLE_DISPATCH', false); define('PIWIK_ENABLE_ERROR_HANDLER', false); define('PIWIK_ENABLE_SESSION_START', false); require_once PIWIK_INCLUDE_PATH . "/index.php"; require_once PIWIK_INCLUDE_PATH . "/core/API/Request.php"; FrontController::getInstance()->init(); $widgets = WidgetsList::get(); foreach ($widgets as $category => $widgetsInCategory) { echo '<h2>' . $category . '</h2>'; foreach ($widgetsInCategory as $widget) { echo '<h3>' . $widget['name'] . '</h3>'; $widgetUrl = UrlHelper::getArrayFromQueryString($url); $widgetUrl['moduleToWidgetize'] = $widget['parameters']['module']; $widgetUrl['actionToWidgetize'] = $widget['parameters']['action']; $parameters = $widget['parameters']; unset($parameters['module']); unset($parameters['action']); foreach ($parameters as $name => $value) { if (is_array($value)) { $value = current($value); } $widgetUrl[$name] = $value;