| Línea 125... |
Línea 125... |
| 125 |
* @return \Laminas\View\Model\JsonModel
|
125 |
* @return \Laminas\View\Model\JsonModel
|
| 126 |
*/
|
126 |
*/
|
| 127 |
public function peopleYouMayKnowAction()
|
127 |
public function peopleYouMayKnowAction()
|
| 128 |
{
|
128 |
{
|
| 129 |
$request = $this->getRequest();
|
129 |
$request = $this->getRequest();
|
| 130 |
if ($request->isGet()) {
|
130 |
// if ($request->isGet()) {
|
| 131 |
$currentUserPlugin = $this->plugin('currentUserPlugin');
|
131 |
// $currentUserPlugin = $this->plugin('currentUserPlugin');
|
| 132 |
$currentUser = $currentUserPlugin->getUser();
|
132 |
// $currentUser = $currentUserPlugin->getUser();
|
| 133 |
|
133 |
|
| 134 |
$connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
134 |
// $connectionMapper = ConnectionMapper::getInstance($this->adapter);
|
| 135 |
$first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
|
135 |
// $first_degree_connections_ids = $connectionMapper->fetchAllConnectionsByUserReturnIds($currentUser->id);
|
| 136 |
$first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
|
136 |
// $first_degree_connections_ids = $first_degree_connections_ids ? $first_degree_connections_ids : [0];
|
| 137 |
|
137 |
|
| 138 |
$second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
|
138 |
// $second_degree_connections_ids = $connectionMapper->fetchAllSecondDegreeConnectionsForUserIdReturnIds($currentUser->id);
|
| 139 |
$second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
|
139 |
// $second_degree_connections_ids = $second_degree_connections_ids ? $second_degree_connections_ids : [0];
|
| 140 |
|
140 |
|
| 141 |
/*Usuarios de la empresas donde trabajo o soy dueño */
|
141 |
// /*Usuarios de la empresas donde trabajo o soy dueño */
|
| 142 |
$company_user_ids = [];
|
142 |
// $company_user_ids = [];
|
| 143 |
$companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
143 |
// $companyUserMapper = CompanyUserMapper::getInstance($this->adapter);
|
| 144 |
|
144 |
|
| 145 |
$records = $companyUserMapper->fetchAllByUserId($currentUser->id);
|
145 |
// $records = $companyUserMapper->fetchAllByUserId($currentUser->id);
|
| 146 |
foreach ($records as $record) {
|
146 |
// foreach ($records as $record) {
|
| 147 |
|
147 |
|
| 148 |
if ($record->status != CompanyUser::STATUS_ACCEPTED) {
|
148 |
// if ($record->status != CompanyUser::STATUS_ACCEPTED) {
|
| 149 |
continue;
|
149 |
// continue;
|
| 150 |
}
|
150 |
// }
|
| 151 |
|
151 |
|
| 152 |
$otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
|
152 |
// $otherUsers = $companyUserMapper->fetchAllByCompanyId($record->company_id);
|
| 153 |
foreach ($otherUsers as $otherUser) {
|
153 |
// foreach ($otherUsers as $otherUser) {
|
| 154 |
if ($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
|
154 |
// if ($currentUser->id != $otherUser->user_id && $otherUser->creator == CompanyUser::CREATOR_NO && $otherUser->status == CompanyUser::STATUS_ACCEPTED) {
|
| 155 |
|
155 |
|
| 156 |
if (!in_array($otherUser->user_id, $company_user_ids)) {
|
156 |
// if (!in_array($otherUser->user_id, $company_user_ids)) {
|
| 157 |
array_push($company_user_ids, $otherUser->user_id);
|
157 |
// array_push($company_user_ids, $otherUser->user_id);
|
| 158 |
}
|
158 |
// }
|
| 159 |
}
|
159 |
// }
|
| 160 |
}
|
160 |
// }
|
| 161 |
}
|
161 |
// }
|
| 162 |
$company_user_ids = $company_user_ids ? $company_user_ids : [0];
|
162 |
// $company_user_ids = $company_user_ids ? $company_user_ids : [0];
|
| 163 |
|
163 |
|
| 164 |
/* Usuario de los grupos donde soy dueño o participo */
|
164 |
// /* Usuario de los grupos donde soy dueño o participo */
|
| 165 |
|
165 |
|
| 166 |
$groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
|
166 |
// $groupMemberMapper = GroupMemberMapper::getInstance($this->adapter);
|
| 167 |
|
167 |
|
| 168 |
$group_member_ids = [];
|
168 |
// $group_member_ids = [];
|
| 169 |
|
169 |
|
| 170 |
$records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
|
170 |
// $records = $groupMemberMapper->fetchAllByUserId($currentUser->id);
|
| 171 |
foreach ($records as $record) {
|
171 |
// foreach ($records as $record) {
|
| 172 |
if ($record->status != GroupMember::STATUS_ACCEPTED) {
|
172 |
// if ($record->status != GroupMember::STATUS_ACCEPTED) {
|
| 173 |
continue;
|
173 |
// continue;
|
| 174 |
}
|
174 |
// }
|
| 175 |
|
175 |
|
| 176 |
$otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
|
176 |
// $otherUsers = $groupMemberMapper->fetchAllByGroupId($record->group_id);
|
| 177 |
foreach ($otherUsers as $otherUser) {
|
177 |
// foreach ($otherUsers as $otherUser) {
|
| 178 |
if ($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
|
178 |
// if ($currentUser->id != $otherUser->user_id && $otherUser->status == GroupMember::STATUS_ACCEPTED) {
|
| 179 |
|
179 |
|
| 180 |
if (!in_array($otherUser->user_id, $group_member_ids)) {
|
180 |
// if (!in_array($otherUser->user_id, $group_member_ids)) {
|
| 181 |
array_push($group_member_ids, $otherUser->user_id);
|
181 |
// array_push($group_member_ids, $otherUser->user_id);
|
| 182 |
}
|
182 |
// }
|
| 183 |
}
|
183 |
// }
|
| 184 |
}
|
184 |
// }
|
| 185 |
}
|
185 |
// }
|
| 186 |
|
186 |
|
| 187 |
$group_member_ids = $group_member_ids ? $group_member_ids : [0];
|
187 |
// $group_member_ids = $group_member_ids ? $group_member_ids : [0];
|
| 188 |
|
188 |
|
| 189 |
|
189 |
|
| 190 |
|
190 |
|
| 191 |
/* Usuarios con que comparto capsulas */
|
191 |
// /* Usuarios con que comparto capsulas */
|
| 192 |
$capsule_user_ids = [];
|
192 |
// $capsule_user_ids = [];
|
| 193 |
$capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
|
193 |
// $capsuleUserMapper = CompanyMicrolearningCapsuleUserMapper::getInstance($this->adapter);
|
| 194 |
|
194 |
|
| 195 |
$company_ids = [];
|
195 |
// $company_ids = [];
|
| 196 |
$records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
|
196 |
// $records = $capsuleUserMapper->fetchAllActiveByUserId($currentUser->id);
|
| 197 |
foreach ($records as $record) {
|
197 |
// foreach ($records as $record) {
|
| 198 |
if (!in_array($record->company_id, $company_ids)) {
|
198 |
// if (!in_array($record->company_id, $company_ids)) {
|
| 199 |
array_push($company_ids, $record->company_id);
|
199 |
// array_push($company_ids, $record->company_id);
|
| 200 |
}
|
200 |
// }
|
| 201 |
}
|
201 |
// }
|
| 202 |
|
202 |
|
| 203 |
|
203 |
|
| 204 |
|
204 |
|
| 205 |
foreach ($company_ids as $company_id) {
|
205 |
// foreach ($company_ids as $company_id) {
|
| 206 |
$otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
|
206 |
// $otherUsers = $capsuleUserMapper->fetchAllUserIdsForCapsulesActiveByCompanyId($company_id);
|
| 207 |
foreach ($otherUsers as $user_id) {
|
207 |
// foreach ($otherUsers as $user_id) {
|
| 208 |
if ($currentUser->id != $user_id) {
|
208 |
// if ($currentUser->id != $user_id) {
|
| 209 |
|
209 |
|
| 210 |
if (!in_array($user_id, $capsule_user_ids)) {
|
210 |
// if (!in_array($user_id, $capsule_user_ids)) {
|
| 211 |
array_push($capsule_user_ids, $user_id);
|
211 |
// array_push($capsule_user_ids, $user_id);
|
| 212 |
}
|
212 |
// }
|
| 213 |
}
|
213 |
// }
|
| 214 |
}
|
214 |
// }
|
| 215 |
}
|
215 |
// }
|
| 216 |
|
216 |
|
| 217 |
$capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
|
217 |
// $capsule_user_ids = $capsule_user_ids ? $capsule_user_ids : [0];
|
| 218 |
|
218 |
|
| 219 |
|
219 |
|
| 220 |
$other_users = array_unique(array_merge(
|
220 |
// $other_users = array_unique(array_merge(
|
| 221 |
$second_degree_connections_ids,
|
221 |
// $second_degree_connections_ids,
|
| 222 |
$company_user_ids,
|
222 |
// $company_user_ids,
|
| 223 |
$group_member_ids,
|
223 |
// $group_member_ids,
|
| 224 |
$capsule_user_ids
|
224 |
// $capsule_user_ids
|
| 225 |
));
|
225 |
// ));
|
| Línea 226... |
Línea 226... |
| 226 |
|
226 |
|
| 227 |
|
227 |
|
| 228 |
|
228 |
|
| 229 |
|
229 |
|
| 230 |
|
230 |
|
| 231 |
|
231 |
|
| 232 |
|
232 |
|
| 233 |
|
233 |
|
| 234 |
$items = [];
|
234 |
// $items = [];
|
| 235 |
$queryMapper = QueryMapper::getInstance($this->adapter);
|
235 |
// $queryMapper = QueryMapper::getInstance($this->adapter);
|
| 236 |
$select = $queryMapper->getSql()->select();
|
236 |
// $select = $queryMapper->getSql()->select();
|
| 237 |
$select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
|
237 |
// $select->columns(['id', 'uuid', 'first_name', 'last_name', 'image']);
|
| 238 |
$select->from(['u' => UserMapper::_TABLE]);
|
238 |
// $select->from(['u' => UserMapper::_TABLE]);
|
| 239 |
$select->where->equalTo('network_id', $currentUser->network_id);
|
239 |
// $select->where->equalTo('network_id', $currentUser->network_id);
|
| 240 |
$select->where->in('u.id', $other_users);
|
240 |
// $select->where->in('u.id', $other_users);
|
| 241 |
$select->where->notIn('u.id', $first_degree_connections_ids);
|
241 |
// $select->where->notIn('u.id', $first_degree_connections_ids);
|
| 242 |
$select->where->notEqualTo('u.id', $currentUser->id);
|
242 |
// $select->where->notEqualTo('u.id', $currentUser->id);
|
| 243 |
$select->where->equalTo('u.status', User::STATUS_ACTIVE);
|
243 |
// $select->where->equalTo('u.status', User::STATUS_ACTIVE);
|
| 244 |
$select->where->in('u.usertype_id', [UserType::ADMIN, UserType::USER]);
|
244 |
// $select->where->in('u.usertype_id', [UserType::ADMIN, UserType::USER]);
|
| 245 |
$select->order(['first_name', 'last_name']);
|
245 |
// $select->order(['first_name', 'last_name']);
|
| 246 |
|
246 |
|
| 247 |
//echo $select->getSqlString($this->adapter->platform); exit;
|
247 |
// //echo $select->getSqlString($this->adapter->platform); exit;
|
| 248 |
|
248 |
|
| 249 |
$records = $queryMapper->fetchAll($select);
|
249 |
// $records = $queryMapper->fetchAll($select);
|
| 250 |
foreach ($records as $record) {
|
250 |
// foreach ($records as $record) {
|
| 251 |
|
251 |
|
| 252 |
$relation = [];
|
252 |
// $relation = [];
|
| 253 |
if (in_array($record['id'], $second_degree_connections_ids)) {
|
253 |
// if (in_array($record['id'], $second_degree_connections_ids)) {
|
| 254 |
array_push($relation, 'LABEL_RELATION_TYPE_SECOND_GRADE');
|
254 |
// array_push($relation, 'LABEL_RELATION_TYPE_SECOND_GRADE');
|
| 255 |
}
|
255 |
// }
|
| 256 |
if (in_array($record['id'], $company_user_ids)) {
|
256 |
// if (in_array($record['id'], $company_user_ids)) {
|
| 257 |
array_push($relation, 'LABEL_RELATION_TYPE_COMPANY_USER');
|
257 |
// array_push($relation, 'LABEL_RELATION_TYPE_COMPANY_USER');
|
| 258 |
}
|
258 |
// }
|
| 259 |
if (in_array($record['id'], $group_member_ids)) {
|
259 |
// if (in_array($record['id'], $group_member_ids)) {
|
| 260 |
array_push($relation, 'LABEL_RELATION_TYPE_GROUP_MEMBER');
|
260 |
// array_push($relation, 'LABEL_RELATION_TYPE_GROUP_MEMBER');
|
| 261 |
}
|
261 |
// }
|
| 262 |
if (in_array($record['id'], $capsule_user_ids)) {
|
262 |
// if (in_array($record['id'], $capsule_user_ids)) {
|
| 263 |
array_push($relation, 'LABEL_RELATION_TYPE_CAPSULE_USER');
|
263 |
// array_push($relation, 'LABEL_RELATION_TYPE_CAPSULE_USER');
|
| 264 |
}
|
264 |
// }
|
| 265 |
|
265 |
|
| 266 |
|
266 |
|
| 267 |
$connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $record['id']);
|
267 |
// $connection = $connectionMapper->fetchOneByUserId1AndUserId2($currentUser->id, $record['id']);
|
| 268 |
|
268 |
|
| 269 |
$item = [
|
269 |
// $item = [
|
| 270 |
'id' => $record['uuid'],
|
270 |
// 'id' => $record['uuid'],
|
| 271 |
'name' => trim($record['first_name'] . ' ' . $record['last_name']),
|
271 |
// 'name' => trim($record['first_name'] . ' ' . $record['last_name']),
|
| 272 |
'image' => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
|
272 |
// 'image' => $this->url()->fromRoute('storage', ['code' => $record['uuid'], 'type' => 'user', 'filename' => $record['image']]),
|
| 273 |
'profile' => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
|
273 |
// 'profile' => $this->url()->fromRoute('profile/view', ['id' => $record['uuid']]),
|
| 274 |
'relation' => $relation,
|
274 |
// 'relation' => $relation,
|
| 275 |
'link_cancel' => '',
|
275 |
// 'link_cancel' => '',
|
| 276 |
'link_request' => '',
|
276 |
// 'link_request' => '',
|
| 277 |
];
|
277 |
// ];
|
| 278 |
|
278 |
|
| 279 |
if ($connection) {
|
279 |
// if ($connection) {
|
| 280 |
switch ($connection->status) {
|
280 |
// switch ($connection->status) {
|
| 281 |
case Connection::STATUS_SENT:
|
281 |
// case Connection::STATUS_SENT:
|
| 282 |
$item['link_cancel'] = $this->url()->fromRoute('connection/delete', ['id' => $record['uuid']]);
|
282 |
// $item['link_cancel'] = $this->url()->fromRoute('connection/delete', ['id' => $record['uuid']]);
|
| 283 |
break;
|
283 |
// break;
|
| 284 |
|
284 |
|
| 285 |
case Connection::STATUS_ACCEPTED:
|
285 |
// case Connection::STATUS_ACCEPTED:
|
| 286 |
$item['link_cancel'] = $this->url()->fromRoute('connection/cancel', ['id' => $record['uuid']]);
|
286 |
// $item['link_cancel'] = $this->url()->fromRoute('connection/cancel', ['id' => $record['uuid']]);
|
| 287 |
break;
|
287 |
// break;
|
| 288 |
|
288 |
|
| 289 |
default:
|
289 |
// default:
|
| 290 |
$item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
|
290 |
// $item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
|
| 291 |
break;
|
291 |
// break;
|
| 292 |
}
|
292 |
// }
|
| 293 |
} else {
|
293 |
// } else {
|
| 294 |
$item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
|
294 |
// $item['link_request'] = $this->url()->fromRoute('connection/request', ['id' => $record['uuid']]);
|
| 295 |
}
|
295 |
// }
|
| 296 |
|
296 |
|
| 297 |
|
297 |
|
| 298 |
array_push($items, $item);
|
298 |
// array_push($items, $item);
|
| 299 |
}
|
299 |
// }
|
| 300 |
|
300 |
|
| 301 |
return new JsonModel([
|
301 |
// return new JsonModel([
|
| 302 |
'success' => true,
|
302 |
// 'success' => true,
|
| 303 |
'data' => $items
|
303 |
// 'data' => $items
|
| Línea 304... |
Línea 304... |
| 304 |
]);
|
304 |
// ]);
|
| 305 |
} else {
|
305 |
// } else {
|
| 306 |
return new JsonModel([
|
306 |
// return new JsonModel([
|