/** * 判断当前用户是否包含某个角色 * @author wjh 2014-9-13 * @param string $roleKey 关键字,如 agent_ ,provider_ ,provider_manager * @return bool 是否包含 */ public static function checkCurrentUserRole($roleKey, $userid = null) { if (empty($userid)) { $userid = BDataHelper::getCurrentUserid(); } $roles = Assignments::model()->findAllByAttributes(array('userid' => $userid)); $data = BArrayHelper::array_func($roles, function ($k, $v, $userdate = null) { return array($v->itemname); }, function ($k, $v, $userdata = null) use($roleKey) { $rolename = $v->itemname; return substr($rolename, 0, strlen($roleKey)) == $roleKey; }); return count($data); }
/** * 获取类型定义中的 index 或 key * @author wjh 2014-6-3 * @param array $arr * @param string $text index or key * @return string */ public static function getKey($arr, $text) { $result = BArrayHelper::array_func($arr, function ($k, $v, $userdata) use($text) { return $k; }, function ($k, $v, $userdata) use($text) { return trim($v) == trim($text); }); return is_null($result) ? '' : implode(',', $result); }