本文整理汇总了PHP中SelectQuery::setGroup方法的典型用法代码示例。如果您正苦于以下问题:PHP SelectQuery::setGroup方法的具体用法?PHP SelectQuery::setGroup怎么用?PHP SelectQuery::setGroup使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SelectQuery
的用法示例。
在下文中一共展示了SelectQuery::setGroup方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_filter
public function action_filter($pageId = 1)
{
$query = new SelectQuery('BackendRequest');
$query->setFields(array('user_id', 'ip', 'user_agent', 'mode', 'request', 'query', 'COUNT(id) AS `occured`', 'MAX(`added`) AS `last_occured`'));
$query->setGroup(array('user_id', 'ip', 'user_agent', 'mode', 'request', 'query'));
$params = $queryFilter = array();
$parameters = Controller::getVar('params');
$sort = Controller::getVar('sort');
if (!empty($parameters['userId'])) {
$queryFilter[] = 'user_id = :userId';
$params[':userId'] = $parameters['userId'];
}
if (!empty($parameters['query'])) {
$queryFilter[] = "query LIKE('%{$parameters['query']}%')";
}
if (!empty($parameters['ip'])) {
$queryFilter[] = "ip LIKE('%{$parameters['ip']}%')";
}
if (!empty($parameters['user_agent'])) {
$queryFilter[] = "user_agent LIKE('%{$parameters['user_agent']}%')";
}
$query->filter($queryFilter);
$count = 10;
if (!empty($sort['field'])) {
$query->setOrder(array($sort['field'] . ' ' . $sort['order']));
}
if ($pageId == 1) {
$start = 0;
} elseif ($pageId == 0) {
$start = false;
$count = false;
} else {
$start = floor(($pageId - 1) * $count);
}
$pager = array();
if ($start === 'all') {
$limit = 'all';
} else {
if ($start || $count) {
$limit = "{$start}, {$count}";
} else {
$limit = false;
}
}
$query->limit($limit);
$items = $query->fetchAll($params);
$totalItems = $query->getCount($params);
$pager = '';
if ($start || $count) {
$pager = array('currentPage' => $pageId, 'itemCount' => count($items), 'itemTotal' => $totalItems, 'totalPages' => round(($totalItems - 1) / $count, 0));
}
$retArray['pager'] = $pager;
$retArray['data'] = $items;
$retArray['params'] = $parameters;
$retArray['sort'] = $sort;
return $retArray;
}