<?php
/**
* @CopyRight (C)2000-2012 XiangYun Development team Inc.
* @WebSite www.cn86.cn
* @Author XiangYun
* @Brief XYCMS v1.0
* @Update 2011.09.23
* @Id 新闻资讯
**/
if (! defined('IN_PHPOE')) {
exit('Access Denied');
}
class CategoryService
{
private static $obj = NULL;
private static $urlpath = NULL;
private static $city_one = '';
private static $fnames = NULL;
/**
* 调取分类
*
* @param string $table
* @param int $parentId
* @param string $orderby
* @return mixed
*/
public function lists($table = 'product', $parentId = 0, $orderby = 'asc')
{
static $data = null;
if (isset($data[$table][$parentId])) {
return $data[$table][$parentId];
}
self::$obj = $GLOBALS['db'];
self::$urlpath = defined('M_PATH_URL') ? M_PATH_URL : PATH_URL;
self::$city_one = $GLOBALS['city_one'] ?? [];
self::$fnames = $GLOBALS['fnames'] ?? null;
$model = $table == 'info' ? 'news' : $table;
$nodes = $this->getAllCateGories($table, $orderby);
foreach ($nodes as $key => $value) {
$nodes[$key]['target'] = intval($value['target']) == 2 ? '_blank' : '';
if($table == 'product' || $table == 'news'){
$nodes[$key]['cname'] = Core_Fun::quChong($nodes[$key]['cname']);
}
$nodes[$key]['img'] = $value['img'] ?: PATH_URL."admin/assets/images/nopic.jpg";
$cityPre = '';
if(empty(self::$fnames)){
if (!empty(self::$city_one) && $table == 'product') {
$cityPre = self::$city_one['en'].'_';
}elseif(!empty(self::$city_one) && $table == 'news'){
$cityPre = self::$city_one['en'].'_';
}
}
if ($table == 'download' || $table == 'job') {
$nodes[$key]['url'] = $value['linkurl'] ?: frontendUrl(self::$urlpath.$model, ($value['slug'] ?:$value['cid']).'/');
} else {
$nodes[$key]['url'] = $value['linkurl'] ?: frontendUrl(self::$urlpath.$model, $cityPre.($value['slug'] ?:$value['cid']).'/');
}
// 新闻分类数量
if ($table == 'news') {
$nodes[$key]['count'] = $this->getcount($value['cid']);
}
}
$data[$table][$parentId] = (new PHPTree)->getTree($nodes, $parentId);
return $data[$table][$parentId];
}
// 获取数量
public static function getcount($cid)
{
self::$obj = $GLOBALS['db'];
$searchsql = " WHERE v.flag=1";
if(intval($cid)>0)
{
$childs_sql = (new Core_Mod)->build_childsql("newscate","v",intval($cid),"");
if(Core_Fun::ischar($childs_sql)) {
$searchsql .= " AND (v.cid='".intval($cid)."'".$childs_sql.")";
} else {
$searchsql .= " AND v.cid='".intval($cid)."'";
}
}
$sql = "SELECT * FROM " . DB_PREFIX. "news as v".$searchsql." ORDER BY orders";
return count(self::$obj->getall($sql));
}
/**
* 调取概况分类
*
* @param string $orderby
* @return
*/
public function page($orderby = 'asc')
{
self::$obj = $GLOBALS['db'];
self::$urlpath = defined('M_PATH_URL') ? M_PATH_URL : PATH_URL;
$sql = "SELECT * FROM ".DB_PREFIX."pagecate WHERE parentid = 0 AND flag = 1 ORDER BY orders ".$orderby;
$result = self::$obj->getall($sql);
if (!empty($result)) {
foreach ($result as $key => $value) {
$result[$key]['url'] = $value['linkurl'] ?: self::$urlpath."about_".$value['catdir'];
if (isset($value['target']) && $value['target'] == 2) {
$result[$key]['target'] = "_blank";
}
$sql = "SELECT * FROM ".DB_PREFIX."page WHERE flag = 1 AND cid = ".$value['cid']." ORDER BY orders ".$orderby;
$child = self::$obj->getall($sql);
if (!empty($child)) {
foreach ($child as $k => $v) {
$child[$k]['url'] = $v['linkurl'] ?: self::$urlpath."about_".$v['catdir'];
if(isset($v['target']) && $v['target'] == 2){
$child[$k]['target'] = "_blank";
}
}
}
$result[$key]['child'] = $child;
}
}
return $result;
}
/**
* @param string $table
* @param string $orderBy
* @return array
*/
public function getAllCateGories($table = 'product', $orderBy = 'asc')
{
self::$obj = $GLOBALS['db'];
$sql = "SELECT * FROM " . DB_PREFIX. "{$table}cate WHERE flag=1 ORDER BY orders {$orderBy}";
return self::$obj->getall($sql);
}
}上一篇:ajax 模板
下一篇:已经是最后一篇