/**
  * See {@link AddSegmentByLabel}.
  *
  * @param DataTable $table
  */
 public function filter($table)
 {
     if (empty($this->segments)) {
         $msg = 'AddSegmentByLabel is called without having any segments defined';
         Development::error($msg);
         return;
     }
     if (count($this->segments) === 1) {
         $segment = reset($this->segments);
         foreach ($table->getRowsWithoutSummaryRow() as $key => $row) {
             $label = $row->getColumn('label');
             if (!empty($label)) {
                 $row->setMetadata('segment', $segment . '==' . urlencode($label));
             }
         }
     } elseif (!empty($this->delimiter)) {
         $numSegments = count($this->segments);
         $conditionAnd = ';';
         foreach ($table->getRowsWithoutSummaryRow() as $key => $row) {
             $label = $row->getColumn('label');
             if (!empty($label)) {
                 $parts = explode($this->delimiter, $label);
                 if (count($parts) === $numSegments) {
                     $filter = array();
                     foreach ($this->segments as $index => $segment) {
                         if (!empty($segment)) {
                             $filter[] = $segment . '==' . urlencode($parts[$index]);
                         }
                     }
                     $row->setMetadata('segment', implode($conditionAnd, $filter));
                 }
             }
         }
     } else {
         $names = implode(', ', $this->segments);
         $msg = 'Multiple segments are given but no delimiter defined. Segments: ' . $names;
         Development::error($msg);
     }
 }
Esempio n. 2
0
 private function checkIsValidWidget(WidgetConfig $widget)
 {
     if (!$widget->getModule()) {
         Development::error('No module is defined for added widget having name "' . $widget->getName());
     }
     if (!$widget->getAction()) {
         Development::error('No action is defined for added widget having name "' . $widget->getName());
     }
 }
Esempio n. 3
0
 private function checkIsValidWidget($name, $method)
 {
     if (!Development::isEnabled()) {
         return;
     }
     if (empty($name)) {
         Development::error('No name is defined for added widget having method "' . $method . '" in ' . get_class($this));
     }
     if (Development::isCallableMethod($this, $method)) {
         return;
     }
     $controllerClass = 'Piwik\\Plugins\\' . $this->getModule() . '\\Controller';
     if (!Development::methodExists($this, $method) && !Development::methodExists($controllerClass, $method)) {
         Development::error('The added method "' . $method . '" neither exists in "' . get_class($this) . '" nor "' . $controllerClass . '". Make sure to define such a method.');
     }
     $definedInClass = get_class($this);
     if (Development::methodExists($controllerClass, $method)) {
         if (Development::isCallableMethod($controllerClass, $method)) {
             return;
         }
         $definedInClass = $controllerClass;
     }
     Development::error('The method "' . $method . '" is not callable on "' . $definedInClass . '". Make sure the method is public.');
 }
Esempio n. 4
0
File: Menu.php Progetto: piwik/piwik
 private function checkisValidCallable($module, $action)
 {
     if (!Development::isEnabled()) {
         return;
     }
     $prefix = 'Menu item added in ' . get_class($this) . ' will fail when being selected. ';
     if (!is_string($action)) {
         Development::error($prefix . 'No valid action is specified. Make sure the defined action that should be executed is a string.');
     }
     $reportAction = lcfirst(substr($action, 4));
     if (ReportsProvider::factory($module, $reportAction)) {
         return;
     }
     $controllerClass = '\\Piwik\\Plugins\\' . $module . '\\Controller';
     if (!Development::methodExists($controllerClass, $action)) {
         Development::error($prefix . 'The defined action "' . $action . '" does not exist in ' . $controllerClass . '". Make sure to define such a method.');
     }
     if (!Development::isCallableMethod($controllerClass, $action)) {
         Development::error($prefix . 'The defined action "' . $action . '" is not callable on "' . $controllerClass . '". Make sure the method is public.');
     }
 }