Выбираем несколько случайных элементов из информационной системы, имеющих хотя бы один общий тег с исходным и добавляем такие элементы контроллеру в тег
samenews
Код вносится в типовую дин. страницу ИС перед показом контроллера
$oInformationsystem_Item = Core_Entity::factory('Informationsystem_Item', $Informationsystem_Controller_Show->item);
$oTag_Informationsystem_Items = $oInformationsystem_Item->Tag_Informationsystem_Items->findAll();
// Минимальное количество тегов для совпадения.
$iSameTags = 1;
$aTagIds = array();
foreach($oTag_Informationsystem_Items as $oTag_Informationsystem_Item)
{
$aTagIds[] = $oTag_Informationsystem_Item->tag_id;
}
$oInformationsystem = Core_Entity::factory('Informationsystem', Core_Array::get(Core_Page::instance()->libParams, 'informationsystemId'));
$Informationsystem_id = $oInformationsystem -> id; // Отбираем элементы только из текущей Инфосистемы
if (count($aTagIds))
{
$oSameTag_Informationsystem_Items = Core_Entity::factory('Tag_Informationsystem_Item');
$oSameTag_Informationsystem_Items->queryBuilder()
->select('tag_informationsystem_items.*')
->where('tag_id', 'IN', $aTagIds)
->where('tag_informationsystem_items.informationsystem_item_id', '!=', $oInformationsystem_Item->id)
->where('informationsystems.id', '=', $Informationsystem_id)
->join('informationsystem_items', 'tag_informationsystem_items.informationsystem_item_id', '=', 'informationsystem_items.id')
->join('informationsystems', 'informationsystem_items.informationsystem_id', '=', 'informationsystems.id')
->where('informationsystems.site_id', '=', CURRENT_SITE)
->groupBy('informationsystem_items.id')
->having('COUNT(tag_id)', '>=', $iSameTags)
->clearOrderBy()
->orderBy('RAND()')
->limit(5); // Указываем количество выводимых элементов
$aSameTag_Informationsystem_Items = $oSameTag_Informationsystem_Items->findAll();
$oXmlSamenews = Core::factory('Core_Xml_Entity')->name('samenews');
$Informationsystem_Controller_Show->addEntity($oXmlSamenews);
foreach($aSameTag_Informationsystem_Items as $oSameTag_Informationsystem_Item)
{
$oXmlSamenews->addEntity(
$oSameTag_Informationsystem_Item
->Informationsystem_Item
->clearEntities()
->showXmlProperties(TRUE) // Добавляем дополнительные свойства
);
}
}