За последние 24 часа нас посетили 22903 программиста и 1264 робота. Сейчас ищет 751 программист ...

Помогите с кодом класса компонента в Битрикс

Тема в разделе "PHP для новичков", создана пользователем Ежи, 31 авг 2016.

Метки:
  1. Ежи

    Ежи Новичок

    С нами с:
    25 авг 2016
    Сообщения:
    4
    Симпатии:
    0
    Подскажите возможно ли такое - вырезать код свойства и параметры ЧПУ - is-from-to-or - из него же? И дополнение /apply/? Поиск по форуму и поисковикам ничего не дал... Колдую над классом компонента smart.filter, но безуспешно. На данный момент так - /catalog/sale_flats/filter/street-is-2-ya-sadovaya/apply/ А хочу чтоб было так - /catalog/sale_flats/filter/2-ya-sadovaya/

    В классе 5 функций которые за это отвечают, но не могу с ними разобраться...

    PHP:
    1. public function searchProperty($items, $lookupValue)
    2.     {
    3.         foreach($items as $itemId => $arItem)
    4.         {
    5.             if (!$arItem["PRICE"])
    6.             {
    7.                 $code = toLower($arItem["CODE"]);
    8.                 if ($lookupValue === $code)
    9.                     return $itemId;
    10.                 if ($lookupValue == intval($arItem["ID"]))
    11.                     return $itemId;
    12.             }
    13.         }
    14.         return false;
    15.     }
    16.  
    17.     public function searchValue($item, $lookupValue)
    18.     {
    19.         foreach($item as $itemId => $arValue)
    20.         {
    21.             if ($lookupValue === $arValue["URL_ID"])
    22.                 return $itemId;
    23.         }
    24.         return false;
    25.     }
    26.  
    27.  
    28.  
    29.     public function convertUrlToCheck($url)
    30.     {
    31.         $result = array();
    32.         $smartParts = explode("/", $url);
    33.         foreach ($smartParts as $smartPart)
    34.         {
    35.             $item = false;
    36.             $smartPart = preg_split("/-(from|to|is|or)-/", $smartPart, -1, PREG_SPLIT_DELIM_CAPTURE);
    37.             foreach ($smartPart as $i => $smartElement)
    38.             {
    39.                 if ($i == 0)
    40.                 {
    41.                     if (preg_match("/^price-(.+)$/", $smartElement, $match))
    42.                         $itemId = $this->searchPrice($this->arResult["ITEMS"], $match[1]);
    43.                     else
    44.                         $itemId = $this->searchProperty($this->arResult["ITEMS"], $smartElement);
    45.  
    46.                     if ($itemId)
    47.                         $item = &$this->arResult["ITEMS"][$itemId];
    48.                     else
    49.                         break;
    50.                 }
    51.                 elseif ($smartElement === "from")
    52.                 {
    53.                     $result[$item["VALUES"]["MIN"]["CONTROL_NAME"]] = $smartPart[$i+1];
    54.                 }
    55.                 elseif ($smartElement === "to")
    56.                 {
    57.                     $result[$item["VALUES"]["MAX"]["CONTROL_NAME"]] = $smartPart[$i+1];
    58.                 }
    59.                 elseif ($smartElement === "is" || $smartElement === "or")
    60.                 {
    61.                     $valueId = $this->searchValue($item["VALUES"], $smartPart[$i+1]);
    62.                     if (strlen($valueId))
    63.                     {
    64.                         $result[$item["VALUES"][$valueId]["CONTROL_NAME"]] = $item["VALUES"][$valueId]["HTML_VALUE"];
    65.                     }
    66.                 }
    67.  
    68.             }
    69.             unset($item);
    70.         }
    71.         return $result;
    72.     }
    73.  
    74.     public function makeSmartUrl($url, $apply, $checkedControlId = false)
    75.     {
    76.         $smartParts = array();
    77.  
    78.         if ($apply)
    79.         {
    80.             foreach($this->arResult["ITEMS"] as $PID => $arItem)
    81.             {  
    82.                 $smartPart = array();
    83.                 //Prices
    84.                 if ($arItem["PRICE"])
    85.                 {
    86.                     if ($arItem["VALUES"]["MIN"]["HTML_VALUE"] || $arItem["VALUES"]["MAX"]["HTML_VALUE"])
    87.                     {
    88.                         if ($arItem["VALUES"]["MIN"]["HTML_VALUE"])
    89.                             $smartPart["from"] = $arItem["VALUES"]["MIN"]["HTML_VALUE"];
    90.                         if ($arItem["VALUES"]["MAX"]["HTML_VALUE"])
    91.                             $smartPart["to"] = $arItem["VALUES"]["MAX"]["HTML_VALUE"];
    92.                     }
    93.                 }
    94.  
    95.                 if ($smartPart)
    96.                 {
    97.                     array_unshift($smartPart, toLower("price-".$arItem["CODE"]));
    98.                     $smartParts[] = $smartPart;
    99.                 }
    100.              
    101.             }
    102.  
    103.             foreach($this->arResult["ITEMS"] as $PID => $arItem)
    104.             {
    105.                 $smartPart = array();
    106.                 if ($arItem["PRICE"])
    107.                     continue;
    108.  
    109.                 //Numbers && calendar == ranges
    110.                 if (
    111.                     $arItem["PROPERTY_TYPE"] == "N"
    112.                     || $arItem["DISPLAY_TYPE"] == "U"
    113.                 )
    114.                 {
    115.                     if ($arItem["VALUES"]["MIN"]["HTML_VALUE"] || $arItem["VALUES"]["MAX"]["HTML_VALUE"])
    116.                     {
    117.                         if ($arItem["VALUES"]["MIN"]["HTML_VALUE"])
    118.                             $smartPart["from"] = $arItem["VALUES"]["MIN"]["HTML_VALUE"];
    119.                         if ($arItem["VALUES"]["MAX"]["HTML_VALUE"])
    120.                             $smartPart["to"] = $arItem["VALUES"]["MAX"]["HTML_VALUE"];
    121.                     }
    122.                 }
    123.                 else
    124.                 {
    125.                     foreach($arItem["VALUES"] as $key => $ar)
    126.                     {
    127.                         if (
    128.                             (
    129.                                 $ar["CHECKED"]
    130.                                 || $ar["CONTROL_ID"] === $checkedControlId
    131.                             )
    132.                             && strlen($ar["URL_ID"])
    133.                         )
    134.                         {
    135.                             $smartPart[] = $ar["URL_ID"];
    136.                         }
    137.                     }
    138.                 }
    139.  
    140.                 if ($smartPart)
    141.                 {
    142.                     if ($arItem["CODE"])
    143.                         array_unshift($smartPart, toLower($arItem["CODE"]));
    144.                     else
    145.                         array_unshift($smartPart, $arItem["ID"]);
    146.  
    147.                     $smartParts[] = $smartPart;
    148.                 }
    149.             }
    150.         }
    151.  
    152.         if (!$smartParts)
    153.             $smartParts[] = array("clear");
    154.  
    155.         return str_replace("#SMART_FILTER_PATH#", implode("/", $this->encodeSmartParts($smartParts)), $url);
    156.     }
    157.  
    158.     public function encodeSmartParts($smartParts)
    159.     {
    160.      
    161.         foreach ($smartParts as &$smartPart)
    162.         {
    163.             $urlPart = "";
    164.             foreach ($smartPart as $i => $smartElement)
    165.             {
    166.              
    167.                 if (!$urlPart){
    168.                     $urlPart .= urlencode($smartElement);
    169.                 }
    170.                 elseif ($i == 'from' || $i == 'to'){
    171.                     $urlPart .= urlencode('-'.$i.'-'.$smartElement);
    172.                 }
    173.                 elseif ($i == 1){
    174.                     $urlPart .= urlencode('-is-'.$smartElement);
    175.                 }  
    176.                 else{
    177.                     $urlPart .= urlencode('-or-'.$smartElement);
    178.                 }
    179.             }
    180.             $smartPart = $urlPart;
    181.         }
    182.         unset($smartPart);
    183.         return $smartParts;
    184.  
    185.     }
    Может быть кто-то более опытный подскажет?