L
L
lexstile2017-10-05 17:08:25
1C-Bitrix
lexstile, 2017-10-05 17:08:25

How to display the required number of infoblock elements using a getlist?

Records are taken from the infoblock - slides, now 10 are displayed. It is
necessary that you yourself be able to set the number of displayed elements on the page.
How to do? Optional in component call) Component
call:

<?$APPLICATION->IncludeComponent(
  "normik:slider",
  "protemplate",
  Array(
    "BACKGROUD_VIDEO" => "",
    "IBLOCK_TYPE" => "content",
    "IBLOCK_ID" => "32",
    "PARENT_SECTION" => "",
    "PARENT_SECTION_CODE" => "",
  )
);?>

componetn.php
<?
if(!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();
/** @var CBitrixComponent $this */
/** @var array $arParams */
/** @var array $arResult */
/** @var string $componentPath */
/** @var string $componentName */
/** @var string $componentTemplate */
/** @global CDatabase $DB */
/** @global CUser $USER */
/** @global CMain $APPLICATION */

/** @global CIntranetToolbar $INTRANET_TOOLBAR */
global $INTRANET_TOOLBAR;

CPageOption::SetOptionString("main", "nav_page_in_session", "N");

if(!isset($arParams["CACHE_TIME"]))
  $arParams["CACHE_TIME"] = 36000000;

$arParams["IBLOCK_TYPE"] = trim($arParams["IBLOCK_TYPE"]);
if(strlen($arParams["IBLOCK_TYPE"])<=0)
  $arParams["IBLOCK_TYPE"] = "news";
$arParams["IBLOCK_ID"] = trim($arParams["IBLOCK_ID"]);
$arParams["PARENT_SECTION"] = intval($arParams["PARENT_SECTION"]);
$arParams["INCLUDE_SUBSECTIONS"] = false;

$arrFilter = array();
$arNavigation = array();
$arResult = array();

$arParams["CACHE_FILTER"] = $arParams["CACHE_FILTER"]=="Y";
if(!$arParams["CACHE_FILTER"] && count($arrFilter)>0)
  $arParams["CACHE_TIME"] = 0;

$arParams["USE_PERMISSIONS"] = $arParams["USE_PERMISSIONS"]=="Y";
if(!is_array($arParams["GROUP_PERMISSIONS"]))
  $arParams["GROUP_PERMISSIONS"] = array(1);

$bUSER_HAVE_ACCESS = !$arParams["USE_PERMISSIONS"];
if($arParams["USE_PERMISSIONS"] && isset($GLOBALS["USER"]) && is_object($GLOBALS["USER"]))
{
  $arUserGroupArray = $USER->GetUserGroupArray();
  foreach($arParams["GROUP_PERMISSIONS"] as $PERM)
  {
    if(in_array($PERM, $arUserGroupArray))
    {
      $bUSER_HAVE_ACCESS = true;
      break;
    }
  }
}

if($this->StartResultCache(false, array(($arParams["CACHE_GROUPS"]==="N"? false: $USER->GetGroups()), $bUSER_HAVE_ACCESS, $arNavigation, $arrFilter)))
{
  if(!CModule::IncludeModule("iblock"))
  {
    $this->AbortResultCache();
    ShowError(GetMessage("IBLOCK_MODULE_NOT_INSTALLED"));
    return;
  }
  if(is_numeric($arParams["IBLOCK_ID"]))
  {
    $rsIBlock = CIBlock::GetList(array(), array(
      "ACTIVE" => "Y",
      "ID" => $arParams["IBLOCK_ID"],
    ));
  }
  else
  {
    $rsIBlock = CIBlock::GetList(array(), array(
      "ACTIVE" => "Y",
      "CODE" => $arParams["IBLOCK_ID"],
      "SITE_ID" => SITE_ID,
    ));
  }
  if($iBlock = $rsIBlock->GetNext())
  {
    //SELECT
    $arSelect = array(
      "ID",
      "IBLOCK_ID",
      "IBLOCK_SECTION_ID",
      "NAME",
      "ACTIVE_FROM",
      "DETAIL_PAGE_URL",
      "DETAIL_TEXT",
      "DETAIL_TEXT_TYPE",
      "PREVIEW_TEXT",
      "PREVIEW_TEXT_TYPE",
      "PREVIEW_PICTURE",
      "PROPERTY_IMG_XLARGE",
      "PROPERTY_IMG_LARGE",
      "PROPERTY_IMG_SMALL",
      "PROPERTY_IMG_XSMALL",
      "PROPERTY_IMG_XSMALL_LAND",
      "PROPERTY_URL",
      "PROPERTY_DESCRIPTION",
    );
    //WHERE
    $arFilter = array (
      "IBLOCK_ID" => $iBlock["ID"],
      "IBLOCK_LID" => SITE_ID,
      "ACTIVE" => "Y",
      "INCLUDE_SUBSECTIONS" => "Y",
    );

    $arParams["PARENT_SECTION"] = CIBlockFindTools::GetSectionID(
      $arParams["PARENT_SECTION"],
      $arParams["PARENT_SECTION_CODE"],
      array(
        "GLOBAL_ACTIVE" => "Y",
        "IBLOCK_ID" => $iBlock["ID"],
      )
    );

    if($arParams["PARENT_SECTION"]>0)
    {
      $arFilter["SECTION_ID"] = $arParams["PARENT_SECTION"];
    }

    $obParser = new CTextParser;
    $arResult["ITEMS"] = array();
    $arResult["ELEMENTS"] = array();
    $rsElement = CIBlockElement::GetList(array("SORT"=>"ASC"), $arFilter, false, array(), $arSelect);
    $rsElement->SetUrlTemplates($arParams["DETAIL_URL"], "", $arParams["IBLOCK_URL"]);
    while($obElement = $rsElement->GetNextElement())
    {
      $arItem = $obElement->GetFields();

      if($arParams["PREVIEW_TRUNCATE_LEN"] > 0)
        $arItem["PREVIEW_TEXT"] = $obParser->html_cut($arItem["PREVIEW_TEXT"], $arParams["PREVIEW_TRUNCATE_LEN"]);

      if(strlen($arItem["ACTIVE_FROM"])>0)
        $arItem["DISPLAY_ACTIVE_FROM"] = CIBlockFormatProperties::DateFormat($arParams["ACTIVE_DATE_FORMAT"], MakeTimeStamp($arItem["ACTIVE_FROM"], CSite::GetDateFormat()));
      else
        $arItem["DISPLAY_ACTIVE_FROM"] = "";

      $ipropValues = new \Bitrix\Iblock\InheritedProperty\ElementValues($arItem["IBLOCK_ID"], $arItem["ID"]);
      $arItem["IPROPERTY_VALUES"] = $ipropValues->getValues();

      if(isset($arItem["PREVIEW_PICTURE"]))
      {
        $arItem["PREVIEW_PICTURE"] = (0 < $arItem["PREVIEW_PICTURE"] ? CFile::GetFileArray($arItem["PREVIEW_PICTURE"]) : false);
        if ($arItem["PREVIEW_PICTURE"])
        {
          $arItem["PREVIEW_PICTURE"]["ALT"] = $arItem["IPROPERTY_VALUES"]["ELEMENT_PREVIEW_PICTURE_FILE_ALT"];
          if ($arItem["PREVIEW_PICTURE"]["ALT"] == "")
            $arItem["PREVIEW_PICTURE"]["ALT"] = $arItem["NAME"];
          $arItem["PREVIEW_PICTURE"]["TITLE"] = $arItem["IPROPERTY_VALUES"]["ELEMENT_PREVIEW_PICTURE_FILE_TITLE"];
          if ($arItem["PREVIEW_PICTURE"]["TITLE"] == "")
            $arItem["PREVIEW_PICTURE"]["TITLE"] = $arItem["NAME"];
        }
      }
      if(isset($arItem["DETAIL_PICTURE"]))
      {
        $arItem["DETAIL_PICTURE"] = (0 < $arItem["DETAIL_PICTURE"] ? CFile::GetFileArray($arItem["DETAIL_PICTURE"]) : false);
        if ($arItem["DETAIL_PICTURE"])
        {
          $arItem["DETAIL_PICTURE"]["ALT"] = $arItem["IPROPERTY_VALUES"]["ELEMENT_DETAIL_PICTURE_FILE_ALT"];
          if ($arItem["DETAIL_PICTURE"]["ALT"] == "")
            $arItem["DETAIL_PICTURE"]["ALT"] = $arItem["NAME"];
          $arItem["DETAIL_PICTURE"]["TITLE"] = $arItem["IPROPERTY_VALUES"]["ELEMENT_DETAIL_PICTURE_FILE_TITLE"];
          if ($arItem["DETAIL_PICTURE"]["TITLE"] == "")
            $arItem["DETAIL_PICTURE"]["TITLE"] = $arItem["NAME"];
        }
      }

      $arResult["ITEMS"][] = $arItem;
      $arResult["ELEMENTS"][] = $arItem["ID"];
    }
    $this->IncludeComponentTemplate();
  }
  else
  {
    $this->AbortResultCache();
    @define("ERROR_404", "Y");
    if($arParams["SET_STATUS_404"]==="Y")
      CHTTP::SetStatus("404 Not Found");
  }
}

?>

.parameters.php
<?
if (!defined("B_PROLOG_INCLUDED") || B_PROLOG_INCLUDED!==true) die();

if(!CModule::IncludeModule("iblock"))
  return;

$arTypesEx = CIBlockParameters::GetIBlockTypes(array("-"=>" "));

$arIBlocks=array();
$db_iblock = CIBlock::GetList(array("SORT"=>"ASC"), array("SITE_ID"=>$_REQUEST["site"], "TYPE" => ($arCurrentValues["IBLOCK_TYPE"]!="-"?$arCurrentValues["IBLOCK_TYPE"]:"")));
while($arRes = $db_iblock->Fetch())
  $arIBlocks[$arRes["ID"]] = $arRes["NAME"];

$arComponentParameters = array(
   "GROUPS" => array(
   ),
   "PARAMETERS" => array(
      "BACKGROUD_VIDEO" => array(
         "PARENT" => "BASE",
         "NAME" => 'Выберите фоновое видео',
         "TYPE" => "FILE",
         "FD_TARGET" => "F",
         "FD_EXT" => 'mp4',
         "FD_UPLOAD" => true,
         "FD_USE_MEDIALIB" => true,
         "FD_MEDIALIB_TYPES" => Array('video')
      ),
  "IBLOCK_TYPE" => array(
         "PARENT" => "BASE",
     "NAME" => "Тип информационного блока",
      "TYPE" => "LIST",
      "VALUES" => $arTypesEx,
      "DEFAULT" => "content",
      "REFRESH" => "Y",
    ),
    "IBLOCK_ID" => array(
      "PARENT" => "BASE",
      "NAME" => "Код информационного блока",
      "TYPE" => "LIST",
      "VALUES" => $arIBlocks,
      "DEFAULT" => '={$_REQUEST["ID"]}',
      "ADDITIONAL_VALUES" => "Y",
      "REFRESH" => "Y",
    ),
    "PARENT_SECTION" => array(
      "PARENT" => "ADDITIONAL_SETTINGS",
      "NAME" => "ID раздела",
      "TYPE" => "STRING",
      "DEFAULT" => '',
    ),
    "PARENT_SECTION_CODE" => array(
      "PARENT" => "ADDITIONAL_SETTINGS",
      "NAME" => "Код раздела",
      "TYPE" => "STRING",
      "DEFAULT" => '',
    ),
   )
);
?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2017-10-05
@lexstile

We have accumulated the news list component, but haven’t figured it out :)
Apparently you want the limit to be in CNT, then describe it in the parameters, and add the limits in the get list

$rsElement = CIBlockElement::GetList(array("SORT"=>"ASC"), $arFilter, false, array('nTopCount' => $arParams['CNT']), $arSelect);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question