You are here

public function MongodbXHProfRuns::getRuns in XHProf 6

Same name and namespace in other branches
  1. 8 modules/xhprof_mongodb/MongodbXHProfRuns.inc \MongodbXHProfRuns::getRuns()
  2. 7 modules/xhprof_mongodb/MongodbXHProfRuns.inc \MongodbXHProfRuns::getRuns()

This function gets runs based on passed parameters, column data as key, value as the value. Values are escaped automatically. You may also pass limit, order by, group by, or "where" to add those values, all of which are used as is, no escaping.

Parameters

array $stats Criteria by which to select columns:

Return value

resource

File

modules/xhprof_mongodb/MongodbXHProfRuns.inc, line 39
Definition of MongodbXHProfRuns.

Class

MongodbXHProfRuns
Defines a MongoDB storage backend for XHProf.

Code

public function getRuns($stats, $limit = 50, $skip = 0) {
  $collection = mongodb_collection('xhprof');
  $sort = isset($_GET['order']) ? $_GET['order'] : 'date';
  $sort_direction_str = isset($_GET['sort']) ? $_GET['sort'] : 'desc';
  $sort_direction = array(
    'asc' => 1,
    'desc' => -1,
  );
  $cursor = $collection
    ->find(array())
    ->limit($limit)
    ->skip($skip)
    ->sort(array(
    strtolower($sort) => $sort_direction[$sort_direction_str],
  ));
  $runs = array();
  foreach ($cursor as $id => $run) {
    $run['run_id'] = $id;
    $runs[] = $run;
  }
  return $runs;
}