Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #
- class SCIBlockElementHD {
- protected static $_method;
- protected static $_db_res;
- protected static $_GetElements;
- protected $_DeployPictures;
- protected $_DeployLinks;
- protected $_DeployFiles;
- function __construct(
- $Method,
- $arOrder,
- $arFilter,
- $arNav,
- $arSelectFields,
- $arSelectProps
- ) {
- $this->_method = $Method;
- $arSelect = $arSelectFields;
- if ($arSelectProps) {
- foreach ($arSelectProps as $prop) {
- $arSelect[] = 'PROPERTY_'.$prop;
- }
- }
- $this->_db_res = CIBlockElement::GetList($arOrder, $arFilter, false, $arNav, $arSelect);
- # constucte closure
- if ($Method == 'P') {
- $this->_GetElements = function ($db_res, $DeployPictures, $DeployLinks, $DeployFiles) {
- while($arElement = $db_res->GetNext()) {
- $arElement = $DeployPictures($arElement);
- $arElement = $DeployLinks($arElement);
- $arElement = $DeployFiles($arElement);
- $arElements[] = $arElement;
- }
- return $arElements;
- };
- } elseif ($Method == 'F') {
- $this->_GetElements = function ($db_res, $DeployPictures, $DeployLinks, $DeployFiles) {
- while($arElement = $db_res->Fetch()) {
- $arElement = $DeployPictures($arElement);
- $arElement = $DeployLinks($arElement);
- $arElement = $DeployFiles($arElement);
- $arElements[] = $arElement;
- }
- return $arElements;
- };
- } else { # S
- $this->_GetElements = function ($db_res, $DeployPictures, $DeployLinks, $DeployFiles) {
- while ($ob = $db_res->GetNextElement()) {
- $arElement = $ob->GetFields();
- $arElement['PROPERTIES'] = $ob->GetProperties();
- $arElement = $DeployPictures($arElement);
- $arElement = $DeployLinks($arElement);
- $arElement = $DeployFiles($arElement);
- $arElements[] = $arElement;
- }
- return $arElements;
- };
- }
- $this->_DeployPictures = function ($element) {return $element;};
- $this->_DeployLinks = function ($element) {return $element;};
- $this->_DeployFiles = function ($element) {return $element;};
- return $this;
- }
- #
- public function DeployPictures() {
- $this->_DeployPictures = function ($element) {
- if(isset($element['PREVIEW_PICTURE'])) {
- $element['PREVIEW_PICTURE'] = (0 < $element['PREVIEW_PICTURE'] ? CFile::GetFileArray($element['PREVIEW_PICTURE']) : false);
- }
- if(isset($element['DETAIL_PICTURE'])) {
- $element['DETAIL_PICTURE'] = (0 < $element['DETAIL_PICTURE'] ? CFile::GetFileArray($element['DETAIL_PICTURE']) : false);
- }
- return $element;
- };
- }
- #
- public function GetNextElement() {
- if ($this->_method == 'S') {
- if($ob = $this->_db_res->GetNextElement()) {
- $arElement = $ob->GetFields();
- $arElement['PROPERTIES'] = $ob->GetProperties();
- return $arElement;
- }
- } elseif ($this->_method == 'P') {
- if($arElement = $this->_db_res->GetNext()) {
- return $arElement;
- }
- } else {
- if($arElement = $this->_db_res->Fetch()) {
- return $arElement;
- }
- }
- }
- #
- public function GetElements() {
- $clsrElements = $this->_GetElements;
- $DeployPictures = $this->_DeployPictures;
- $DeployLinks = $this->_DeployLinks;
- $DeployFiles = $this->_DeployFiles;
- return $clsrElements($this->_db_res, $DeployPictures, $DeployLinks, $DeployFiles);
- }
- #
- public function GetElementsNonClsr() {
- if ($this->_method == 'S') {
- while ($ob = $this->_db_res->GetNextElement()) {
- $arElement = $ob->GetFields();
- $arElement['PROPERTIES'] = $ob->GetProperties();
- if(isset($arElement['PREVIEW_PICTURE'])) {
- $arElement['PREVIEW_PICTURE'] = (0 < $arElement['PREVIEW_PICTURE'] ? CFile::GetFileArray($arElement['PREVIEW_PICTURE']) : false);
- }
- if(isset($arElement['DETAIL_PICTURE'])) {
- $arElement['DETAIL_PICTURE'] = (0 < $arElement['DETAIL_PICTURE'] ? CFile::GetFileArray($arElement['DETAIL_PICTURE']) : false);
- }
- $arElements[] = $arElement;
- }
- return $arElements;
- } elseif ($this->_method == 'P') {
- while($arElement = $this->_db_res->GetNext()) {
- if(isset($arElement['PREVIEW_PICTURE'])) {
- $arElement['PREVIEW_PICTURE'] = (0 < $arElement['PREVIEW_PICTURE'] ? CFile::GetFileArray($arElement['PREVIEW_PICTURE']) : false);
- }
- if(isset($arElement['DETAIL_PICTURE'])) {
- $arElement['DETAIL_PICTURE'] = (0 < $arElement['DETAIL_PICTURE'] ? CFile::GetFileArray($arElement['DETAIL_PICTURE']) : false);
- }
- $arElements[] = $arElement;
- }
- return $arElements;
- } else {
- while($arElement = $this->_db_res->Fetch()) {
- if(isset($arElement['PREVIEW_PICTURE'])) {
- $arElement['PREVIEW_PICTURE'] = (0 < $arElement['PREVIEW_PICTURE'] ? CFile::GetFileArray($arElement['PREVIEW_PICTURE']) : false);
- }
- if(isset($arElement['DETAIL_PICTURE'])) {
- $arElement['DETAIL_PICTURE'] = (0 < $arElement['DETAIL_PICTURE'] ? CFile::GetFileArray($arElement['DETAIL_PICTURE']) : false);
- }
- $arElements[] = $arElement;
- }
- return $arElements;
- }
- }
- #
- }
- #
Advertisement
Add Comment
Please, Sign In to add comment