부터: 2.5.0
예제 #1
0
 public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true, $isAuthenticatedWithViewAccess)
 {
     $segments = array();
     /**
      * Triggered to add custom segment definitions.
      *
      * **Example**
      *
      *     public function addSegments(&$segments)
      *     {
      *         $segment = new Segment();
      *         $segment->setSegment('my_segment_name');
      *         $segment->setType(Segment::TYPE_DIMENSION);
      *         $segment->setName('My Segment Name');
      *         $segment->setSqlSegment('log_table.my_segment_name');
      *         $segments[] = $segment;
      *     }
      *
      * @param array &$segments An array containing a list of segment entries.
      */
     Piwik::postEvent('Segment.addSegments', array(&$segments));
     foreach (Dimension::getAllDimensions() as $dimension) {
         foreach ($dimension->getSegments() as $segment) {
             $segments[] = $segment;
         }
     }
     /** @var Segment[] $dimensionSegments */
     $dimensionSegments = $segments;
     $segments = array();
     foreach ($dimensionSegments as $segment) {
         if ($segment->isRequiresAtLeastViewAccess()) {
             $segment->setPermission($isAuthenticatedWithViewAccess);
         }
         $segments[] = $segment->toArray();
     }
     foreach ($segments as &$segment) {
         $segment['name'] = Piwik::translate($segment['name']);
         $segment['category'] = Piwik::translate($segment['category']);
         if ($_hideImplementationData) {
             unset($segment['sqlFilter']);
             unset($segment['sqlFilterValue']);
             unset($segment['sqlSegment']);
             if (isset($segment['suggestedValuesCallback']) && !is_string($segment['suggestedValuesCallback'])) {
                 unset($segment['suggestedValuesCallback']);
             }
         }
     }
     usort($segments, array($this, 'sortSegments'));
     return $segments;
 }
예제 #2
0
 /**
  * @param Dimension|null $lhs
  * @param Dimension|null $rhs
  * @return bool
  */
 private static function areDimensionsNotEqualAndNotNull($lhs, $rhs)
 {
     return !empty($lhs) && !empty($rhs) && $lhs->getId() != $rhs->getId();
 }
예제 #3
0
 /**
  * Finds a top level report that provides stats for a specific Dimension.
  *
  * @param Dimension $dimension The dimension whose report we're looking for.
  * @return Report|null The
  * @api
  */
 public static function getForDimension(Dimension $dimension)
 {
     return ComponentFactory::getComponentIf(__CLASS__, $dimension->getModule(), function (Report $report) use($dimension) {
         return !$report->isSubtableReport() && $report->getDimension() && $report->getDimension()->getId() == $dimension->getId();
     });
 }
예제 #4
0
 /**
  * Adds a new segment. It automatically sets the SQL segment depending on the column name in case none is set
  * already.
  * @see \Piwik\Columns\Dimension::addSegment()
  * @param Segment $segment
  * @api
  */
 protected function addSegment(Segment $segment)
 {
     $sqlSegment = $segment->getSqlSegment();
     if (!empty($this->columnName) && empty($sqlSegment)) {
         $segment->setSqlSegment($this->tableName . '.' . $this->columnName);
     }
     parent::addSegment($segment);
 }
예제 #5
0
 /**
  * @param ConversionDimension|VisitDimension|ActionDimension $dimension
  */
 private function uninstallDimension(Dimension $dimension)
 {
     $dimension->uninstall();
     Option::delete('version_' . $dimension->getVersion());
 }
예제 #6
0
 public function test_factory_ShouldCreateDimensionFromDimensionId()
 {
     Manager::getInstance()->loadPlugins(array('ExampleTracker'));
     $dimension = Dimension::factory("ExampleTracker.ExampleDimension");
     $this->assertInstanceOf("Piwik\\Plugins\\ExampleTracker\\Columns\\ExampleDimension", $dimension);
 }
예제 #7
0
 /**
  * Builts the report metadata for this report. Can be useful in case you want to change the behavior of
  * {@link configureReportMetadata()}.
  * @return array
  * @ignore
  */
 protected function buildReportMetadata()
 {
     $report = array('category' => $this->getCategory(), 'name' => $this->getName(), 'module' => $this->getModule(), 'action' => $this->getAction());
     if (null !== $this->parameters) {
         $report['parameters'] = $this->parameters;
     }
     if (!empty($this->dimension)) {
         $report['dimension'] = $this->dimension->getName();
     }
     if (!empty($this->documentation)) {
         $report['documentation'] = $this->documentation;
     }
     if (true === $this->isSubtableReport) {
         $report['isSubtableReport'] = $this->isSubtableReport;
     }
     $report['metrics'] = $this->getMetrics();
     $report['metricsDocumentation'] = $this->getMetricsDocumentation();
     $report['processedMetrics'] = $this->getProcessedMetrics();
     if (!empty($this->actionToLoadSubTables)) {
         $report['actionToLoadSubTables'] = $this->actionToLoadSubTables;
     }
     if (true === $this->constantRowsCount) {
         $report['constantRowsCount'] = $this->constantRowsCount;
     }
     $report['order'] = $this->order;
     return $report;
 }
예제 #8
0
파일: API.php 프로젝트: mgou-net/piwik
 public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true)
 {
     if (empty($idSites)) {
         Piwik::checkUserHasSomeViewAccess();
     } else {
         Piwik::checkUserHasViewAccess($idSites);
     }
     $isNotAnonymous = !Piwik::isUserIsAnonymous();
     $segments = array();
     foreach (Dimension::getAllDimensions() as $dimension) {
         foreach ($dimension->getSegments() as $segment) {
             if ($segment->isRequiresAtLeastViewAccess()) {
                 $segment->setPermission($isNotAnonymous);
             }
             $segments[] = $segment->toArray();
         }
     }
     /**
      * Triggered when gathering all available segment dimensions.
      *
      * This event can be used to make new segment dimensions available.
      *
      * **Example**
      *
      *     public function getSegmentsMetadata(&$segments, $idSites)
      *     {
      *         $segments[] = array(
      *             'type'           => 'dimension',
      *             'category'       => Piwik::translate('General_Visit'),
      *             'name'           => 'General_VisitorIP',
      *             'segment'        => 'visitIp',
      *             'acceptedValues' => '13.54.122.1, etc.',
      *             'sqlSegment'     => 'log_visit.location_ip',
      *             'sqlFilter'      => array('Piwik\IP', 'P2N'),
      *             'permission'     => $isAuthenticatedWithViewAccess,
      *         );
      *     }
      *
      * @param array &$dimensions The list of available segment dimensions. Append to this list to add
      *                           new segments. Each element in this list must contain the
      *                           following information:
      *
      *                           - **type**: Either `'metric'` or `'dimension'`. `'metric'` means
      *                                       the value is a numeric and `'dimension'` means it is
      *                                       a string. Also, `'metric'` values will be displayed
      *                                       under **Visit (metrics)** in the Segment Editor.
      *                           - **category**: The segment category name. This can be an existing
      *                                           segment category visible in the segment editor.
      *                           - **name**: The pretty name of the segment. Can be a translation token.
      *                           - **segment**: The segment name, eg, `'visitIp'` or `'searches'`.
      *                           - **acceptedValues**: A string describing one or two exacmple values, eg
      *                                                 `'13.54.122.1, etc.'`.
      *                           - **sqlSegment**: The table column this segment will segment by.
      *                                             For example, `'log_visit.location_ip'` for the
      *                                             **visitIp** segment.
      *                           - **sqlFilter**: A PHP callback to apply to segment values before
      *                                            they are used in SQL.
      *                           - **permission**: True if the current user has view access to this
      *                                             segment, false if otherwise.
      * @param array $idSites The list of site IDs we're getting the available segments
      *                       for. Some segments (such as Goal segments) depend on the
      *                       site.
      */
     Piwik::postEvent('API.getSegmentDimensionMetadata', array(&$segments, $idSites));
     foreach ($segments as &$segment) {
         $segment['name'] = Piwik::translate($segment['name']);
         $segment['category'] = Piwik::translate($segment['category']);
         if ($_hideImplementationData) {
             unset($segment['sqlFilter']);
             unset($segment['sqlFilterValue']);
             unset($segment['sqlSegment']);
             if (isset($segment['suggestedValuesCallback']) && !is_string($segment['suggestedValuesCallback'])) {
                 unset($segment['suggestedValuesCallback']);
             }
         }
     }
     usort($segments, array($this, 'sortSegments'));
     return $segments;
 }
예제 #9
0
파일: API.php 프로젝트: KingNoosh/Teknik
 public function getSegmentsMetadata($idSites = array(), $_hideImplementationData = true)
 {
     $segments = array();
     foreach (Dimension::getAllDimensions() as $dimension) {
         foreach ($dimension->getSegments() as $segment) {
             $segments[] = $segment->toArray();
         }
     }
     /**
      * Triggered when gathering all available segment dimensions.
      *
      * This event can be used to make new segment dimensions available.
      *
      * **Example**
      *
      *     public function getSegmentsMetadata(&$segments, $idSites)
      *     {
      *         $segments[] = array(
      *             'type'           => 'dimension',
      *             'category'       => Piwik::translate('General_Visit'),
      *             'name'           => 'General_VisitorIP',
      *             'segment'        => 'visitIp',
      *             'acceptedValues' => '13.54.122.1, etc.',
      *             'sqlSegment'     => 'log_visit.location_ip',
      *             'sqlFilter'      => array('Piwik\IP', 'P2N'),
      *             'permission'     => $isAuthenticatedWithViewAccess,
      *         );
      *     }
      *
      * @param array &$dimensions The list of available segment dimensions. Append to this list to add
      *                           new segments. Each element in this list must contain the
      *                           following information:
      *
      *                           - **type**: Either `'metric'` or `'dimension'`. `'metric'` means
      *                                       the value is a numeric and `'dimension'` means it is
      *                                       a string. Also, `'metric'` values will be displayed
      *                                       under **Visit (metrics)** in the Segment Editor.
      *                           - **category**: The segment category name. This can be an existing
      *                                           segment category visible in the segment editor.
      *                           - **name**: The pretty name of the segment. Can be a translation token.
      *                           - **segment**: The segment name, eg, `'visitIp'` or `'searches'`.
      *                           - **acceptedValues**: A string describing one or two exacmple values, eg
      *                                                 `'13.54.122.1, etc.'`.
      *                           - **sqlSegment**: The table column this segment will segment by.
      *                                             For example, `'log_visit.location_ip'` for the
      *                                             **visitIp** segment.
      *                           - **sqlFilter**: A PHP callback to apply to segment values before
      *                                            they are used in SQL.
      *                           - **permission**: True if the current user has view access to this
      *                                             segment, false if otherwise.
      * @param array $idSites The list of site IDs we're getting the available segments
      *                       for. Some segments (such as Goal segments) depend on the
      *                       site.
      */
     Piwik::postEvent('API.getSegmentDimensionMetadata', array(&$segments, $idSites));
     $isAuthenticatedWithViewAccess = Piwik::isUserHasViewAccess($idSites) && !Piwik::isUserIsAnonymous();
     $segments[] = array('type' => 'dimension', 'category' => Piwik::translate('General_Visit'), 'name' => 'General_UserId', 'segment' => 'userId', 'acceptedValues' => 'any non empty unique string identifying the user (such as an email address or a username).', 'sqlSegment' => 'log_visit.idvisitor', 'sqlFilterValue' => array('Piwik\\Common', 'convertUserIdToVisitorIdBin'), 'sqlFilter' => array($this, 'checkSegmentMatchTypeIsValidForUser'), 'permission' => $isAuthenticatedWithViewAccess);
     $segments[] = array('type' => 'dimension', 'category' => Piwik::translate('General_Visit'), 'name' => 'General_VisitorID', 'segment' => 'visitorId', 'acceptedValues' => '34c31e04394bdc63 - any 16 Hexadecimal chars ID, which can be fetched using the Tracking API function getVisitorId()', 'sqlSegment' => 'log_visit.idvisitor', 'sqlFilterValue' => array('Piwik\\Common', 'convertVisitorIdToBin'), 'permission' => $isAuthenticatedWithViewAccess);
     $segments[] = array('type' => 'dimension', 'category' => Piwik::translate('General_Visit'), 'name' => Piwik::translate('General_Visit') . " ID", 'segment' => 'visitId', 'acceptedValues' => 'Any integer. ', 'sqlSegment' => 'log_visit.idvisit', 'permission' => $isAuthenticatedWithViewAccess);
     $segments[] = array('type' => 'metric', 'category' => Piwik::translate('General_Visit'), 'name' => 'General_VisitorIP', 'segment' => 'visitIp', 'acceptedValues' => '13.54.122.1. </code>Select IP ranges with notation: <code>visitIp>13.54.122.0;visitIp<13.54.122.255', 'sqlSegment' => 'log_visit.location_ip', 'sqlFilterValue' => array('Piwik\\IP', 'P2N'), 'permission' => $isAuthenticatedWithViewAccess);
     foreach ($segments as &$segment) {
         $segment['name'] = Piwik::translate($segment['name']);
         $segment['category'] = Piwik::translate($segment['category']);
         if ($_hideImplementationData) {
             unset($segment['sqlFilter']);
             unset($segment['sqlFilterValue']);
             unset($segment['sqlSegment']);
         }
     }
     usort($segments, array($this, 'sortSegments'));
     return $segments;
 }
예제 #10
0
 public function test_getAllDimensions_shouldReturnActionVisitAndConversionDimensions()
 {
     Manager::getInstance()->loadPlugins(array('Actions', 'Events', 'DevicesDetector', 'Goals'));
     $dimensions = Dimension::getAllDimensions();
     $this->assertGreaterThan(20, count($dimensions));
     $foundConversion = false;
     $foundVisit = false;
     $foundAction = false;
     foreach ($dimensions as $dimension) {
         if ($dimension instanceof \Piwik\Plugin\Dimension\ConversionDimension) {
             $foundConversion = true;
         } else {
             if ($dimension instanceof \Piwik\Plugin\Dimension\ActionDimension) {
                 $foundAction = true;
             } else {
                 if ($dimension instanceof \Piwik\Plugin\Dimension\VisitDimension) {
                     $foundVisit = true;
                 } else {
                     $this->fail('Unexpected dimension class found');
                 }
             }
         }
         $this->assertRegExp('/Piwik.Plugins.(Actions|Events|DevicesDetector|Goals).Columns/', get_class($dimension));
     }
     $this->assertTrue($foundConversion);
     $this->assertTrue($foundAction);
     $this->assertTrue($foundVisit);
 }
예제 #11
0
 /**
  * @param InputInterface $input
  * @param OutputInterface $output
  * @param string $pluginName
  * @return array
  * @throws \RuntimeException
  */
 protected function getDimension(InputInterface $input, OutputInterface $output, $pluginName)
 {
     $dimensions = array();
     $dimensionNames = array();
     $reports = new ReportsProvider();
     foreach ($reports->getAllReports() as $report) {
         $dimension = $report->getDimension();
         if (is_object($dimension)) {
             $name = $dimension->getName();
             if (!empty($name)) {
                 $dimensions[$name] = get_class($dimension);
                 $dimensionNames[] = $name;
             }
         }
     }
     $plugin = Manager::getInstance()->loadPlugin($pluginName);
     $dimensions = Dimension::getAllDimensions();
     $dimensions = array_merge($dimensions, Dimension::getDimensions($plugin));
     foreach ($dimensions as $dimension) {
         $name = $dimension->getName();
         if (!empty($name)) {
             $dimensions[$name] = get_class($dimension);
             $dimensionNames[] = $name;
         }
     }
     $dimensionNames = array_values(array_unique($dimensionNames));
     $validate = function ($dimension) use($dimensions) {
         if (empty($dimension)) {
             return '';
         }
         if (!empty($dimension) && !array_key_exists($dimension, $dimensions)) {
             throw new \InvalidArgumentException('Leave dimension either empty or use an existing one. You can also create a new dimension by calling .console generate:dimension before generating this report.');
         }
         return $dimension;
     };
     $actualDimension = $input->getOption('dimension');
     if (null === $actualDimension) {
         $dialog = $this->getHelperSet()->get('dialog');
         $actualDimension = $dialog->askAndValidate($output, 'Enter the report dimension, for instance "Browser" (you can leave it either empty or use an existing one): ', $validate, false, null, $dimensionNames);
     } else {
         $validate($actualDimension);
     }
     if (empty($actualDimension)) {
         return array('null', '');
     }
     $className = $dimensions[$actualDimension];
     $parts = explode('\\', $className);
     $name = end($parts);
     return array('new ' . $name . '()', 'use ' . $className . ';');
 }
예제 #12
0
 public static function getSegmentsMetadata()
 {
     // Refresh cache for CustomVariables\Model
     Cache::clearCacheGeneral();
     $segments = array();
     $environment = new Environment(null);
     $exception = null;
     try {
         $environment->init();
         $environment->getContainer()->get('Piwik\\Plugin\\Manager')->loadActivatedPlugins();
         foreach (Dimension::getAllDimensions() as $dimension) {
             if ($dimension instanceof CustomVariableName || $dimension instanceof CustomVariableValue) {
                 continue;
                 // added manually below
             }
             foreach ($dimension->getSegments() as $segment) {
                 $segments[] = $segment->getSegment();
             }
         }
         // add CustomVariables manually since the data provider may not have access to the DB
         for ($i = 1; $i != Model::DEFAULT_CUSTOM_VAR_COUNT + 1; ++$i) {
             $segments = array_merge($segments, self::getCustomVariableSegments($i));
         }
         $segments = array_merge($segments, self::getCustomVariableSegments());
     } catch (\Exception $ex) {
         $exception = $ex;
         echo $ex->getMessage() . "\n" . $ex->getTraceAsString() . "\n";
     }
     $environment->destroy();
     if (!empty($exception)) {
         throw $exception;
     }
     return $segments;
 }