Skip to content

Instantly share code, notes, and snippets.

@atsu666
Created May 20, 2020 03:49
Show Gist options
  • Save atsu666/c56b58108d69290df25970784a431aa1 to your computer and use it in GitHub Desktop.
Save atsu666/c56b58108d69290df25970784a431aa1 to your computer and use it in GitHub Desktop.
php/ACMS/GET/Tag/Assist.php
<?php
class ACMS_GET_Tag_Assist extends ACMS_GET
{
function get()
{
$Tpl = new Template($this->tpl, new ACMS_Corrector());
$SQL = SQL::newSelect('tag');
$SQL->addSelect('tag_name');
$SQL->addSelect('tag_name', 'tag_amount', null, 'count');
$SQL->addWhereOpr('tag_blog_id', $this->bid);
$SQL->addGroup('tag_name');
$SQL->setLimit(config('tag_assist_limit'));
ACMS_Filter::tagOrder($SQL, config('tag_assist_order'));
if (1 < ($tagThreshold = idval(config('tag_assist_threshold')))) {
$SQL->addHaving('tag_amount >= ' . $tagThreshold);
}
$q = $SQL->get(dsn());
$DB = DB::singleton(dsn());
if (!$DB->query($q, 'fetch')) {
return $Tpl->get();
}
if (!$row = $DB->fetch($q)) {
return $Tpl->get();
}
$firstLoop = true;
do {
if (!$firstLoop) {
$Tpl->add(array('tag:glue', 'tag:loop'));
}
$firstLoop = false;
$Tpl->add('tag:loop', array(
'name' => $row['tag_name'],
'amount' => $row['tag_amount'],
));
} while ($row = $DB->fetch($q));
return $Tpl->get();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment