mirror of
https://git.beihong.wang/wangbeihong/blog-source.git
synced 2026-04-23 20:13:04 +08:00
initial
This commit is contained in:
38
var/Widget/Metas/Category/Related.php
Executable file
38
var/Widget/Metas/Category/Related.php
Executable file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Widget\Metas\Category;
|
||||
|
||||
use Typecho\Db\Exception;
|
||||
use Widget\Base\Metas;
|
||||
use Widget\Base\TreeTrait;
|
||||
|
||||
if (!defined('__TYPECHO_ROOT_DIR__')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Related extends Metas
|
||||
{
|
||||
use InitTreeRowsTrait;
|
||||
use TreeTrait;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$ids = array_column($this->db->fetchAll($this->select('table.metas.mid')
|
||||
->join('table.relationships', 'table.relationships.mid = table.metas.mid')
|
||||
->where('table.relationships.cid = ?', $this->parameter->cid)
|
||||
->where('table.metas.type = ?', 'category')), 'mid');
|
||||
|
||||
usort($ids, function ($a, $b) {
|
||||
$orderA = array_search($a, $this->orders);
|
||||
$orderB = array_search($b, $this->orders);
|
||||
|
||||
return $orderA <=> $orderB;
|
||||
});
|
||||
|
||||
$this->pushAll($this->getRows($ids));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user