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
Показать файл
Открыть проект
Примеры использования класса
Защищенные свойства (Protected)
Открытые методы
Метод |
Описание |
|
__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. |
|
Защищенные методы
Приватные методы
Описание методов
__construct()
публичный Метод
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()
публичный Метод
Returns the segment string.
getCleanedExpression()
защищенный Метод
getHash()
публичный Метод
Returns a hash of the segment condition, or the empty string if the segment
condition is empty.
getSelectQuery()
публичный Метод
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. |
getString()
публичный Метод
Returns the segment condition.
initializeSegment()
защищенный Метод
isEmpty()
публичный Метод
Returns true if the segment is empty, false if otherwise.
willBeArchived()
публичный Метод
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 |
$idSites защищенное свойство
protected array $idSites |
Результат |
array |
|
$segmentExpression защищенное свойство
protected SegmentExpression,Piwik\Segment $segmentExpression |
Результат |
Piwik\Segment\SegmentExpression |
|
$string защищенное свойство
protected string $string |
Результат |
string |
|