Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
sectionpath.php
1<?php
8
9class SectionPath extends Base
10{
11 protected $dbPath = null;
12
16 public function __construct($id)
17 {
18 parent::__construct($id);
19 $this->fieldMap = array(
20 "name" => "NAME",
21 "previewtext" => "DESCRIPTION",
22 "detailtext" => "DESCRIPTION",
23 "code" => "CODE",
24 //not accessible from template engine
25 "ID" => "ID",
26 "IBLOCK_ID" => "IBLOCK_ID",
27 "IBLOCK_SECTION_ID" => "IBLOCK_SECTION_ID",
28 );
29 }
30
37 public function loadFromDatabase()
38 {
39 if (!isset($this->fields))
40 {
41 //From down to up
42 $select = array_values($this->fieldMap);
43 $this->dbPath = array();
44 $id = $this->id;
45 while ($id > 0)
46 {
47 $sectionList = \Bitrix\Iblock\SectionTable::getList(array(
48 "select" => $select,
49 "filter" => array("=ID" => $id),
50 ));
51 $section = $sectionList->fetch();
52 if ($section)
53 $this->dbPath[] = $section;
54 else
55 break;
56 $id = $section["IBLOCK_SECTION_ID"];
57 }
58 //Reversed from up to down
59 //and laid by fields
60 $this->fields = array();
61 for($i = count($this->dbPath)-1; $i >= 0; $i--)
62 {
63 foreach($this->dbPath[$i] as $fieldName => $fieldValue)
64 {
65 $this->fields[$fieldName][] = $fieldValue;
66 }
67 }
68 $this->loadProperty();
69 }
70 return is_array($this->fields);
71 }
72
78 protected function loadProperty()
79 {
81 global $USER_FIELD_MANAGER;
82
83 foreach ($this->fields["ID"] as $i => $sectionId)
84 {
85 $userFields = $USER_FIELD_MANAGER->getUserFields(
86 "IBLOCK_".$this->fields["IBLOCK_ID"][$i]."_SECTION",
87 $sectionId
88 );
89 foreach ($userFields as $id => $uf)
90 {
91 //TODO $uf["USER_TYPE"]["BASE_TYPE"] == "enum"
92 $propertyCode = $id;
93 $fieldCode = "property.".mb_strtolower(mb_substr($id, 3));
94 $this->fieldMap[$fieldCode] = $propertyCode;
95 if (is_array($uf["VALUE"]))
96 {
97 foreach ($uf["VALUE"] as $value)
98 $this->fields[$propertyCode][] = $value;
99 }
100 else
101 {
102 $this->fields[$propertyCode][] = $uf["VALUE"];
103 }
104 }
105 }
106 }
107}