本文整理汇总了PHP中PageList::sortby方法的典型用法代码示例。如果您正苦于以下问题:PHP PageList::sortby方法的具体用法?PHP PageList::sortby怎么用?PHP PageList::sortby使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PageList
的用法示例。
在下文中一共展示了PageList::sortby方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: heading
function heading()
{
global $request;
$nbsp = HTML::raw(' ');
// allow sorting?
if (1) {
// multiple comma-delimited sortby args: "+hits,+pagename"
// asc or desc: +pagename, -pagename
$sortby = PageList::sortby($this->_field, 'flip_order');
//Fixme: pass all also other GET args along. (limit, p[])
//TODO: support GET and POST
$s = HTML::a(array('href' => $request->GetURLtoSelf(array('sortby' => $sortby)), 'class' => 'pagetitle', 'title' => sprintf(_("Sort by %s"), $this->_field)), $nbsp, HTML::u($this->_heading), $nbsp);
} else {
$s = HTML($nbsp, HTML::u($this->_heading), $nbsp);
}
return HTML::th(array('align' => 'center'), $s);
}
示例2: _doSort
function _doSort(&$array, $sortby)
{
$sortby = PageList::sortby($sortby, 'init');
if ($sortby == '+pagename') {
sort($array, SORT_STRING);
} elseif ($sortby == '-pagename') {
rsort($array, SORT_STRING);
}
reset($array);
}
示例3: run
function run($dbi, $argstr, &$request, $basepage)
{
global $DBParams;
//$request->setArg('nocache','1');
extract($this->getArgs($argstr, $request));
if (!$alias) {
return $this->error(_("No DSN alias for SqlResult.ini specified"));
}
$sql = $this->_sql;
// apply custom filters
if ($where and strstr($sql, "%%where%%")) {
$sql = str_replace("%%where%%", $where, $sql);
}
// TODO: use a SQL construction library?
if ($limit) {
$pagelist = new PageList();
$limit = $pagelist->limit($limit);
if (strstr($sql, "%%limit%%")) {
$sql = str_replace("%%limit%%", $limit, $sql);
} else {
if (strstr($sql, "LIMIT")) {
$sql = preg_replace("/LIMIT\\s+[\\d,]+\\s+/m", "LIMIT " . $limit . " ", $sql);
}
}
}
if (strstr($sql, "%%sortby%%")) {
if (!$sortby) {
$sql = preg_replace("/ORDER BY .*%%sortby%%\\s/m", "", $sql);
} else {
$sql = str_replace("%%sortby%%", $sortby, $sql);
}
} elseif (PageList::sortby($sortby, 'db')) {
// add sorting: support paging sortby links
if (preg_match("/\\sORDER\\s/", $sql)) {
$sql = preg_replace("/ORDER BY\\s\\S+\\s/m", "ORDER BY " . PageList::sortby($sortby, 'db'), $sql);
} else {
$sql .= " ORDER BY " . PageList::sortby($sortby, 'db');
}
}
$inidsn = $this->getDsn($alias);
if (!$inidsn) {
return $this->error(sprintf(_("No DSN for alias %s in SqlResult.ini found"), $alias));
}
// adodb or pear? adodb as default, since we distribute per default it.
// for pear there may be overrides.
// TODO: native PDO support (for now we use ADODB)
if ($DBParams['dbtype'] == 'SQL') {
$dbh = DB::connect($inidsn);
$all = $dbh->getAll($sql);
if (DB::isError($all)) {
return $this->error($all->getMessage() . ' ' . $all->userinfo);
}
} else {
// unless PearDB use the included ADODB, regardless if dba, file or PDO, ...
if ($DBParams['dbtype'] != 'ADODB') {
// require_once('lib/WikiDB/adodb/adodb-errorhandler.inc.php');
require_once 'lib/WikiDB/adodb/adodb.inc.php';
}
$parsed = parseDSN($inidsn);
$dbh =& ADONewConnection($parsed['phptype']);
$conn = $dbh->Connect($parsed['hostspec'], $parsed['username'], $parsed['password'], $parsed['database']);
if (!$conn) {
return $this->error($dbh->errorMsg());
}
$GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_ASSOC;
$dbh->SetFetchMode(ADODB_FETCH_ASSOC);
$all = $dbh->getAll($sql);
$GLOBALS['ADODB_FETCH_MODE'] = ADODB_FETCH_NUM;
$dbh->SetFetchMode(ADODB_FETCH_NUM);
if (!$all) {
return $this->error($dbh->errorMsg());
}
}
$args = array();
if ($limit) {
// fill paging vars (see PageList)
$args = $pagelist->pagingTokens(count($all), count($all[0]), $limit);
if (!$args) {
$args = array();
}
}
if ($template) {
$args = array_merge(array('SqlResult' => $all, 'ordered' => $ordered, 'where' => $where, 'sortby' => $sortby, 'limit' => $limit), $args);
// paging params override given params
return Template($template, $args);
} else {
if ($ordered) {
$html = HTML::ol(array('class' => 'sqlresult'));
if ($all) {
foreach ($all as $row) {
$html->pushContent(HTML::li(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow'), $row[0]));
}
}
} else {
$html = HTML::table(array('class' => 'sqlresult'));
$i = 0;
if ($all) {
foreach ($all as $row) {
$tr = HTML::tr(array('class' => $i++ % 2 ? 'evenrow' : 'oddrow'));
if ($row) {
//.........这里部分代码省略.........