• Модуль: lists
  • Путь к файлу: ~/bitrix/modules/lists/classes/general/lists.php
  • Класс: CLists
  • Вызов: CLists::createSeachableContentForProperty
static function createSeachableContentForProperty($fields)
{
	$searchableContent = '';

	global $DB;
	$properties = array();
	foreach($fields["PROPERTY_VALUES"] as $propertyId => $valueData)
	{
		if(!$valueData)
			continue;
		$properties[$propertyId] = array();
		if(is_array($valueData))
		{
			foreach($valueData as $valueId => $value)
			{
				if(is_object($value))
					continue;
				if(isset($value["VALUE"]))
				{
					if(is_array($value["VALUE"]))
					{
						if(!empty($value["VALUE"]))
							$properties[$propertyId][] = $value["VALUE"];
					}
					else
					{
						if($value["VALUE"] <> '')
							$properties[$propertyId][] = $value["VALUE"];
					}
				}
				else
				{
					if(is_array($value))
					{
						foreach($value as $v)
						{
							if($v <> '')
								$properties[$propertyId][] = $v;
						}
					}
					else
					{
						if($value <> '')
							$properties[$propertyId][] = $value;
					}
				}
			}
		}
		else
		{
			$properties[$propertyId][] = $valueData;
		}

		$queryObject = CIBlockProperty::getById($propertyId);
		if($property = $queryObject->fetch())
		{
			$propertyValues = array();
			if(!empty($property["USER_TYPE"]))
			{
				switch($property["USER_TYPE"])
				{
					case "Date":
					case "DateTime":
					{
						$format = "FULL";
						if($property["USER_TYPE"] == "Date")
							$format = "SHORT";
						foreach($properties[$propertyId] as $value)
						{
							try
							{
								$date = new BitrixMainTypeDateTime($value);
								$propertyValues[] = $date->format($DB->dateFormatToPHP(CSite::getDateFormat($format)));
							}
							catch (Exception $ex)
							{
								$propertyValues[] = $value;
							}
						}
						break;
					}
					case "HTML":
					{
						foreach($properties[$propertyId] as $value)
						{
							if (is_string($value))
							{
								$unserialize = unserialize($value, ['allowed_classes' => false]);
								if($unserialize)
									$value = $unserialize;
							}
							if (
								is_array($value)
								&& !empty($value['TEXT'])
								&& is_string($value['TEXT'])
							)
							{
								if (isset($value["TYPE"]))
								{
									$value["TYPE"] = mb_strtoupper($value["TYPE"]);
									if ($value["TYPE"] == "HTML")
										$propertyValues[] = HTMLToTxt($value["TEXT"]);
								}
							}
						}
						break;
					}
					case "EList":
					{
						if(!empty($properties[$propertyId]))
						{
							$queryObject = CIBlockElement::getList(array(), array("ID" => $properties[$propertyId]),
								false, false, array('NAME'));
							while($element = $queryObject->getNext())
								$propertyValues[] = $element["~NAME"];
						}
						break;
					}
					case "Money":
					case "map_yandex":
					{
						$propertyValues = $properties[$propertyId];
						break;
					}
					case "Sequence":
					{
						foreach($properties[$propertyId] as $value)
							$propertyValues[] = intval($value);
						break;
					}
					case "ECrm":
					{
						if(Loader::includeModule("crm"))
						{
							foreach($properties[$propertyId] as $value)
							{
								if (intval($value))
								{
									foreach($property["USER_TYPE_SETTINGS"] as $entityType => $marker)
									{
										if ($entityType != "VISIBLE" && $marker == "Y")
										{
											$typeId = CCrmOwnerType::resolveID($entityType);
											$propertyValues[] = CCrmOwnerType::getCaption($typeId, $value, false);
										}
									}
								}
								else
								{
									$explode = explode('_', $value);
									$type = $explode[0];
									$typeId = CCrmOwnerType::resolveID(CCrmOwnerTypeAbbr::resolveName($type));
									$propertyValues[] = CCrmOwnerType::getCaption($typeId, $explode[1], false);
								}
							}
						}
						break;
					}
					case "employee":
					{
						$siteNameFormat = CSite::getNameFormat(false);
						foreach($properties[$propertyId] as $value)
						{
							$user = new CUser();
							$userDetails = $user->getByID($value)->fetch();
							if(is_array($userDetails))
								$propertyValues[] = CUser::formatName($siteNameFormat, $userDetails,true,false);
						}
						break;
					}
					case "DiskFile":
					{
						if(Loader::includeModule("disk"))
						{
							foreach($properties[$propertyId] as $value)
							{
								if(!is_array($value))
									$value = array($value);
								foreach($value as $v)
								{
									if(empty($v))
										continue;
									list($type, $realId) = FileUserType::detectType($v);
									if($type == FileUserType::TYPE_ALREADY_ATTACHED)
									{
										$attachedModel = AttachedObject::loadById($realId);
										if($attachedModel)
										{
											$file = $attachedModel->getFile();
											if($file)
												$propertyValues[] = $file->getName();
										}
									}
									else
									{
										$fileModel = File::loadById($realId, array('STORAGE'));
										if($fileModel)
											$propertyValues[] = $fileModel->getName();
									}
								}
							}
						}
						break;
					}
				}
			}
			else
			{
				switch($property["PROPERTY_TYPE"])
				{
					case "S":
					{
						$propertyValues = $properties[$propertyId];
						break;
					}
					case "N":
					{
						$propertyValues = $properties[$propertyId];
						break;
					}
					case "L":
					{
						$queryObject = CIBlockProperty::getPropertyEnum($propertyId);
						while($propertyEnum = $queryObject->fetch())
						{
							if(in_array($propertyEnum["ID"], $properties[$propertyId]))
								$propertyValues[] = $propertyEnum["VALUE"];
						}
						break;
					}
					case "F":
					{
						$listPropertyIdForGetExtraValue = array();
						foreach($properties[$propertyId] as $value)
						{
							if(isset($value["name"]))
							{
								if(!empty($value["name"]))
								{
									$propertyValues[] = $value["name"];
								}
								else
								{
									$listPropertyIdForGetExtraValue[] = $propertyId;
								}
							}
							else
							{
								$fileData = CFile::getFileArray($value);
								if($fileData)
									$propertyValues[] = $fileData["FILE_NAME"];
							}
						}
						if(!empty($fields["ID"]) && !empty($listPropertyIdForGetExtraValue))
						{
							$query = CIblockElement::getPropertyValues($property["IBLOCK_ID"],
								array("ID" => $fields["ID"]), false, array("ID" => $listPropertyIdForGetExtraValue));
							if($listExtraPropertyValues = $query->fetch())
							{
								foreach($listExtraPropertyValues as $id => $extraPropertyValues)
								{
									if($id == "IBLOCK_ELEMENT_ID")
										continue;
									if(is_array($extraPropertyValues))
									{
										foreach($extraPropertyValues as $extraPropertyValue)
										{
											$fileData = CFile::getFileArray($extraPropertyValue);
											if($fileData)
												$propertyValues[] = $fileData["FILE_NAME"];
										}
									}
									else
									{
										$fileData = CFile::getFileArray($extraPropertyValues);
										if($fileData)
											$propertyValues[] = $fileData["FILE_NAME"];
									}
								}
							}
						}
						break;
					}
					case "G":
					{
						if(!empty($properties[$propertyId]))
						{
							$queryObject = CIBlockSection::getList(array(),
								array("=ID" => $properties[$propertyId]), false, array("NAME"));
							while($section = $queryObject->getNext())
								$propertyValues[] = $section["~NAME"];
						}
						break;
					}
					case "E":
					{
						if(!empty($properties[$propertyId]))
						{
							$queryObject = CIBlockElement::getList(array(), array("ID" => $properties[$propertyId]),
								false, false, array('NAME'));
							while($element = $queryObject->getNext())
								$propertyValues[] = $element["~NAME"];
						}
						break;
					}
				}
			}
			foreach($propertyValues as $propertyValue)
				$searchableContent .= "rn".$propertyValue;
		}
	}

	return $searchableContent;
}