<?php namespace Phpcmf\Model\Cqx;
class Content extends \Phpcmf\Model
{
private $config;
public function __construct(...$params) {
parent::__construct($params);
$file = WRITEPATH.'config/cqx.php';
if (!is_file($file)) {
$this->config = [
SITE_ID => [
'category' => [],
],
'role' => [],
];
} else {
$this->config = require $file;
}
}
public function get_list_where() {
if ($this->admin['adminid'] == 1) {
return '';
}
$where = [];
$catid = $this->_get_role_catid(APP_DIR);
if ($catid) {
$where[] = 'catid NOT IN('.implode(',', $catid).')';
}
$gid = $this->_get_role_groupid();
if ($gid) {
$where[] = 'uid NOT IN(select uid from '.$this->dbprefix('member_group_index').' where gid in('.implode(',', $gid).'))';
}
return $where ? '('.implode(' AND ', $where).')' : '';
}
private function _get_role_groupid() {
$ids = [];
if (isset($this->config['role'])) {
foreach ($this->config['role'] as $gid => $t) {
if ($t) {
foreach ($t as $rid => $v) {
if (in_array($rid, $this->admin['roleid'])) {
$ids[] = $gid;
}
}
}
}
}
$ids && $ids = array_unique($ids);
return $ids;
}
private function _get_role_catid($mid) {
$module = \Phpcmf\Service::L('cache')->get('module-'.SITE_ID.'-'.$mid);
if ($module['share']) {
$mid = 'share';
}
$ids = [];
if (isset($this->config[SITE_ID]['category'][$mid])) {
foreach ($this->config[SITE_ID]['category'][$mid] as $catid => $t) {
if ($t) {
foreach ($t as $rid => $v) {
if (in_array($rid, $this->admin['roleid'])) {
$ids[] = $catid;
}
}
}
}
}
$ids && $ids = array_unique($ids);
return $ids;
}
public function is_edit($catid, $uid = 0) {
$ids = $this->_get_role_catid(APP_DIR);
if ($ids && in_array($catid, $ids)) {
return 1;
}
if ($uid) {
$user = dr_member_info($uid);
$gid = $this->_get_role_groupid();
if ($user['groupid']) {
foreach ($user['groupid'] as $id => $t) {
if (in_array($id, $gid)) {
return 1;
}
}
}
}
return 0;
}
}