Framework  3.9
PivotQuery Class Reference

Standard Pivot Query, with support for paging. More...

+ Inheritance diagram for PivotQuery:
+ Collaboration diagram for PivotQuery:

Public Member Functions

 __construct ($base, $baseConstraint="")
 Constructs a new AbstractPivotQuery. More...
 
 page ($page, $size)
 Sets the page number and size for constraining the result set by page. More...
 
 execute ()
 
- Public Member Functions inherited from AbstractPivotQuery
 pivot ($pivotClass, $pivotConstraint, $pivotFunction="SUM")
 Adds the pivot to the query. More...
 
 range ($rangeClass, $rangeConstraint)
 Adds the range to the query. More...
 
 field ($field, $alias="", $type=String)
 Adds a fixed field to the output object. More...
 
 pivotField ($format, $value, $alias=null, $expression="SUM", $type=Number)
 Adds a pivot field format to the output object. More...
 
 createPivotItem ()
 Creates an empty PivotItem, configured with fields and field aliases based on the pivot and range. More...
 
 additionalFields ()
 Register additional fields from the base to be included in the PivotItem output. More...
 
- Public Member Functions inherited from AbstractQuery
 constraints ($constraints)
 Sets the constraint clause for the Query. More...
 
 filter ($filter)
 Sets a filter to constrain the fields retrieved when the query is executed. More...
 
 params ($params)
 Sets the bound parameters array. More...
 
 bind ()
 Binds placeholders to parameter values. More...
 

Static Public Member Functions

static create ($base, $baseConstraint="")
 

Public Attributes

 $page
 
 $size
 
- Public Attributes inherited from AbstractPivotQuery
 $baseClass
 
 $baseConstraint
 
 $baseItem
 
 $rangeClass
 
 $rangeConstraint
 
 $pivotClass
 
 $pivotConstraint
 
 $pivotItem
 
 $fields
 
 $fieldAliases
 
 $additionalFields = array()
 
 $groupByFields = array()
 
 $orderBy
 
 $totalField = null
 
- Public Attributes inherited from AbstractQuery
 $class
 
 $constraints
 
 $filter
 
 $params
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractPivotQuery
 generateFieldExpressions ()
 Builds the expressions for the pivot query. More...
 
 generateQuery ()
 Generates SQL for the full pivot query, with grouping. More...
 

Detailed Description

Standard Pivot Query, with support for paging.

Author
andy

Definition at line 307 of file pivot.inc.

Constructor & Destructor Documentation

◆ __construct()

PivotQuery::__construct (   $base,
  $baseConstraint = "" 
)

Constructs a new AbstractPivotQuery.

Parameters
string$baseClass name of the DataItem that will be the base
string$baseConstraintSQL constraint over which the base query will operate.

Reimplemented from AbstractPivotQuery.

Definition at line 312 of file pivot.inc.

313  {
314  parent::__construct($base, $baseConstraint);
315  }

Member Function Documentation

◆ create()

static PivotQuery::create (   $base,
  $baseConstraint = "" 
)
static

Definition at line 331 of file pivot.inc.

332  {
333  return new PivotQuery($base, $baseConstraint);
334  }
Standard Pivot Query, with support for paging.
Definition: pivot.inc:308

◆ execute()

PivotQuery::execute ( )
See also
AbstractQuery::execute()

Reimplemented from AbstractQuery.

Definition at line 339 of file pivot.inc.

340  {
341  $query = $this->generateQuery();
342 
343  trace("$query", 3);
344  trace("Page: $this->page Size: $this->size", 3);
345  $items = array();
346 
347  $size = $this->size;
348 
349  try
350  {
352 
353  $result = $db->prepare($query);
354  $result->execute($this->params);
355 
356  if ($this->page > 0)
357  {
358  $count = ($this->page - 1) * $this->size;
359  while($count--)
360  {
361  $result->fetch();
362  }
363  }
364 
365  while($line = $result->fetch())
366  {
367  $item = $this->createPivotItem();
368  $item->populate($line);
369  $items[] = $item;
370 
371  --$size;
372  if ($size == 0) break;
373  }
374 
375  unset($result);
376  }
377  catch(PDOException $e)
378  {
379  $err = "query() failed - " . $e->getMessage();
380  trace($err, 2);
381  throw new DataItemException($err);
382  }
383 
384  trace(count($items)." items found", 3);
385  return $items;
386  }
generateQuery()
Generates SQL for the full pivot query, with grouping.
Definition: pivot.inc:236
createPivotItem()
Creates an empty PivotItem, configured with fields and field aliases based on the pivot and range.
Definition: pivot.inc:279
params($params)
Sets the bound parameters array.
Definition: query.inc:91
static getConnection()
Retrieves a reference to the global database connection.
page($page, $size)
Sets the page number and size for constraining the result set by page.
Definition: pivot.inc:324
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ page()

PivotQuery::page (   $page,
  $size 
)

Sets the page number and size for constraining the result set by page.

By default results are not paged.

Parameters
$pageinteger the page number
$sizeinteger the number of items per page
Returns
Query reference to the Query object, to allow for call chaining.

Definition at line 324 of file pivot.inc.

325  {
326  $this->page = $page;
327  $this->size = $size;
328  return $this;
329  }

Member Data Documentation

◆ $page

PivotQuery::$page

Definition at line 309 of file pivot.inc.

◆ $size

PivotQuery::$size

Definition at line 310 of file pivot.inc.


The documentation for this class was generated from the following file: