예제 #1
0
    /**
     * @param $pages int|array Page IDs
     */
    protected function _setPageState($pages)
    {
        if ($pages === 'all') {
            $pages = array_keys($this->_getPages());
        }

        // Get rid of KConfig
        $pages      = (array) KConfig::unbox($pages);
        $conditions = array();

        if ($pages)
        {
            $all_pages = $this->_getPages();
            $categories = array();

            foreach ($pages as $id)
            {
                if (!isset($all_pages[$id])) {
                    continue;
                }

                $page = $all_pages[$id];

                if ($page->query['view'] === 'list')
                {
                    // If we have a category view to the root category everything is reachable
                    if (empty($page->query['slug']))
                    {
                        $categories = array();
                        $conditions = array();
                        break;
                    }

                    $categories = array_merge($categories, $page->children);
                }
                elseif ($page->query['view'] === 'filteredlist')
                {
                    $conditions[] = array('documents', array(
                        'created_by' => $page->params->get('created_by'),
                        'categories' => $page->params->get('category')
                    ));
                }
            }

            if ($categories) {
                $conditions[] = array('categories', array_unique($categories));
            }
        }

        parent::set('page', $pages);
        parent::set('page_conditions', $conditions);
    }