1: <?php
2:
3: 4: 5: 6: 7: 8: 9: 10: 11:
12:
13:
14: $client = cRegistry::getClientId();
15: $lang = cRegistry::getLanguageId();
16: $idart = cRegistry::getArticleId();
17:
18:
19: $artLang = new cApiArticleLanguage();
20: $artLang->loadByArticleAndLanguageId($idart, $lang);
21:
22: $content = $artLang->getContent('CMS_TEXT', 1);
23: $level = $artLang->getContent('CMS_TEXT', 2);
24: $article = $artLang->getContent('CMS_TEXT', 3);
25:
26:
27: $tpl = cSmartyFrontend::getInstance();
28: $tpl->assign('isBackendEditMode', cRegistry::isBackendEditMode());
29:
30:
31: $tpl->assign('trans', [
32: 'headline' => mi18n("HEADLINE"),
33: 'categoryLabel' => mi18n("CATEGORY_LABEL"),
34: 'levelLabel' => mi18n("LEVEL_LABEL"),
35: 'articleLabel' => mi18n("ARTICLE_LABEL"),
36: 'articleHintLabel' => mi18n("ARTICLE_HINT_LABEL"),
37: 'categoryHintLabel' => mi18n("GATEGORY_HINT_LABEL"),
38: 'levelHintLabel' => mi18n("LEVEL_HINT_LABEL")
39: ]);
40:
41:
42: $tpl->assign('category', "CMS_TEXT[1]");
43: $tpl->assign('level', "CMS_TEXT[2]");
44: $tpl->assign('article', "CMS_TEXT[3]");
45: $tpl->assign('first', false);
46:
47:
48: if (false === is_numeric($content) || false === is_numeric($level)) {
49: $tpl->assign('error', mi18n("NOT_NUMERIC_VALUE"));
50: } else if ($article != 0 && $article != 1) {
51: $tpl->assign('error', mi18n("NOT_ZERO_OR_ONE"));
52: } else {
53:
54: $categoryHelper = cCategoryHelper::getInstance();
55: $categoryHelper->setAuth(cRegistry::getAuth());
56: $tree = $categoryHelper->getSubCategories($content, $level);
57: if (1 == $article) {
58: $tree = addArticlesToTree($tree);
59: }
60: $tpl->assign('tree', $tree);
61: }
62:
63: $tpl->display('get.tpl');
64:
65: 66: 67: 68: 69: 70: 71:
72: function addArticlesToTree(array $tree) {
73: $startIdArtLang = getStartIdArtLang();
74:
75: foreach ($tree as $key => $wrapper) {
76: $tree[$key]['articles'] = getArticlesFromCategory($wrapper['idcat'], $startIdArtLang);
77: $tree[$key]['subcats'] = addArticlesToTree($tree[$key]['subcats']);
78: }
79:
80: return $tree;
81: }
82:
83: 84: 85: 86: 87: 88: 89:
90: function getStartIdArtLang() {
91: $cfg = cRegistry::getConfig();
92: $db = cRegistry::getDb();
93:
94:
95: $ret = $db->query('-- getStartIdArtLang()
96: SELECT
97: startidartlang
98: FROM
99: `' . $cfg['tab']['cat_lang'] . '`
100: WHERE
101: visible = 1
102: AND public = 1
103: ;');
104:
105: $result = [];
106: while ($db->nextRecord()) {
107: $result[] = $db->f('startidartlang');
108: }
109:
110: return $result;
111: }
112:
113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125:
126: function getArticlesFromCategory($idcat, array $excludedIdArtLangs = []) {
127: $cfg = cRegistry::getConfig();
128: $db = cRegistry::getDb();
129: $idlang = cRegistry::getLanguageId();
130:
131: $ret = $db->query('-- getArticlesFromCategory()
132: SELECT
133: art_lang.idartlang
134: FROM
135: `' . $cfg['tab']['art_lang'] . '` AS art_lang,
136: `' . $cfg['tab']['cat_art'] . '` AS cat_art
137: WHERE
138: art_lang.idart = cat_art.idart
139: AND art_lang.idlang = ' . cSecurity::toInteger($idlang) . '
140: AND art_lang.online = 1
141: AND art_lang.searchable = 1
142: AND cat_art.idcat = ' . cSecurity::toInteger($idcat) . '
143: ;');
144:
145: if (false === $ret) {
146: return [];
147: }
148:
149: $result = [];
150: while ($db->nextRecord()) {
151:
152: if (in_array($db->f('idartlang'), $excludedIdArtLangs)) {
153: continue;
154: }
155:
156:
157: $result[] = new cApiArticleLanguage($db->f('idartlang'));
158: }
159:
160: return $result;
161: }
162:
163: ?>