Guest User

Untitled

a guest
Sep 29th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.05 KB | None | 0 0
  1. #
  2. class SCIBlockElementHD {
  3.    
  4.     protected static $_method;
  5.     protected static $_db_res;
  6.     protected static $_GetElements;
  7.    
  8.     protected $_DeployPictures;
  9.     protected $_DeployLinks;
  10.     protected $_DeployFiles;
  11.    
  12.    
  13.     function __construct(
  14.             $Method,
  15.             $arOrder,
  16.             $arFilter,
  17.             $arNav,
  18.             $arSelectFields,
  19.             $arSelectProps
  20.         ) {
  21.        
  22.         $this->_method = $Method;
  23.        
  24.         $arSelect = $arSelectFields;
  25.        
  26.         if ($arSelectProps) {
  27.             foreach ($arSelectProps as $prop) {
  28.                 $arSelect[] = 'PROPERTY_'.$prop;
  29.             }
  30.         }
  31.        
  32.         $this->_db_res = CIBlockElement::GetList($arOrder, $arFilter, false, $arNav, $arSelect);
  33.        
  34.         # constucte closure
  35.         if ($Method == 'P') {
  36.             $this->_GetElements = function ($db_res, $DeployPictures, $DeployLinks, $DeployFiles) {
  37.                
  38.                 while($arElement = $db_res->GetNext()) {
  39.                    
  40.                     $arElement = $DeployPictures($arElement);
  41.                     $arElement = $DeployLinks($arElement);
  42.                     $arElement = $DeployFiles($arElement);
  43.                    
  44.                     $arElements[] = $arElement;
  45.                 }
  46.                 return $arElements;
  47.             };
  48.         } elseif ($Method == 'F') {
  49.             $this->_GetElements = function ($db_res, $DeployPictures, $DeployLinks, $DeployFiles) {
  50.                 while($arElement = $db_res->Fetch()) {
  51.                    
  52.                     $arElement = $DeployPictures($arElement);
  53.                     $arElement = $DeployLinks($arElement);
  54.                     $arElement = $DeployFiles($arElement);
  55.                    
  56.                     $arElements[] = $arElement;
  57.                 }
  58.                 return $arElements;
  59.             };
  60.         } else { # S
  61.             $this->_GetElements = function ($db_res, $DeployPictures, $DeployLinks, $DeployFiles) {
  62.                 while ($ob = $db_res->GetNextElement()) {
  63.                     $arElement = $ob->GetFields();
  64.                     $arElement['PROPERTIES'] = $ob->GetProperties();
  65.                    
  66.                     $arElement = $DeployPictures($arElement);
  67.                     $arElement = $DeployLinks($arElement);
  68.                     $arElement = $DeployFiles($arElement);
  69.                    
  70.                     $arElements[] = $arElement;
  71.                 }
  72.                 return $arElements;
  73.             };
  74.         }
  75.        
  76.        
  77.         $this->_DeployPictures = function ($element) {return $element;};
  78.         $this->_DeployLinks = function ($element) {return $element;};
  79.         $this->_DeployFiles = function ($element) {return $element;};
  80.        
  81.        
  82.         return $this;
  83.     }
  84.     #
  85.    
  86.     public function DeployPictures() {
  87.         $this->_DeployPictures = function ($element) {
  88.             if(isset($element['PREVIEW_PICTURE'])) {
  89.                 $element['PREVIEW_PICTURE'] = (0 < $element['PREVIEW_PICTURE'] ? CFile::GetFileArray($element['PREVIEW_PICTURE']) : false);
  90.             }
  91.             if(isset($element['DETAIL_PICTURE'])) {
  92.                 $element['DETAIL_PICTURE'] = (0 < $element['DETAIL_PICTURE'] ? CFile::GetFileArray($element['DETAIL_PICTURE']) : false);
  93.             }
  94.             return $element;
  95.         };
  96.     }
  97.     #
  98.    
  99.     public function GetNextElement() {
  100.        
  101.         if ($this->_method == 'S') {
  102.             if($ob = $this->_db_res->GetNextElement()) {
  103.                 $arElement = $ob->GetFields();
  104.                 $arElement['PROPERTIES'] = $ob->GetProperties();
  105.                 return $arElement;
  106.             }
  107.         } elseif ($this->_method == 'P') {
  108.             if($arElement = $this->_db_res->GetNext()) {
  109.                 return $arElement;
  110.             }
  111.         } else {
  112.             if($arElement = $this->_db_res->Fetch()) {
  113.                 return $arElement;
  114.             }
  115.         }
  116.     }
  117.     #
  118.    
  119.     public function GetElements() {
  120.         $clsrElements = $this->_GetElements;
  121.         $DeployPictures = $this->_DeployPictures;
  122.         $DeployLinks = $this->_DeployLinks;
  123.         $DeployFiles = $this->_DeployFiles;
  124.         return $clsrElements($this->_db_res, $DeployPictures, $DeployLinks, $DeployFiles);
  125.     }
  126.     #
  127.    
  128.    
  129.     public function GetElementsNonClsr() {
  130.        
  131.         if ($this->_method == 'S') {
  132.             while ($ob = $this->_db_res->GetNextElement()) {
  133.                 $arElement = $ob->GetFields();
  134.                 $arElement['PROPERTIES'] = $ob->GetProperties();
  135.                
  136.                
  137.                 if(isset($arElement['PREVIEW_PICTURE'])) {
  138.                     $arElement['PREVIEW_PICTURE'] = (0 < $arElement['PREVIEW_PICTURE'] ? CFile::GetFileArray($arElement['PREVIEW_PICTURE']) : false);
  139.                 }
  140.                 if(isset($arElement['DETAIL_PICTURE'])) {
  141.                     $arElement['DETAIL_PICTURE'] = (0 < $arElement['DETAIL_PICTURE'] ? CFile::GetFileArray($arElement['DETAIL_PICTURE']) : false);
  142.                 }
  143.                
  144.                 $arElements[] = $arElement;
  145.             }
  146.             return $arElements;
  147.         } elseif ($this->_method == 'P') {
  148.             while($arElement = $this->_db_res->GetNext()) {
  149.                
  150.                
  151.                 if(isset($arElement['PREVIEW_PICTURE'])) {
  152.                     $arElement['PREVIEW_PICTURE'] = (0 < $arElement['PREVIEW_PICTURE'] ? CFile::GetFileArray($arElement['PREVIEW_PICTURE']) : false);
  153.                 }
  154.                 if(isset($arElement['DETAIL_PICTURE'])) {
  155.                     $arElement['DETAIL_PICTURE'] = (0 < $arElement['DETAIL_PICTURE'] ? CFile::GetFileArray($arElement['DETAIL_PICTURE']) : false);
  156.                 }
  157.                
  158.                
  159.                 $arElements[] = $arElement;
  160.             }
  161.             return $arElements;
  162.         } else {
  163.             while($arElement = $this->_db_res->Fetch()) {
  164.                
  165.                 if(isset($arElement['PREVIEW_PICTURE'])) {
  166.                     $arElement['PREVIEW_PICTURE'] = (0 < $arElement['PREVIEW_PICTURE'] ? CFile::GetFileArray($arElement['PREVIEW_PICTURE']) : false);
  167.                 }
  168.                 if(isset($arElement['DETAIL_PICTURE'])) {
  169.                     $arElement['DETAIL_PICTURE'] = (0 < $arElement['DETAIL_PICTURE'] ? CFile::GetFileArray($arElement['DETAIL_PICTURE']) : false);
  170.                 }
  171.                
  172.                
  173.                 $arElements[] = $arElement;
  174.             }
  175.             return $arElements;
  176.         }
  177.     }
  178.     #
  179.    
  180. }
  181. #
Advertisement
Add Comment
Please, Sign In to add comment