InfoController.class.php
5.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
/**
* Created by PhpStorm.
* User: liyifei2012it
* Date: 17/9/26
* Time: 14:34
*/
namespace Api\Controller\HomePage;
use Common\Common\User;
use Common\Common\HomePage;
class InfoController extends AbstractController
{
/**
* Info
* @author liyifei
* @desc 获取个人主页设置
* @param String uid:true 人员UID
* @return array
array(
'memUsername' => '张三',
'memFace' => 'http://p.qlogo.cn/bizmail/0IUNiaicjyroLPJ2Etmrb4RgQ8JLmbLZWBJSONSCKQjeJXfiapIuic6g2Q/0',
'list' => array(
array(
'field_name' => 'memUsername',
'attr_name' => '姓名',
'attr_value' => '李以飞',
'type' => 1, // 属性类型:1=单行文本;2=多行文本;3=数字;4=日期;5=时间;6=日期时间;7=单选;8=多选;9=地址;10=图片;11=下拉框单选;999=部门(选人组件,前端不可选择)
'option' => []; // 属性选项
),
array(
'field_name' => 'memGender',
'attr_name' => '性别',
'attr_value' => 1,
'type' => 7, // 属性类型:1=单行文本;2=多行文本;3=数字;4=日期;5=时间;6=日期时间;7=单选;8=多选;9=地址;10=图片;11=下拉框单选;999=部门(选人组件,前端不可选择)
'option' => array( // 属性选项
{
"name": "男",
"value": 1
},
{
"name": "女",
"value": 2
}
),
),
array(
'field_name' => 'dpName',
'attr_name' => '组织',
'attr_value' => array(
'一飞冲天',
),
'type' => 1, // 属性类型:1=单行文本;2=多行文本;3=数字;4=日期;5=时间;6=日期时间;7=单选;8=多选;9=地址;10=图片;11=下拉框单选;999=部门(选人组件,前端不可选择)
'option' => []; // 属性选项
),
array(
'field_name' => 'custom1',
'attr_name' => '多选属性',
'attr_value' => array(
'属性1',
'属性2'
),
'type' => 1, // 属性类型:1=单行文本;2=多行文本;3=数字;4=日期;5=时间;6=日期时间;7=单选;8=多选;9=地址;10=图片;11=下拉框单选;999=部门(选人组件,前端不可选择)
'option' => array(); // 属性选项
)
)
)
*/
public function Index()
{
$uid = I('post.uid', '', 'trim');
if (empty($uid)) {
E('_ERR_UID_IS_NULL');
}
// 获取个人主页设置缓存
$homepageServ = &HomePage::instance();
$setting = $homepageServ->getSetting();
// 是否开启个人主页设置
if ($setting['homepage'] == HomePage::CLOSE) {
E('_ERR_HOMEPAGE_CLOSED');
}
// 用户信息(从缓存架构用户信息表中的数据获取用户信息,参数设为true越过缓存)
$commUser = new User();
$userInfo = $commUser->getByUid($uid);
if (empty($userInfo)) {
E('_ERR_HOMEPAGE_GET_USER_FAIL');
}
// 可显示的个人信息
$attrs = $setting['attrs'];
$isSecret = $homepageServ->checkUserInSecret($userInfo);
if ($isSecret) {
$attrs = $setting['secret_attrs'];
}
// 没有可显示的个人信息
if (empty($attrs)) {
E('_ERR_HOMEPAGE_ATTRS_LOSE');
}
// 员工管理中设置可用人员属性
$homepageServ = &HomePage::instance();
$attrList = $homepageServ->getAttrs();
// 可显示的个人信息详情
$list = [];
foreach ($attrs as $fieldName) {
// 跳过员工管理中设置不显示的属性
if (!isset($attrList[$fieldName])) {
continue;
}
$attrValue = $userInfo[$fieldName];
switch ($attrList[$fieldName]['type']) {
// 多选类型属性,反序列化属性值
case 8:
if (!empty($attrValue)) {
$attrValue = array_column(unserialize($attrValue), 'name');
}
break;
// 部门、组织属性,仅取第一个部门名称
case 999:
if (is_array($attrValue) && !empty($attrValue)) {
$attrValue = $userInfo[$fieldName][0]['dpName'];
}
break;
}
$list[] = [
'field_name' => $fieldName,
'attr_value' => $attrValue,
'attr_name' => $attrList[$fieldName]['attr_name'],
'type' => $attrList[$fieldName]['type'],
'option' => $attrList[$fieldName]['option'],
];
}
$this->_result = [
'memUsername' => $userInfo['memUsername'],
'memFace' => $userInfo['memFace'],
'list' => $list,
];
}
}