setSegment('exitPageUrl'); * $segment->setName('Actions_ColumnExitPageURL'); * $segment->setCategory('General_Visit'); * $this->addSegment($segment); * ``` */ protected function configureSegments() { } /** * Check whether a dimension has overwritten a specific method. * @param $method * @return bool * @ignore */ public function hasImplementedEvent($method) { $method = new \ReflectionMethod($this, $method); $declaringClass = $method->getDeclaringClass(); return 0 === strpos($declaringClass->name, 'Piwik\Plugins'); } /** * Adds a new segment. The segment type will be set to 'dimension' automatically if not already set. * @param Segment $segment * @api */ protected function addSegment(Segment $segment) { $type = $segment->getType(); if (empty($type)) { $segment->setType(Segment::TYPE_DIMENSION); } $this->segments[] = $segment; } /** * Get the list of configured segments. * @return Segment[] * @ignore */ public function getSegments() { if (empty($this->segments)) { $this->configureSegments(); } return $this->segments; } /** * Get the name of the dimension column. * @return string * @ignore */ public function getColumnName() { return $this->columnName; } /** * Check whether the dimension has a column type configured * @return bool * @ignore */ public function hasColumnType() { return !empty($this->columnType); } /** * Get the translated name of the dimension. Defaults to an empty string. * @return string * @api */ public function getName() { return ''; } /** * Returns a unique string ID for this dimension. The ID is built using the namespaced class name * of the dimension, but is modified to be more human readable. * * @return string eg, `"Referrers.Keywords"` * @throws Exception if the plugin and simple class name of this instance cannot be determined. * This would only happen if the dimension is located in the wrong directory. * @api */ public function getId() { $className = get_class($this); // parse plugin name & dimension name $regex = "/Piwik\\\\Plugins\\\\([^\\\\]+)\\\\" . self::COMPONENT_SUBNAMESPACE . "\\\\([^\\\\]+)/"; if (!preg_match($regex, $className, $matches)) { throw new Exception("'$className' is located in the wrong directory."); } $pluginName = $matches[1]; $dimensionName = $matches[2]; return $pluginName . '.' . $dimensionName; } /** * Gets an instance of all available visit, action and conversion dimension. * @return Dimension[] */ public static function getAllDimensions() { $dimensions = array(); foreach (VisitDimension::getAllDimensions() as $dimension) { $dimensions[] = $dimension; } foreach (ActionDimension::getAllDimensions() as $dimension) { $dimensions[] = $dimension; } foreach (ConversionDimension::getAllDimensions() as $dimension) { $dimensions[] = $dimension; } return $dimensions; } public static function getDimensions(Plugin $plugin) { $dimensions = array(); foreach (VisitDimension::getDimensions($plugin) as $dimension) { $dimensions[] = $dimension; } foreach (ActionDimension::getDimensions($plugin) as $dimension) { $dimensions[] = $dimension; } foreach (ConversionDimension::getDimensions($plugin) as $dimension) { $dimensions[] = $dimension; } return $dimensions; } /** * Creates a Dimension instance from a string ID (see {@link getId()}). * * @param string $dimensionId See {@link getId()}. * @return Dimension|null The created instance or null if there is no Dimension for * $dimensionId or if the plugin that contains the Dimension is * not loaded. * @api */ public static function factory($dimensionId) { list($module, $dimension) = explode('.', $dimensionId); return ComponentFactory::factory($module, $dimension, __CLASS__); } /** * Returns the name of the plugin that contains this Dimension. * * @return string * @throws Exception if the Dimension is not located within a Plugin module. * @api */ public function getModule() { $id = $this->getId(); if (empty($id)) { throw new Exception("Invalid dimension ID: '$id'."); } $parts = explode('.', $id); return reset($parts); } }