Piwik\Segment::getSelectQuery PHP Méthode

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.
    public function getSelectQuery($select, $from, $where = false, $bind = array(), $orderBy = false, $groupBy = false, $limit = 0, $offset = 0)
    {
        $segmentExpression = $this->segmentExpression;
        $limitAndOffset = null;
        if ($limit > 0) {
            $limitAndOffset = (int) $offset . ', ' . (int) $limit;
        }
        return $this->segmentQueryBuilder->getSelectQueryString($segmentExpression, $select, $from, $where, $bind, $groupBy, $orderBy, $limitAndOffset);
    }

Usage Example

 /**
  * @dataProvider getTestDataForSegmentSqlTest
  */
 public function test_SegmentSql_IsCorrectlyDecoratedWithIdSegment($segment, $triggerValue, $expectedPrefix)
 {
     if (!empty($triggerValue)) {
         $_GET['trigger'] = $triggerValue;
     }
     $segment = new Segment($segment, array());
     $query = $segment->getSelectQuery('*', 'log_visit');
     $sql = $query['sql'];
     if (empty($expectedPrefix)) {
         $this->assertStringStartsNotWith("/* idSegments", $sql);
     } else {
         $this->assertStringStartsWith($expectedPrefix, $sql);
     }
 }
All Usage Examples Of Piwik\Segment::getSelectQuery