/** * 根据角色获取默认头像 * @param $role_id * @param $size * @return mixed|string * @author 郑钟良<*****@*****.**> */ private function getImageUrlByRoleId($role_id, $size) { $avatar_id = S('Role_Avatar_Id_' . $role_id); if (!$avatar_id) { $map = getRoleConfigMap('avatar', $role_id); $avatar_id = M('RoleConfig')->where($map)->field('value')->find(); S('Role_Avatar_Id_' . $role_id, $avatar_id, 600); } if ($avatar_id) { if ($size != 0) { $path = getThumbImageById($avatar_id['value'], $size, $size); } else { $path = getThumbImageById($avatar_id['value']); } } else { //角色没有默认 if ($size != 0) { $default_avatar = "Public/images/default_avatar.jpg"; $path = $this->getImageUrlByPath($default_avatar, $size, false); } else { $path = get_pic_src("Public/images/default_avatar.jpg"); } } return $path; }
private function getRoleFieldIds($uid = null) { $role_id = get_role_id($uid); $fields_list = S('Role_Expend_Info_' . $role_id); if (!$fields_list) { $map_role_config = getRoleConfigMap('expend_field', $role_id); $fields_list = D('RoleConfig')->where($map_role_config)->getField('value'); if ($fields_list) { $fields_list = explode(',', $fields_list); S('Role_Expend_Info_' . $role_id, $fields_list, 600); } } return $fields_list; }
/** * 重新设置拥有字段的身份 * @param $role_ids 身份ids * @param $add_id 新增字段时字段id * @param $edit_id 编辑字段时字段id * @return bool * @author 郑钟良<*****@*****.**> */ private function _setFieldRole($role_ids, $add_id, $edit_id) { $type = 'expend_field'; $roleConfigModel = D('RoleConfig'); $map = getRoleConfigMap($type, 0); if ($edit_id) { //编辑字段 unset($map['role_id']); $map['value'] = array('like', array('%,' . $edit_id . ',%', $edit_id . ',%', '%,' . $edit_id, $edit_id), 'or'); $already_role_id = $roleConfigModel->where($map)->select(); $already_role_id = array_column($already_role_id, 'role_id'); unset($map['value']); if (count($role_ids) && count($already_role_id)) { $need_add_role_ids = array_diff($role_ids, $already_role_id); $need_del_role_ids = array_diff($already_role_id, $role_ids); } else { if (count($role_ids)) { $need_add_role_ids = $role_ids; } else { $need_del_role_ids = $already_role_id; } } foreach ($need_add_role_ids as $val) { $map['role_id'] = $val; $oldConfig = $roleConfigModel->where($map)->find(); if (count($oldConfig)) { $oldConfig['value'] = implode(',', array_merge(explode(',', $oldConfig['value']), array($edit_id))); $roleConfigModel->saveData($map, $oldConfig); } else { $data = $map; $data['value'] = $edit_id; $roleConfigModel->addData($data); } } foreach ($need_del_role_ids as $val) { $map['role_id'] = $val; $oldConfig = $roleConfigModel->where($map)->find(); $oldConfig['value'] = array_diff(explode(',', $oldConfig['value']), array($edit_id)); if (count($oldConfig['value'])) { $oldConfig['value'] = implode(',', $oldConfig['value']); $roleConfigModel->saveData($map, $oldConfig); } else { $roleConfigModel->deleteData($map); } } } else { //新增字段 foreach ($role_ids as $val) { $map['role_id'] = $val; $oldConfig = $roleConfigModel->where($map)->find(); if (count($oldConfig)) { $oldConfig['value'] = implode(',', array_unique(array_merge(explode(',', $oldConfig['value']), array($add_id)))); $roleConfigModel->saveData($map, $oldConfig); } else { $data = $map; $data['value'] = $add_id; $roleConfigModel->addData($data); } } } return true; }
private function setMap() { $aTag = I('tag', 0, 'intval'); $aRole = I('role', 0, 'intval'); $role_list = modC('SHOW_ROLE_TAB', '', 'People'); if ($role_list != '') { $role_list = json_decode($role_list, true); $role_list = $role_list[1]['items']; if (count($role_list)) { foreach ($role_list as &$val) { $val['id'] = $val['data-id']; } unset($val); $this->assign('role_list', $role_list); } else { $aRole = 0; } } else { $aRole = 0; } $map = array(); if ($aTag && $aRole) { //同时选择标签和身份 !isset($_GET['tag']) && ($_GET['tag'] = $_POST['tag']); $map_uids['tags'] = array('like', '%[' . $aTag . ']%'); $tag_links = M('Ucenter/UserTagLink')->getListByMap($map_uids); $tag_uids = array_column($tag_links, 'uid'); $this->assign('tag_id', $aTag); !isset($_GET['role']) && ($_GET['role'] = $_POST['role']); $map_role['role_id'] = $aRole; $map_role['status'] = 1; $role_links = D('UserRole')->where($map_role)->limit(999)->field('uid')->select(); $role_uids = array_column($role_links, 'uid'); $this->assign('role_id', $aRole); if ($tag_uids && $role_uids) { $uids = array_intersect($tag_uids, $role_uids); } else { $uids = array(); } $map['uid'] = array('in', $uids); } else { if ($aTag) { //选择标签,没选择身份 !isset($_GET['tag']) && ($_GET['tag'] = $_POST['tag']); $map_uids['tags'] = array('like', '%[' . $aTag . ']%'); $tag_links = M('Ucenter/UserTagLink')->getListByMap($map_uids); $tag_uids = array_column($tag_links, 'uid'); $map['uid'] = array('in', $tag_uids); $this->assign('tag_id', $aTag); } else { if ($aRole) { //选择身份,没选择标签 !isset($_GET['role']) && ($_GET['role'] = $_POST['role']); $map_role['role_id'] = $aRole; $map_role['status'] = 1; $role_links = D('UserRole')->where($map_role)->limit(999)->field('uid')->select(); $role_uids = array_column($role_links, 'uid'); $map['uid'] = array('in', $role_uids); $this->assign('role_id', $aRole); } } } $userTagModel = M('Ucenter/UserTag'); if ($aRole) { $map_tags = getRoleConfigMap('user_tag', $aRole); $can_config = D('RoleConfig')->where($map_tags)->field('value')->find(); if ($can_config['value'] != '') { $tag_list = $userTagModel->getTreeListByIds($can_config['value']); } else { $tag_list = null; } } else { $tag_list = $userTagModel->getTreeList(); } $this->assign('tag_list', $tag_list); $nickname = I('keywords', '', 'op_t'); if ($nickname != '') { !isset($_GET['keywords']) && ($_GET['keywords'] = $_POST['keywords']); $map['nickname'] = array('like', '%' . $nickname . '%'); $this->assign('nickname', $nickname); } return $map; }
/** * 身份扩展资料配置 及 注册时要填写的资料配置 * @author 郑钟良<*****@*****.**> */ public function configField() { $aRoleId = I('id', 0, 'intval'); if (!$aRoleId) { $this->error(L('_PLEASE_CHOOSE_YOUR_IDENTITY_')); } $aType = I('get.type', 0, 'intval'); //扩展资料设置类型:1注册时要填写资料配置,0扩展资料字段设置 if ($aType) { //注册时要填写资料配置 $type = 'register_expend_field'; } else { //扩展资料字段设置 $type = 'expend_field'; } $map = getRoleConfigMap($type, $aRoleId); if (IS_POST) { $data['value'] = ''; if (isset($_POST['fields'])) { sort($_POST['fields']); $data['value'] = implode(',', array_unique($_POST['fields'])); } if ($this->roleConfigModel->where($map)->find()) { $result = $this->roleConfigModel->saveData($map, $data); } else { $data = array_merge($map, $data); $result = $this->roleConfigModel->addData($data); } if ($result === false) { $this->error(L('_FAILED_') . $this->roleConfigModel->getError()); } else { clear_role_cache($aRoleId); $this->success(L('_OPERATION_SUCCESS_')); } } else { $aType = I('get.type', 0, 'intval'); //扩展资料设置类型:1注册时要填写资料配置,0扩展资料字段设置 $mRole_list = $this->roleModel->field('id,title')->select(); $fields = $this->roleConfigModel->where($map)->getField('value'); if ($aType == 1) { //注册时要填写资料配置 $map_fields = getRoleConfigMap('expend_field', $aRoleId); $expend_fields = $this->roleConfigModel->where($map_fields)->getField('value'); $field_list = $expend_fields ? $this->getExpendField($expend_fields) : array(); $this->meta_title = L('_REGISTRATION_TO_FILL_IN_THE_DATA_CONFIGURATION_'); $tpl = 'fieldregister'; //模板地址 $tab = 'fieldRegister'; } else { //扩展资料字段设置 $field_list = $this->getExpendField(); $this->meta_title = L('_EXTENDED_DATA_FIELD_SETTINGS_'); $tpl = 'field'; //模板地址 $tab = 'field'; } $this->assign('field_list', $field_list); $this->assign('role_list', $mRole_list); $this->assign('this_role', array('id' => $aRoleId, 'fields' => $fields)); $this->assign('tab', $tab); $this->display($tpl); } }
/** * 角色扩展资料配置 及 注册时要填写的资料配置 * @author 郑钟良<*****@*****.**> */ public function configField() { $aRoleId = I('id', 0, 'intval'); if (!$aRoleId) { $this->error('请选择角色!'); } $aType = I('get.type', 0, 'intval'); //扩展资料设置类型:1注册时要填写资料配置,0扩展资料字段设置 if ($aType) { //注册时要填写资料配置 $type = 'register_expend_field'; } else { //扩展资料字段设置 $type = 'expend_field'; } $map = getRoleConfigMap($type, $aRoleId); if (IS_POST) { $data['value'] = ''; if (isset($_POST['fields'])) { sort($_POST['fields']); $data['value'] = implode(',', array_unique($_POST['fields'])); } if ($this->roleConfigModel->where($map)->find()) { $result = $this->roleConfigModel->saveData($map, $data); } else { $data = array_merge($map, $data); $result = $this->roleConfigModel->addData($data); } if ($result === false) { $this->error('操作失败' . $this->roleConfigModel->getError()); } else { clear_role_cache($aRoleId); $this->success('操作成功!'); } } else { $aType = I('get.type', 0, 'intval'); //扩展资料设置类型:1注册时要填写资料配置,0扩展资料字段设置 $mRole_list = $this->roleModel->field('id,title')->select(); $fields = $this->roleConfigModel->where($map)->getField('value'); if ($aType == 1) { //注册时要填写资料配置 $map_fields = getRoleConfigMap('expend_field', $aRoleId); $expend_fields = $this->roleConfigModel->where($map_fields)->getField('value'); $field_list = $expend_fields ? $this->getExpendField($expend_fields) : array(); $this->meta_title = '注册时要填写资料配置'; $tpl = 'fieldregister'; //模板地址 $tab = 'fieldRegister'; } else { //扩展资料字段设置 $field_list = $this->getExpendField(); $this->meta_title = '扩展资料字段设置'; $tpl = 'field'; //模板地址 $tab = 'field'; } $this->assign('field_list', $field_list); $this->assign('role_list', $mRole_list); $this->assign('this_role', array('id' => $aRoleId, 'fields' => $fields)); $this->assign('tab', $tab); $this->display($tpl); } }
private function getRoleFieldIds($uid = null) { $role_id = session('temp_login_role_id') ? session('temp_login_role_id') : get_role_id($uid); $fields_list = S('Role_Register_Expend_Info_' . $role_id); if (!$fields_list) { $map_role_config = getRoleConfigMap('register_expend_field', $role_id); $fields_list = M('RoleConfig')->where($map_role_config)->getField('value'); if ($fields_list) { $fields_list = explode(',', $fields_list); S('Role_Register_Expend_Info_' . $role_id, $fields_list, 600); } } return $fields_list; }