Cheshir Posted April 22, 2017 Report Share Posted April 22, 2017 Это код плагина Файлы подкатегорий Downloads {{$files = array(); $category = \IPS\downloads\Category::loadAndCheckPerms(\IPS\Request::i()->id); $cids = array_map(function($c) { return $c->_id; }, $category->children());}} {{$cheTable = new \IPS\Helpers\Table\Content('\IPS\downloads\File', $category->url(), array(\IPS\Db::i()->in('file_cat', $cids)));}} {{$cheTable->limit = \IPS\Settings::i()->che_count;}} {{if (count($cids))}} {{$files = iterator_to_array(\IPS\downloads\File::getItemsWithPermission(array(\IPS\Db::i()->in('file_cat', $cids)), 'file_submitted DESC' ));}} {{endif}} <div class='ipsBox ipsSpacer_top'> <div class='ipsPad_half'> {{if (count($files))}} <ul class='che_resub_cat' data-role='tableRows'> {$cheTable|raw} </ul> {{else}} <p class='ipsType_reset ipsType_light ipsPad'>{lang="che_no_files_in_subcat"}</p> {{endif}} </div> </div> $cids = array_map(function($c) { return $c->_id; }, $category->children()); - отвечает за выборку категорий из которых показывать файлы, но этот вариант работает таким образом, что показывает файлы только из прямой связи родитель - ребенок, т.е. если: Категория Подкатегория 1 файл 1 файл 2 Подкатегория 2 в Категория файлы будут отображаться из подкатегорий 1 и 2, Но, если файлы расположены глубже 2ого уровня, то файлы не отображаются, т.е.: Категория Подкатегория 1 ПодПодкатегория1 файл 1 файл 2 ПодПодкатегория2 При такой структуре файлы из подкатегорий будут показаны только в Подкатегория1, а в Категория файлы уже не отображаются. Собственно вопрос, каким образом рекурсивно получить все дочерние категории? Quote Link to comment Share on other sites More sharing options...
Cheshir Posted April 27, 2017 Author Report Share Posted April 27, 2017 Если кому-то интересно Спойлер public function categoryChild() { $cids = array(); $cids[] = $this->_id; if ($this->hasChildren()) { $allChildren = function($cat) use (&$allChildren) { $ids = array(); if ($cat->hasChildren()) { foreach ($cat->children() as $child) { $ids[] = $child->_id; if ($child->hasChildren()) { $ids = array_merge($ids, $allChildren($child)); } } } return $ids; }; $cids = array_merge($cids, $allChildren($this)); } return $cids; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.