<?php /** * RightModel.class.php * $author$ */ namespace Common\Model; class RightModel extends AbstractModel { // 全部人可见 const IS_ALL = 1; // 部分人可见 const NOT_IS_ALL = 0; /** * 构造方法 */ public function __construct() { parent::__construct(); } /** * 根据用户ID、部门ID、角色ID、岗位ID获取有这些权限的调研ID * * @param string $memID 用户ID * @param array $depIDs 部门ID数组 * @param array $roleIDs 角色ID数组 * @param array $jobIDs 岗位ID数组 * @param array $tagIDs 标签ID数组 * @return array 返回有权限的调研ID数组 */ public function get_list_id($memID, $depIDs = array(), $roleIDs = array(), $jobIDs = array(), $tagIDs = array()) { list($where, $params) = $this->_get_list_id_where($memID, $depIDs, $roleIDs, $jobIDs, $tagIDs); $where = ' WHERE `domain`=? AND status<? ' . $where; array_unshift($params, self::ST_DELETE); array_unshift($params, QY_DOMAIN); $sql = 'SELECT * FROM __TABLE__' . $where; $right_list = $this->_m->fetch_array($sql, $params); $ids = array_column($right_list, 'qu_id'); return array_unique($ids); } /** * 根据用户ID、部门ID、角色ID、岗位ID获取有这些权限的调研ID的sql语句where子句 * * @param string $memID 用户ID * @param array $depIDs 部门ID数组 * @param array $roleIDs 角色ID数组 * @param array $jobIDs 岗位ID数组 * @param array $tagIDs 标签ID数组 * * @return string */ protected function _get_list_id_where($memID, $depIDs, $roleIDs, $jobIDs, $tagIDs) { $where = ' `uid`=?'; $params = [$memID]; if (!empty($depIDs)) { $where .= ' OR `dp_id` IN (?)'; $params[] = $depIDs; } if (!empty($roleIDs)) { $where .= ' OR `role_id` IN (?)'; $params[] = $roleIDs; } if (!empty($jobIDs)) { $where .= ' OR `job_id` IN (?)'; $params[] = $jobIDs; } if (!empty($tagIDs)) { $where .= ' OR `tag_id` IN (?)'; $params[] = $tagIDs; } return [ ' AND (' . $where . ')', $params ]; } }