Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
search.php
1<?php
9
15
16Loc::loadMessages(__FILE__);
17
18class Search
19{
20 protected static function actionProcessAjaxGetDepartmentData($requestFields = array())
21 {
22 return array(
23 'USERS' => \CSocNetLogDestination::getUsers(
24 array(
25 'deportament_id' => $requestFields['DEPARTMENT_ID'],
26 "NAME_TEMPLATE" => Handler::getNameTemplate($requestFields)
27 )
28 ),
29 'dataOnly' => true
30 );
31 }
32
33 public static function searchUsers($params = array(), &$searchModified)
34 {
35 $search = $params['search'];
36 $nameTemplate = $params['nameTemplate'];
37 $requestFields = $params['requestFields'];
38
39 $searchResult = \CSocNetLogDestination::searchUsers(
40 array(
41 "SEARCH" => $search,
42 "NAME_TEMPLATE" => $nameTemplate,
43 "SELF" => (!isset($requestFields['SELF']) || $requestFields['SELF'] != 'N'),
44 "EMPLOYEES_ONLY" => (isset($requestFields['EXTRANET_SEARCH']) && $requestFields['EXTRANET_SEARCH'] == "I"),
45 "EXTRANET_ONLY" => (isset($requestFields['EXTRANET_SEARCH']) && $requestFields['EXTRANET_SEARCH'] == "E"),
46 "DEPARTAMENT_ID" => (
47 isset($requestFields['DEPARTMENT_ID'])
48 && intval($requestFields['DEPARTMENT_ID']) > 0
49 ? intval($requestFields['DEPARTMENT_ID'])
50 : false
51 ),
52 "EMAIL_USERS" => (isset($requestFields['EMAIL_USERS']) && $requestFields['EMAIL_USERS'] == 'Y'),
53 "CRMEMAIL_USERS" => (isset($requestFields['CRMEMAIL']) && $requestFields['CRMEMAIL'] == 'Y'),
54 "NETWORK_SEARCH" => $params['useNetwork'],
55 ),
56 $searchModified
57 );
58
59 return $searchResult;
60 }
61
62 protected static function searchSonetGroups($params = array())
63 {
64 $search = $params['search'];
65 $features = $params['features'];
66
67 return \CSocNetLogDestination::searchSonetGroups(array(
68 "SEARCH" => $search,
69 "FEATURES" => $features
70 ));
71 }
72
73 protected static function searchCrmEmails($params = array(), &$usersList)
74 {
75 $search = $params['search'];
76 $nameTemplate = $params['nameTemplate'];
77
78 $searchResult = \CSocNetLogDestination::searchCrmEntities(array(
79 "SEARCH" => $search,
80 "NAME_TEMPLATE" => $nameTemplate
81 ));
82
83 return self::filterCrmSearchResult($searchResult, $usersList);
84 }
85
86
87 protected static function searchCrmEntities($params = array(), &$usersList)
88 {
89 $search = $params['search'];
90 $nameTemplate = $params['nameTemplate'];
91 $entitiesList = $params['entities'];
92 $searchByEmailOnly = $params['searchByEmailOnly'];
93
94 $searchResult = \CSocNetLogDestination::searchCrmEntities(array(
95 "SEARCH" => $search,
96 "NAME_TEMPLATE" => $nameTemplate,
97 "ENTITIES" => $entitiesList,
98 "SEARCH_BY_EMAIL_ONLY" => ($searchByEmailOnly ? "Y" : "N")
99 ));
100
101 return self::filterCrmSearchResult($searchResult, $usersList);
102 }
103
104 protected static function filterCrmSearchResult($searchResult, &$usersList)
105 {
106 foreach($usersList as $key => $value)
107 {
108 if (array_key_exists($value["crmEntity"], $searchResult))
109 {
110 unset($searchResult[$value["crmEntity"]]);
111 }
112 }
113
114 $crmUsersListTmp = $usersListTmp= array();
115 foreach($usersList as $key => $user)
116 {
117 if (!empty($user['crmEntity']))
118 {
119 $crmUsersListTmp[$key] = $user;
120 }
121 else
122 {
123 $usersListTmp[$key] = $user;
124 }
125 }
126 foreach($searchResult as $key => $user)
127 {
128 if (!empty($user['crmEntity']))
129 {
130 $crmUsersListTmp[$key] = $user;
131 }
132 else
133 {
134 $usersListTmp[$key] = $user;
135 }
136 }
137
138 $usersList = $usersListTmp;
139 return $crmUsersListTmp;
140 }
141
142 protected static function searchCrmContacts($params = array())
143 {
144 $searchResult = array();
145
146 if (Loader::includeModule('crm'))
147 {
148 $search = $params['search'];
149 $nameTemplate = $params['nameTemplate'];
150
151 $res = \CCrmContact::getListEx(
152 [],
153 ['%FULL_NAME' => $search, '@CATEGORY_ID' => 0,],
154 false,
155 ['nTopCount' => 20],
156 ['ID', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'COMPANY_TITLE', 'PHOTO']
157 );
158
159 while ($res && ($contact = $res->fetch()))
160 {
161 $searchResult['CRMCONTACT'.$contact['ID']] = array(
162 'id' => 'CRMCONTACT'.$contact['ID'],
163 'entityType' => 'contacts',
164 'entityId' => $contact['ID'],
165 'name' => htmlspecialcharsbx(\CUser::formatName(
166 $nameTemplate,
167 array(
168 'LOGIN' => '',
169 'NAME' => $contact['NAME'],
170 'SECOND_NAME' => $contact['SECOND_NAME'],
171 'LAST_NAME' => $contact['LAST_NAME']
172 ),
173 false, false
174 )),
175 'desc' => htmlspecialcharsbx($contact['COMPANY_TITLE'])
176 );
177
178 if (!empty($contact['PHOTO']) && intval($contact['PHOTO']) > 0)
179 {
180 $image = \CFile::resizeImageGet($contact['PHOTO'], array('width' => 100, 'height' => 100), BX_RESIZE_IMAGE_EXACT);
181 $searchResult['CRMCONTACT'.$contact['ID']]['avatar'] = $image['src'];
182 }
183 }
184 }
185
186 return $searchResult;
187 }
188
189 protected static function searchCrmCompanies($params = array())
190 {
191 $searchResult = array();
192
193 if (Loader::includeModule('crm'))
194 {
195 $search = $params['search'];
196
197 $companyTypeList = \CCrmStatus::getStatusListEx('COMPANY_TYPE');
198 $companyIndustryList = \CCrmStatus::getStatusListEx('INDUSTRY');
199
200 $res = \CCrmCompany::getListEx(
201 [],
202 ['%TITLE' => $search, '@CATEGORY_ID' => 0,],
203 false,
204 ['nTopCount' => 20],
205 ['ID', 'TITLE', 'COMPANY_TYPE', 'INDUSTRY', 'LOGO']
206 );
207
208 while ($res && ($company = $res->fetch()))
209 {
210 $descList = array();
211 if (isset($companyTypeList[$company['COMPANY_TYPE']]))
212 {
213 $descList[] = $companyTypeList[$company['COMPANY_TYPE']];
214 }
215 if (isset($companyIndustryList[$company['INDUSTRY']]))
216 {
217 $descList[] = $companyIndustryList[$company['INDUSTRY']];
218 }
219
220 $searchResult['CRMCOMPANY'.$company['ID']] = array(
221 'id' => 'CRMCOMPANY'.$company['ID'],
222 'entityId' => $company['ID'],
223 'entityType' => 'companies',
224 'name' => htmlspecialcharsbx(str_replace(array(';', ','), ' ', $company['TITLE'])),
225 'desc' => htmlspecialcharsbx(implode(', ', $descList))
226 );
227
228 if (!empty($company['LOGO']) && intval($company['LOGO']) > 0)
229 {
230 $image = \CFile::resizeImageGet($company['LOGO'], array('width' => 100, 'height' => 100), BX_RESIZE_IMAGE_EXACT);
231 $searchResult['CRMCOMPANY'.$company['ID']]['avatar'] = $image['src'];
232 }
233 }
234 }
235
236 return $searchResult;
237 }
238
239 protected static function searchCrmLeads($params = array())
240 {
241 $searchResult = array();
242
243 if (Loader::includeModule('crm'))
244 {
245 $search = $params['search'];
246 $nameTemplate = $params['nameTemplate'];
247
248 $res = \CCrmLead::getListEx(
249 $arOrder = array(),
250 $arFilter = array('LOGIC' => 'OR', '%FULL_NAME' => $search, '%TITLE' => $search),
251 $arGroupBy = false,
252 $arNavStartParams = array('nTopCount' => 20),
253 $arSelectFields = array('ID', 'TITLE', 'NAME', 'SECOND_NAME', 'LAST_NAME', 'STATUS_ID')
254 );
255
256 while ($res && ($lead = $res->fetch()))
257 {
258 $searchResult['CRMLEAD'.$lead['ID']] = array(
259 'id' => 'CRMLEAD'.$lead['ID'],
260 'entityId' => $lead['ID'],
261 'entityType' => 'leads',
262 'name' => htmlspecialcharsbx($lead['TITLE']),
263 'desc' => htmlspecialcharsbx(\CUser::formatName(
264 $nameTemplate,
265 array(
266 'LOGIN' => '',
267 'NAME' => $lead['NAME'],
268 'SECOND_NAME' => $lead['SECOND_NAME'],
269 'LAST_NAME' => $lead['LAST_NAME']
270 ),
271 false, false
272 ))
273 );
274 }
275 }
276
277 return $searchResult;
278 }
279
280 protected static function searchCrmDeals($params = array())
281 {
282 $searchResult = array();
283
284 if (Loader::includeModule('crm'))
285 {
286 $search = $params['search'];
287 $nameTemplate = $params['nameTemplate'];
288
289 $res = \CCrmDeal::getListEx(
290 $arOrder = array(),
291 $arFilter = array('%TITLE' => $search),
292 $arGroupBy = false,
293 $arNavStartParams = array('nTopCount' => 20),
294 $arSelectFields = array('ID', 'TITLE', 'COMPANY_TITLE', 'CONTACT_NAME', 'CONTACT_SECOND_NAME', 'CONTACT_LAST_NAME')
295 );
296
297 while ($res && ($deal = $res->fetch()))
298 {
299 $descList = array();
300 if ($deal['COMPANY_TITLE'] != '')
301 {
302 $descList[] = $deal['COMPANY_TITLE'];
303 }
304 $descList[] = \CUser::formatName(
305 $nameTemplate,
306 array(
307 'LOGIN' => '',
308 'NAME' => $deal['CONTACT_NAME'],
309 'SECOND_NAME' => $deal['CONTACT_SECOND_NAME'],
310 'LAST_NAME' => $deal['CONTACT_LAST_NAME']
311 ),
312 false, false
313 );
314
315 $arDeals['CRMDEAL'.$deal['ID']] = array(
316 'id' => 'CRMDEAL'.$deal['ID'],
317 'entityId' => $deal['ID'],
318 'entityType' => 'deals',
319 'name' => htmlspecialcharsbx($deal['TITLE']),
320 'desc' => htmlspecialcharsbx(implode(', ', $descList))
321 );
322 }
323 }
324
325 return $searchResult;
326 }
327
328 public static function process($requestFields = array())
329 {
330 $result = array(
331 'dataOnly' => true
332 );
333
334 $search = $requestFields['SEARCH'];
335 $searchConverted = (!empty($requestFields['SEARCH_CONVERTED']) ? $requestFields['SEARCH_CONVERTED'] : false);
336 $nameTemplate = Handler::getNameTemplate($requestFields);
337
338 if (
339 isset($requestFields['ADDITIONAL_SEARCH'])
340 && $requestFields['ADDITIONAL_SEARCH'] == 'Y'
341 )
342 {
343 $result["USERS"] = array();
344
345 return $result;
346 }
347
348 if (
349 !isset($requestFields['USER_SEARCH'])
350 || $requestFields['USER_SEARCH'] != 'N'
351 )
352 {
353 $searchModified = false;
354 $result["USERS"] = self::searchUsers(array(
355 'search' => $search,
356 'nameTemplate' => $nameTemplate,
357 'useNetwork' => false,
358 'requestFields' => $requestFields
359 ), $searchModified);
360
361 if (!empty($searchModified))
362 {
363 $result['SEARCH'] = $searchModified;
364 }
365
366 if (
367 empty($result['USERS'])
368 && $searchConverted
369 && $search != $searchConverted
370 )
371 {
372 $result['USERS'] = self::searchUsers(array(
373 'search' => $searchConverted,
374 'nameTemplate' => $nameTemplate,
375 'useNetwork' => false,
376 'requestFields' => $requestFields
377 ), $searchModified);
378 $result['SEARCH'] = $searchConverted;
379 }
380 }
381
382 if (
383 isset($requestFields['SEARCH_SONET_GROUPS'])
384 && $requestFields['SEARCH_SONET_GROUPS'] == 'Y'
385 )
386 {
387 $result['SONET_GROUPS'] = self::searchSonetGroups(array(
388 'search' => $search,
389 'features' => (isset($requestFields['SEARCH_SONET_FEATUES']) && is_array($requestFields['SEARCH_SONET_FEATUES']) ? $requestFields['SEARCH_SONET_FEATUES'] : false),
390 ));
391 }
392
393 if (
394 isset($requestFields['CRMEMAIL'])
395 && $requestFields['CRMEMAIL'] == 'Y'
396 )
397 {
398 $result['CRM_EMAILS'] = self::searchCrmEmails(array(
399 'search' => $search,
400 'nameTemplate' => $nameTemplate
401 ), $result['USERS']);
402 }
403 elseif (
404 isset($requestFields['CRMCONTACTEMAIL'])
405 && $requestFields['CRMCONTACTEMAIL'] == 'Y'
406 )
407 {
408 $result['CRM_EMAILS'] = self::searchCrmEntities(array(
409 'search' => $search,
410 'nameTemplate' => $nameTemplate,
411 'entities' => array("CONTACT"),
412 'searchByEmailOnly' => true
413 ), $result['USERS']);
414 }
415
416 if (
417 isset($requestFields['CRM_SEARCH'])
418 && $requestFields['CRM_SEARCH'] == 'Y'
419 )
420 {
421 $crmAllowedTypesList = array();
422
423 if (
424 isset($requestFields['CRM_SEARCH_TYPES'])
425 && is_array($requestFields['CRM_SEARCH_TYPES'])
426 && !empty($requestFields['CRM_SEARCH_TYPES'])
427 )
428 {
429 $crmAllowedTypesList = $requestFields['CRM_SEARCH_TYPES'];
430 }
431
432 $result['CONTACTS'] = array();
433 $result['COMPANIES'] = array();
434 $result['LEADS'] = array();
435 $result['DEALS'] = array();
436
437 if (
438 empty($crmAllowedTypesList)
439 || in_array("CRMCONTACT", $crmAllowedTypesList)
440 )
441 {
442 $result['CONTACTS'] = self::searchCrmContacts(array(
443 'search' => $search,
444 'nameTemplate' => $nameTemplate
445 ));
446 }
447
448 if (
449 empty($crmAllowedTypesList)
450 || in_array("CRMCOMPANY", $crmAllowedTypesList)
451 )
452 {
453 $result['CONTACTS'] = self::searchCrmCompanies(array(
454 'search' => $search
455 ));
456 }
457
458 if (
459 empty($crmAllowedTypesList)
460 || in_array("CRMLEAD", $crmAllowedTypesList)
461 )
462 {
463 $result['LEADS'] = self::searchCrmLeads(array(
464 'search' => $search,
465 'nameTemplate' => $nameTemplate
466 ));
467 }
468
469 if (
470 empty($crmAllowedTypesList)
471 || in_array("CRMDEAL", $crmAllowedTypesList)
472 )
473 {
474 $result['LEADS'] = self::searchCrmDeals(array(
475 'search' => $search,
476 'nameTemplate' => $nameTemplate
477 ));
478 }
479 }
480
481 return $result;
482 }
483}
static loadMessages($file)
Definition loc.php:64
static actionProcessAjaxGetDepartmentData($requestFields=array())
Definition search.php:20
static filterCrmSearchResult($searchResult, &$usersList)
Definition search.php:104
static searchCrmEntities($params=array(), &$usersList)
Definition search.php:87
static searchUsers($params=array(), &$searchModified)
Definition search.php:33
static searchCrmEmails($params=array(), &$usersList)
Definition search.php:73