PHP 클래스 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
파일 보기
프로젝트 열기: piwik/piwik
1 사용 예제들
보호된 프로퍼티들
공개 메소드들
메소드 |
설명 |
|
__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. |
|
보호된 메소드들
비공개 메소드들
메소드 상세
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. |
Returns the segment string.
getCleanedExpression()
보호된 메소드
Returns a hash of the segment condition, or the empty string if the segment
condition is empty.
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 |
리턴 |
string |
The entire select query. |
Returns the segment condition.
initializeSegment()
보호된 메소드
Returns true if the segment is empty, false if otherwise.
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.
프로퍼티 상세
$availableSegments 보호되어 있는 프로퍼티
protected $availableSegments |
protected array $idSites |
리턴 |
array |
|
$segmentExpression 보호되어 있는 프로퍼티
protected SegmentExpression,Piwik\Segment $segmentExpression |
리턴 |
Piwik\Segment\SegmentExpression |
|
protected string $string |
리턴 |
string |
|