本文整理汇总了PHP中tag::fetch方法的典型用法代码示例。如果您正苦于以下问题:PHP tag::fetch方法的具体用法?PHP tag::fetch怎么用?PHP tag::fetch使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tag
的用法示例。
在下文中一共展示了tag::fetch方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_latest_toptics
public function get_latest_toptics($offset, $limit, $tag_name = NULL)
{
if ($tag_name) {
}
$ds = new self();
$qb = new \ActiveRecord\SQLBuilder($ds->connection(), $ds->table_name());
$qb->select("disqusid, title, tag_id")->where("parentid IS NULL")->offset($offset)->limit($limit);
if ($tag_name) {
$tag = tag::fetch($tag_name);
if (!$tag) {
return array();
}
$qb->where("parentid IS NULL AND tag_id = ?", $tag->tag_id);
}
// fetch roots
$roots = $ds->find_by_sql($qb->to_s(), $qb->bind_values());
// fetch latest reply
$qb->select("disqusid, title, context, username, tag_id, disquses.updated_at")->joins("INNER JOIN disquses ON disquses.disqusid = disquses.parentid")->joins("INNER JOIN users ON users.userid= disquses.created_by")->limit(1)->order("disquses.created_at desc");
$latest_topics = array();
foreach ($roots as $root) {
$qb->where("parentid = ?", $root->disqusid);
$query = $ds->find_by_sql($qb->to_s(), $qb->bind_values());
// if no sub-topic?
if (!count($query)) {
// consider the root topic!
$qb->where("disqusid = ?", $root->disqusid);
$query = $ds->find_by_sql($qb->to_s(), $qb->bind_values());
}
$topic = array_shift($query);
$topic->readonly();
$topic->title = $root->title;
$topic->tag_id = @$root->tag_id;
$topic->disqusid = $root->disqusid;
$latest_topics[] = $topic;
}
// sort by updated_at desc
usort($latest_topics, function ($a, $b) {
if ($a->updated_at == $b->updated_at) {
return 0;
}
if ($a->updated_at < $b->updated_at) {
return 1;
}
return -1;
});
return $latest_topics;
}