PHP Class Piwik\Segment

A segment is a condition used to filter visits. They can, for example, select visits that have a specific browser or come from a specific country, or both. Individual segment dimensions (such as browserCode and countryCode) are defined by plugins. Read about the {@hook API.getSegmentDimensionMetadata} event to learn more. Plugins that aggregate data stored in Piwik can support segments by using this class when generating aggregation SQL queries. ### Examples **Basic usage** $idSites = array(1,2,3); $segmentStr = "browserCode==ff;countryCode==CA"; $segment = new Segment($segmentStr, $idSites); $query = $segment->getSelectQuery( $select = "table.col1, table2.col2", $from = array("table", "table2"), $where = "table.col3 = ?", $bind = array(5), $orderBy = "table.col1 DESC", $groupBy = "table2.col2" ); Db::fetchAll($query['sql'], $query['bind']); **Creating a _null_ segment** $idSites = array(1,2,3); $segment = new Segment('', $idSites); $segment->getSelectQuery will return a query that selects all visits
Afficher le fichier Open project: piwik/piwik Class Usage Examples

Protected Properties

Свойство Type Description
$availableSegments
$idSites array
$segmentExpression Piwik\Segment\SegmentExpression
$string string

Méthodes publiques

Méthode Description
__construct ( string $segmentCondition, array $idSites ) Constructor.
__toString ( ) : string Returns the segment string.
getHash ( ) : string Returns a hash of the segment condition, or the empty string if the segment condition is empty.
getSelectQuery ( string $select, array $from, false | string $where = false, array | string $bind = [], false | string $orderBy = false, false | string $groupBy = false, integer $limit, integer $offset ) : string Extend an SQL query that aggregates data over one of the 'log_' tables with segment expressions.
getString ( ) : string Returns the segment condition.
isEmpty ( ) Returns true if the segment is empty, false if otherwise.
willBeArchived ( ) : boolean Detects whether the Piwik instance is configured to be able to archive this segment. It checks whether the segment will be either archived via browser or cli archiving. It does not check if the segment has been archived. If you want to know whether the segment has been archived, the actual report data needs to be requested.

Méthodes protégées

Méthode Description
getCleanedExpression ( $expression )
initializeSegment ( $string, $idSites )

Private Methods

Méthode Description
getAvailableSegments ( )
getExpressionsWithUnionsResolved ( $expressions )
getSegmentByName ( $name )

Method Details

__construct() public méthode

Constructor.
public __construct ( string $segmentCondition, array $idSites )
$segmentCondition string The segment condition, eg, `'browserCode=ff;countryCode=CA'`.
$idSites array The list of sites the segment will be used with. Some segments are dependent on the site, such as goal segments.

__toString() public méthode

Returns the segment string.
public __toString ( ) : string
Résultat string

getCleanedExpression() protected méthode

protected getCleanedExpression ( $expression )

getHash() public méthode

Returns a hash of the segment condition, or the empty string if the segment condition is empty.
public getHash ( ) : string
Résultat string

getSelectQuery() public méthode

Extend an SQL query that aggregates data over one of the 'log_' tables with segment expressions.
public getSelectQuery ( string $select, array $from, false | string $where = false, array | string $bind = [], false | string $orderBy = false, false | string $groupBy = false, integer $limit, integer $offset ) : string
$select string The select clause. Should NOT include the **SELECT** just the columns, eg, `'t1.col1 as col1, t2.col2 as col2'`.
$from array Array of table names (without prefix), eg, `array('log_visit', 'log_conversion')`.
$where false | string (optional) Where clause, eg, `'t1.col1 = ? AND t2.col2 = ?'`.
$bind array | string (optional) Bind parameters, eg, `array($col1Value, $col2Value)`.
$orderBy false | string (optional) Order by clause, eg, `"t1.col1 ASC"`.
$groupBy false | string (optional) Group by clause, eg, `"t2.col2"`.
$limit integer Limit number of result to $limit
$offset integer Specified the offset of the first row to return
Résultat string The entire select query.

getString() public méthode

Returns the segment condition.
public getString ( ) : string
Résultat string

initializeSegment() protected méthode

protected initializeSegment ( $string, $idSites )
$string
$idSites

isEmpty() public méthode

Returns true if the segment is empty, false if otherwise.
public isEmpty ( )

willBeArchived() public méthode

This method does not take any date/period into consideration. Meaning a Piwik instance might be able to archive this segment in general, but not for a certain period if eg the archiving of range dates is disabled.
public willBeArchived ( ) : boolean
Résultat boolean

Property Details

$availableSegments protected_oe property

protected $availableSegments

$idSites protected_oe property

protected array $idSites
Résultat array

$segmentExpression protected_oe property

protected SegmentExpression,Piwik\Segment $segmentExpression
Résultat Piwik\Segment\SegmentExpression

$string protected_oe property

protected string $string
Résultat string