33 public static function searchUsers($params = array(), &$searchModified)
35 $search = $params[
'search'];
36 $nameTemplate = $params[
'nameTemplate'];
37 $requestFields = $params[
'requestFields'];
39 $searchResult = \CSocNetLogDestination::searchUsers(
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"),
47 isset($requestFields[
'DEPARTMENT_ID'])
48 && intval($requestFields[
'DEPARTMENT_ID']) > 0
49 ? intval($requestFields[
'DEPARTMENT_ID'])
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'],
106 foreach($usersList as $key => $value)
108 if (array_key_exists($value[
"crmEntity"], $searchResult))
110 unset($searchResult[$value[
"crmEntity"]]);
114 $crmUsersListTmp = $usersListTmp= array();
115 foreach($usersList as $key => $user)
117 if (!empty($user[
'crmEntity']))
119 $crmUsersListTmp[$key] = $user;
123 $usersListTmp[$key] = $user;
126 foreach($searchResult as $key => $user)
128 if (!empty($user[
'crmEntity']))
130 $crmUsersListTmp[$key] = $user;
134 $usersListTmp[$key] = $user;
138 $usersList = $usersListTmp;
139 return $crmUsersListTmp;
144 $searchResult = array();
146 if (Loader::includeModule(
'crm'))
148 $search = $params[
'search'];
149 $nameTemplate = $params[
'nameTemplate'];
151 $res = \CCrmContact::getListEx(
153 [
'%FULL_NAME' => $search,
'@CATEGORY_ID' => 0,],
156 [
'ID',
'NAME',
'SECOND_NAME',
'LAST_NAME',
'COMPANY_TITLE',
'PHOTO']
159 while ($res && ($contact = $res->fetch()))
161 $searchResult[
'CRMCONTACT'.$contact[
'ID']] = array(
162 'id' =>
'CRMCONTACT'.$contact[
'ID'],
163 'entityType' =>
'contacts',
164 'entityId' => $contact[
'ID'],
165 'name' => htmlspecialcharsbx(\CUser::formatName(
169 'NAME' => $contact[
'NAME'],
170 'SECOND_NAME' => $contact[
'SECOND_NAME'],
171 'LAST_NAME' => $contact[
'LAST_NAME']
175 'desc' => htmlspecialcharsbx($contact[
'COMPANY_TITLE'])
178 if (!empty($contact[
'PHOTO']) && intval($contact[
'PHOTO']) > 0)
180 $image = \CFile::resizeImageGet($contact[
'PHOTO'], array(
'width' => 100,
'height' => 100), BX_RESIZE_IMAGE_EXACT);
181 $searchResult[
'CRMCONTACT'.$contact[
'ID']][
'avatar'] = $image[
'src'];
186 return $searchResult;
191 $searchResult = array();
193 if (Loader::includeModule(
'crm'))
195 $search = $params[
'search'];
197 $companyTypeList = \CCrmStatus::getStatusListEx(
'COMPANY_TYPE');
198 $companyIndustryList = \CCrmStatus::getStatusListEx(
'INDUSTRY');
200 $res = \CCrmCompany::getListEx(
202 [
'%TITLE' => $search,
'@CATEGORY_ID' => 0,],
205 [
'ID',
'TITLE',
'COMPANY_TYPE',
'INDUSTRY',
'LOGO']
208 while ($res && ($company = $res->fetch()))
211 if (isset($companyTypeList[$company[
'COMPANY_TYPE']]))
213 $descList[] = $companyTypeList[$company[
'COMPANY_TYPE']];
215 if (isset($companyIndustryList[$company[
'INDUSTRY']]))
217 $descList[] = $companyIndustryList[$company[
'INDUSTRY']];
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))
228 if (!empty($company[
'LOGO']) && intval($company[
'LOGO']) > 0)
230 $image = \CFile::resizeImageGet($company[
'LOGO'], array(
'width' => 100,
'height' => 100), BX_RESIZE_IMAGE_EXACT);
231 $searchResult[
'CRMCOMPANY'.$company[
'ID']][
'avatar'] = $image[
'src'];
236 return $searchResult;
241 $searchResult = array();
243 if (Loader::includeModule(
'crm'))
245 $search = $params[
'search'];
246 $nameTemplate = $params[
'nameTemplate'];
248 $res = \CCrmLead::getListEx(
250 $arFilter = array(
'LOGIC' =>
'OR',
'%FULL_NAME' => $search,
'%TITLE' => $search),
252 $arNavStartParams = array(
'nTopCount' => 20),
253 $arSelectFields = array(
'ID',
'TITLE',
'NAME',
'SECOND_NAME',
'LAST_NAME',
'STATUS_ID')
256 while ($res && ($lead = $res->fetch()))
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(
267 'NAME' => $lead[
'NAME'],
268 'SECOND_NAME' => $lead[
'SECOND_NAME'],
269 'LAST_NAME' => $lead[
'LAST_NAME']
277 return $searchResult;
282 $searchResult = array();
284 if (Loader::includeModule(
'crm'))
286 $search = $params[
'search'];
287 $nameTemplate = $params[
'nameTemplate'];
289 $res = \CCrmDeal::getListEx(
291 $arFilter = array(
'%TITLE' => $search),
293 $arNavStartParams = array(
'nTopCount' => 20),
294 $arSelectFields = array(
'ID',
'TITLE',
'COMPANY_TITLE',
'CONTACT_NAME',
'CONTACT_SECOND_NAME',
'CONTACT_LAST_NAME')
297 while ($res && ($deal = $res->fetch()))
300 if ($deal[
'COMPANY_TITLE'] !=
'')
302 $descList[] = $deal[
'COMPANY_TITLE'];
304 $descList[] = \CUser::formatName(
308 'NAME' => $deal[
'CONTACT_NAME'],
309 'SECOND_NAME' => $deal[
'CONTACT_SECOND_NAME'],
310 'LAST_NAME' => $deal[
'CONTACT_LAST_NAME']
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))
325 return $searchResult;
328 public static function process($requestFields = array())
334 $search = $requestFields[
'SEARCH'];
335 $searchConverted = (!empty($requestFields[
'SEARCH_CONVERTED']) ? $requestFields[
'SEARCH_CONVERTED'] :
false);
339 isset($requestFields[
'ADDITIONAL_SEARCH'])
340 && $requestFields[
'ADDITIONAL_SEARCH'] ==
'Y'
343 $result[
"USERS"] = array();
349 !isset($requestFields[
'USER_SEARCH'])
350 || $requestFields[
'USER_SEARCH'] !=
'N'
353 $searchModified =
false;
356 'nameTemplate' => $nameTemplate,
357 'useNetwork' =>
false,
358 'requestFields' => $requestFields
361 if (!empty($searchModified))
363 $result[
'SEARCH'] = $searchModified;
367 empty($result[
'USERS'])
369 && $search != $searchConverted
373 'search' => $searchConverted,
374 'nameTemplate' => $nameTemplate,
375 'useNetwork' =>
false,
376 'requestFields' => $requestFields
378 $result[
'SEARCH'] = $searchConverted;
383 isset($requestFields[
'SEARCH_SONET_GROUPS'])
384 && $requestFields[
'SEARCH_SONET_GROUPS'] ==
'Y'
389 'features' => (isset($requestFields[
'SEARCH_SONET_FEATUES']) && is_array($requestFields[
'SEARCH_SONET_FEATUES']) ? $requestFields[
'SEARCH_SONET_FEATUES'] :
false),
394 isset($requestFields[
'CRMEMAIL'])
395 && $requestFields[
'CRMEMAIL'] ==
'Y'
400 'nameTemplate' => $nameTemplate
401 ), $result[
'USERS']);
404 isset($requestFields[
'CRMCONTACTEMAIL'])
405 && $requestFields[
'CRMCONTACTEMAIL'] ==
'Y'
410 'nameTemplate' => $nameTemplate,
411 'entities' => array(
"CONTACT"),
412 'searchByEmailOnly' =>
true
413 ), $result[
'USERS']);
417 isset($requestFields[
'CRM_SEARCH'])
418 && $requestFields[
'CRM_SEARCH'] ==
'Y'
421 $crmAllowedTypesList = array();
424 isset($requestFields[
'CRM_SEARCH_TYPES'])
425 && is_array($requestFields[
'CRM_SEARCH_TYPES'])
426 && !empty($requestFields[
'CRM_SEARCH_TYPES'])
429 $crmAllowedTypesList = $requestFields[
'CRM_SEARCH_TYPES'];
432 $result[
'CONTACTS'] = array();
433 $result[
'COMPANIES'] = array();
434 $result[
'LEADS'] = array();
435 $result[
'DEALS'] = array();
438 empty($crmAllowedTypesList)
439 || in_array(
"CRMCONTACT", $crmAllowedTypesList)
444 'nameTemplate' => $nameTemplate
449 empty($crmAllowedTypesList)
450 || in_array(
"CRMCOMPANY", $crmAllowedTypesList)
459 empty($crmAllowedTypesList)
460 || in_array(
"CRMLEAD", $crmAllowedTypesList)
465 'nameTemplate' => $nameTemplate
470 empty($crmAllowedTypesList)
471 || in_array(
"CRMDEAL", $crmAllowedTypesList)
476 'nameTemplate' => $nameTemplate