ИНФОСИСТЕМЫ / PHP КОДЫ вывода данных для ИНФОСИСТЕМ

Заметка создана: 01 апреля 2034 г.
Снижаем нагрузку за счёт оптимизации обращений к базе данных
    
                        ->groupsMode('none')
                        ->itemsForbiddenTags(
                                array(
                                'description',
                                'text',
                                'guid',
                                'ip',
                                'seo_description',
                                'seo_keywords',
                                'seo_title',
                                'comment',
                                'image_large_width', 
                                'image_large_height',
                                'image_large',
                                'datetime', 
                                'start_datetime', 
                                'end_datetime', 
                                'adult', 
                                'cpa', 
                                'showed', 
                                'indexing',
                                'comments_count',
                                'comments_grade_sum',
                                'comments_grade_count',
                                'comments_average_grade',
                               ))
                        ->groupsForbiddenTags(
                                array(
                                'seo_title',
                                'seo_item_description_template',
                                'seo_item_keywords_template',
                                'seo_item_title_template',
                                'seo_group_description_template',
                                'seo_group_keywords_template',
                                'seo_group_title_template',
                                'seo_description',
                                'seo_keywords',
                                'siteuser_group_id',
                                'user_id',
                                'guid',
                                'siteuser_id',
                                'items_count',
                                'items_total_count',
                                'image_large',           
                                'image_large_width',
                                'image_large_height',
                                'image_small_width',
                                'image_small_height',
                                'siteuser_group_id',               
                                'indexing',
                                'subgroups_count',
                                'subgroups_total_count'
                            ))
                        ->groupsProperties(FALSE)
                        ->groupsPropertiesList(FALSE)
                        ->itemsProperties(FALSE)
                        ->itemsPropertiesList(FALSE)
                        ->siteuser(FALSE)
                        ->siteuserProperties(FALSE)
                        ->tags(FALSE)
                        ->votes(FALSE)
                        //->cache(FALSE) 
                        ->comments(FALSE)
                        ->commentsRating(TRUE)
Меняем ID макета для инфоэлемента
if (isset($Informationsystem_Controller_Show->item) && $Informationsystem_Controller_Show->item)
{
	Core_Page::instance()->template(
		Core_Entity::factory('Template', 35)
	);
}
Меню инфосистемы
 <?php
     // Меню из инфосистемы
    $Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
    Core_Entity::factory('Informationsystem', 15)
     );
     $Informationsystem_Controller_Show
    ->xsl(
       Core_Entity::factory('Xsl')->getByName('МенюИнфосистемы')
    )

    ->group(FALSE)
    ->limit(15)
    ->show();
    ?>

     <?php
     // МЕНЮ ИНФОСИСТЕМЫ
     if (Core::moduleIsActive('informationsystem'))
     {
     $Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
      Core_Entity::factory('Informationsystem', 1)
      );

      $Informationsystem_Controller_Show
      ->xsl(
         Core_Entity::factory('Xsl')->getByName('ДеревоНовостей')
      )
      ->groupsMode('all')
      ->itemsForbiddenTags(array('text', 'description'))
      ->group(FALSE)
      ->limit(0)
      ->show();
      }
      ?>
Вывод статей или новостей
  <?php
          // Новости
          if (Core::moduleIsActive('informationsystem'))
          {
               $Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
                    Core_Entity::factory('Informationsystem', 27)
               );
               $Informationsystem_Controller_Show
                    ->xsl(
                         Core_Entity::factory('Xsl')->getByName('СписокНовостейНаГлавной')
                    )
                    ->groupsMode('none')
                    ->itemsForbiddenTags(array('text'))
                    ->group(FALSE)
                    ->limit(2)
                    ->show();
          }
     ?>
Случайный вывод новостей из группы
<?php
          // Новости
          if (Core::moduleIsActive('informationsystem'))
          {
               $Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
                    Core_Entity::factory('Informationsystem', 1)
               );

               $Informationsystem_Controller_Show
                    ->informationsystemItems()
                    ->queryBuilder()
                    ->clearOrderBy()
                    ->orderBy('RAND()');

               $Informationsystem_Controller_Show
                    ->xsl(
                         Core_Entity::factory('Xsl')->getByName('СписокУслугНаГлавной')
                    )
                    ->groupsMode('none')
                    ->itemsForbiddenTags(array('text'))
                    ->group(14)
                    ->limit(2)
                    ->show();
          }
    ?>
Вывод новостей с ссылкой на архив
<?php
     // НОВОСТИ
      if (Core::moduleIsActive('informationsystem'))
     {
     $Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
          Core_Entity::factory('Informationsystem', '15')
     );

     $Informationsystem_Controller_Show
          ->xsl(
               Core_Entity::factory('Xsl')->getByName('НовостиНаГлавной')
          )
          ->groupsMode('none')
          ->itemsForbiddenTags(array('text'))
          ->group(FALSE)
          ->limit(2)
          ->addEntity(Core::factory('Core_Xml_Entity')
               ->name('НовостиНаГлавной')
               ->value(1))
          ->addEntity(Core::factory('Core_Xml_Entity')
               ->name('ОтображатьСсылкуНаАрхив')
               ->value(1))
          ->show();
}
?>
Вывод одной новости по ее id
<?php
$Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
   Core_Entity::factory('Informationsystem', 1)
);

$Informationsystem_Controller_Show
   ->xsl(
      Core_Entity::factory('Xsl')->getByName('Новость')
   )
   ->item(123)
   ->show();
?>
Вывод элементов инфосистемы по id дополнительного свойства
<?php

  // Новости
      $Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
         Core_Entity::factory('Informationsystem', 1)
      );
      $Informationsystem_Controller_Show
         ->xsl(
            Core_Entity::factory('Xsl')->getByName('СписокНовостейНаГлавной')
         )
         ->groupsMode('none')
         ->itemsForbiddenTags(array('text'))
         ->itemsProperties(TRUE)
         ->group(FALSE)
         ->limit(3);

      // Объединение с нужной таблицей свойств
      $Informationsystem_Controller_Show
         ->informationsystemItems()
         ->queryBuilder()
         ->leftJoin('informationsystem_item_properties', 'informationsystem_items.informationsystem_id', '=', 'informationsystem_item_properties.informationsystem_id')
         ->leftJoin('property_value_ints', 'informationsystem_items.id', '=', 'property_value_ints.entity_id',
            array(
               array('AND' => array('informationsystem_item_properties.property_id', '=', Core_QueryBuilder::expression('`property_value_ints`.`property_id`')))
            )
         )
         // Идентификатор дополнительного свойства
         ->where('informationsystem_item_properties.property_id', '=', 19)
         // Значание дополнительного свойства
         ->where('property_value_ints.value', '=', '123')
         ->groupBy('informationsystem_items.id')
         // Количество свойств
         ->having('COUNT(informationsystem_item_properties.informationsystem_id)', '=', 1);

         $Informationsystem_Controller_Show->show();
?>
Вывод групп инфосистемы по id дополнительного свойства
<?php

  // ГРУППЫ
      $Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
         Core_Entity::factory('Informationsystem', 16)
      );
      $Informationsystem_Controller_Show
         ->xsl(
            Core_Entity::factory('Xsl')->getByName('СписокСтатейСайт4')
         )
         ->groupsMode('none')
         ->itemsForbiddenTags(array('text'))
         ->group(TRUE)
         ->groupsProperties(TRUE)
         ->limit(3)
         //->show()
         ;

      // Объединение с нужной таблицей свойств
      $Informationsystem_Controller_Show
         ->informationsystemGroups()
         ->queryBuilder()
         ->leftJoin('informationsystem_group_properties', 'informationsystem_groups.informationsystem_id', '=', 'informationsystem_group_properties.informationsystem_id')
         ->leftJoin('property_value_ints', 'informationsystem_groups.id', '=', 'property_value_ints.entity_id',
            array(
               array('AND' => array('informationsystem_group_properties.property_id', '=', Core_QueryBuilder::expression('`property_value_ints`.`property_id`')))
            )
         )
         // Идентификатор дополнительного свойства
         ->where('informationsystem_group_properties.property_id', '=', 19)
         // Значание дополнительного свойства
         ->where('property_value_ints.value', '=', '123')
         ->groupBy('informationsystem_groups.id')
         // Количество свойств
         ->having('COUNT(informationsystem_group_properties.informationsystem_id)', '=', 1);

         $Informationsystem_Controller_Show->show();
    ?>
Случайный вывод элементов Инфосистемы
<?php
$Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
            Core_Entity::factory('Informationsystem', 20)
         );
         $Informationsystem_Controller_Show
->xsl(Core_Entity::factory('Xsl')->getByName('СписокХитовНаГлавной'))
->groupsMode('none')
->itemsForbiddenTags(array('text'))
->group(FALSE)
->limit(3)
->itemsProperties(TRUE);

$Informationsystem_Controller_Show
->informationsystemItems()
->queryBuilder()
->clearOrderBy()
->orderBy('RAND()');
$Informationsystem_Controller_Show->show();
  ?>
Вывод меток Инфосистемы
<?php
   // Метки
          if (Core::moduleIsActive('informationsystem'))
          {
               $Informationsystem_Controller_Tag_Show = new Informationsystem_Controller_Tag_Show(
                    Core_Entity::factory('Informationsystem', 1)
               );
               $Informationsystem_Controller_Tag_Show
                    ->xsl(
                         Core_Entity::factory('Xsl')->getByName('ОблакоТэговИнформационнойСистемы')
                    )
                    ->show();
          }
        ?>
Вывод элементов конкретной группы
<?php

$Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
    Core_Entity::factory('Informationsystem', 8)
);

$Informationsystem_Controller_Show
    ->xsl(
        Core_Entity::factory('Xsl')->getByName('СписокЭлементовИнфосистемы')
    )
    ->limit(50)
    ->group(34)
    ->show();
?>
Популярные информационные элементы за месяц
<h3>Популярные</h3>
<?php
$Informationsystem_Controller_Show = new Informationsystem_Controller_Show(
   Core_Entity::factory('Informationsystem', 1)
);
$Informationsystem_Controller_Show
   ->xsl(
      Core_Entity::factory('Xsl')->getByName('ВыводПопулярныхФотоНаГлавной')
   )
   ->groupsMode('none')
simi
   ->itemsForbiddenTags(array('text'))
   ->group(FALSE)
   ->limit(10);

 $Informationsystem_Controller_Show
   ->informationsystemItems()
   ->queryBuilder()
   ->where('informationsystem_items.active', '=', 1)
   ->where('informationsystem_items.datetime', '>', Core_Date::timestamp2sql(strtotime("-30 day")))
   ->clearOrderBy()
   ->orderBy('informationsystem_items.showed', 'DESC');

$Informationsystem_Controller_Show->show();
?>
Вывод нескольких схожих инфоэлементов. Код добавляем в ТДС инфосистемы
$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;
}
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)
      ->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(4);
   $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) // Добавляем дополнительные свойства в похожие товары
      );
   }
}


<!--==Этот код добавляем в XSL-шаблон вывода единицы Инфосистемы==-->
  <xsl:if test="count(samenews) >0">
            <div class="samenews"><p class="h4">Статьи по теме</p>
                <div class="row"><xsl:apply-templates select="//samenews/informationsystem_item[@id]" mode="samenews"
/></div>
            </div>
   </xsl:if>


<!--=== Шаблон для схожих статей ===-->
<xsl:template match="//samenews/informationsystem_item" mode="samenews"
>
    <xsl:if test="@id !=''">
        <div class="col-12"><a href="{url}"><xsl:value-of disable-output-escaping="yes" select="name"/></a>
        <xsl:value-of disable-output-escaping="yes" select="description"/>  
        </div>
    </xsl:if>
</xsl:template>
ВЫВОД ОПРЕДЕЛЕННЫХ ЭЛЕМЕНТОВ ИНФОСИСТЕМЫ
<?php
if (Core::moduleIsActive('informationsystem')) {
    $Informationsystem_Controller_Show = new Informationsystem_Controller_Show(Core_Entity::factory('Informationsystem', 17)); // Идентификатор информационной системы
    $Informationsystem_Controller_Show->xsl(Core_Entity::factory('Xsl')->getByName('ЭлементыНаГлавной'))->groupsMode('none')->itemsForbiddenTags(array( // Название XSL шаблона
        'text'
    ))->group(FALSE)->limit(18); // Ограничение на кол-во элементов
    
    $Informationsystem_Controller_Show->informationsystemItems()->queryBuilder()->leftJoin('informationsystem_item_properties', 'informationsystem_items.informationsystem_id', '=', 'informationsystem_item_properties.informationsystem_id')->leftJoin('property_value_ints', 'informationsystem_items.id', '=', 'property_value_ints.entity_id', array(
        array(
            'AND' => array(
                'informationsystem_item_properties.property_id',
                '=',
                Core_QueryBuilder::expression('`property_value_ints`.`property_id`')
            )
        )
    ))
    
        ->where('informationsystem_item_properties.property_id', '=', 77) // Идентификатор дополнительного свойства
    
        ->where('property_value_ints.value', '=', '1'); // Значание дополнительного свойства
    $Informationsystem_Controller_Show->show();  
}
?>
Выбор инфоэлементов из подгрупп независимо от уровня вложенности. Код добавляем в ТДС Инфосистемы
class My_Informationsystem_Controller_Show extends Informationsystem_Controller_Show 
{ 
   protected function _groupCondition() 
   { 
      $oInformationsystem = $this->getEntity(); 
   
      if ($this->group) 
      { 
         // если ID группы не 0, т.е. не корневая группа 
         // получаем подгруппы 
         $aSubGroupsID = $this->fillInformationsystemGroup($oInformationsystem->id, $this->group); // добавляем текущую группу в массив 
         $aSubGroupsID[] = $this->group; 
         $this->informationsystemItems() 
            ->queryBuilder() 
            ->where('informationsystem_items.informationsystem_group_id', 'IN', $aSubGroupsID); // получаем все товары из подгрупп 
      } 
      else 
      { 
         $this->informationsystemItems() 
            ->queryBuilder() 
            ->where('informationsystem_items.informationsystem_group_id', 'NOT IN', Core_QueryBuilder::select('id')->from('informationsystem_groups')->where('informationsystem_id', '=', $oInformationsystem->id)->where('active', '=', 0)); 
      } 
      return $this; 
   } 
   protected $_aGroupTree = array(); 
   public function fillInformationsystemGroup($iInformationsystemId, $iInformationsystemGroupParentId = 0, $iLevel = 0) 
   { 
      $iInformationsystemId = intval($iInformationsystemId); 
      $iInformationsystemGroupParentId = intval($iInformationsystemGroupParentId); 
      $iLevel = intval($iLevel); 
      if ($iLevel == 0) 
      { 
         $aTmp = Core_QueryBuilder::select('id', 'parent_id') 
            ->from('informationsystem_groups') 
            ->where('informationsystem_id', '=', $iInformationsystemId) 
            ->where('deleted', '=', 0) 
            ->execute()->asAssoc()->result(); 
         foreach ($aTmp as $aGroup) 
         { 
            $this->_aGroupTree[$aGroup['parent_id']][] = $aGroup; 
         } 
      } 
      $aReturn = array(); 
      if (isset($this->_aGroupTree[$iInformationsystemGroupParentId])) 
      { 
         foreach ($this->_aGroupTree[$iInformationsystemGroupParentId] as $childrenGroup) 
         { 
            $aReturn[] = $childrenGroup['id']; 
            $aReturn = array_merge($aReturn, $this->fillInformationsystemGroup($iInformationsystemId, $childrenGroup['id'], $iLevel + 1)); 
         } 
      } 
      $iLevel == 0 && $this->_aGroupTree = array(); 
      return $aReturn; 
   } 
} 
$Informationsystem_Controller_Show = new My_Informationsystem_Controller_Show($oInformationsystem);
Меняем в ТДС макет для страницы с инфоэлементом
Core_Page::instance()->template(Core_Entity::factory('Template', 54)); // указываем id макета для Инфоэлемента

if (isset($Informationsystem_Controller_Show ->item) && $Informationsystem_Controller_Show ->item)
{
Core_Page::instance()->template(
Core_Entity::factory('Template', 8)
);
}