Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added .gitignore
Empty file.
48 changes: 48 additions & 0 deletions CachedIBlock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace KDev;

use \Bitrix\Iblock\ElementTable;
use \Bitrix\Main\Data\Cache;

class CachedIBlock {

private $id;
private $lifetime;
private $initdir = false;
private $basedir = "cache";

public function __construct($livetime, $id, $initdir = false, $basedir = "cache") {
$this->lifetime = $livetime;
$this->id = $id;
}

// $query аналогичен запросу \Bitrix\Iblock\ElementTable::getList
// array(
// 'order' => array('SORT' => 'ASC'), // сортировка
// 'select' => array('ID', 'NAME', 'IBLOCK_ID', 'SORT', 'TAGS'), // выбираемые поля, без свойств. Свойства можно получать на старом ядре \CIBlockElement::getProperty
// 'filter' => array('IBLOCK_ID' => 4), // фильтр только по полям элемента, свойства (PROPERTY) использовать нельзя
// 'group' => array('TAGS'), // группировка по полю, order должен быть пустой
// 'limit' => 1000, // целое число, ограничение выбираемого кол-ва
// 'offset' => 0, // целое число, указывающее номер первого столбца в результате
// 'count_total' => 1 // дает возможность получить кол-во элементов через метод getCount()
// )
// )

public function getList($query) {
$cache = Cache::createInstance();
if ($cache->initCache($this->lifetime, $this->id, $initdir, $basedir)) {
$arResult = $cache->getVars();
} elseif ($cache->startDataCache()) {
$arResult = array();
if ($dbItems = ElementTable::getList($query)) {
$arResult = $dbItems->fetchAll();
} else {
$cache->abortDataCache();
}
$cache->endDataCache($arResult);
}
return $arResult;
}

}
Empty file added FETCH_HEAD
Empty file.
13 changes: 13 additions & 0 deletions getLastNews.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
$data = simplexml_load_file("https://lenta.ru/rss", 'SimpleXMLElement', LIBXML_NOCDATA);
if ($data) {

$i = 0;
while ($i < 5):
$item = $data->channel->item[$i];
echo PHP_EOL.$item->title . PHP_EOL.$item->link . PHP_EOL.trim($item->description) . PHP_EOL;
$i++;
endwhile;
echo PHP_EOL;

} else { echo "Parse error" . PHP_EOL; }