<?php
$isLimit = !empty($scriptProperties['limit']);
$start = $modx->getOption('start',$scriptProperties,0);
$limit = $modx->getOption('limit',$scriptProperties,10);
$sort = $modx->getOption('sort',$scriptProperties,'name');
$dir = $modx->getOption('dir',$scriptProperties,'ASC');
$query = $modx->getOption('query',$scriptProperties,'');
 
/* build query */
$c = $modx->newQuery('params');
if (!empty($query)) {
    $c->where(array(
        'name:LIKE' => '%'.$query.'%',
        'OR:values:LIKE' => '%'.$query.'%',
    ));
}
$count = $modx->getCount('params',$c);
$c->sortby($sort,$dir);
if ($isLimit) $c->limit($limit,$start);
$params = $modx->getIterator('params', $c);
 
/* iterate */
$list = array();
foreach ($params as $param) {
    $paramArray = $param->toArray();
    $list[]= $paramArray;
}
return $this->outputArray($list,$count);