/** * Finds the first available page for a row * * If the $row is a document, it will look for a document page first * before looking at list view pages. * * @param KDatabaseRowInterface $row * * @return int */ protected function _findPage(KDatabaseRowInterface $row) { $itemid = 0; $key = $row->docman_category_id ? $row->docman_category_id : $row->id; if ($row instanceof ComDocmanDatabaseRowDocument) { $document_pages = self::$_pages_model->reset()->view('document')->getList(); foreach ($document_pages as $page) { if (!empty($this->_state->page) && !in_array($page->id, (array) $this->_state->page)) { continue; } if (isset($page->query['slug']) && $row->slug === $page->query['slug']) { $itemid = $page->id; break; } } } if (!$itemid) { $category_pages = $this->_getCategoryPages(); foreach ($category_pages as $page) { if (!empty($this->_state->page) && !in_array($page->id, (array) $this->_state->page)) { continue; } if (in_array($key, $page->children)) { $itemid = $page->id; break; } } } if (!$itemid && $row instanceof ComDocmanDatabaseRowDocument) { $documents_pages = self::$_pages_model->reset()->view('filteredlist')->getList(); foreach ($documents_pages as $page) { if (!empty($this->_state->page) && !in_array($page->id, (array) $this->_state->page)) { continue; } $categories = (array) $page->params->get('category'); $created_by = (array) $page->params->get('created_by'); if ((empty($categories) || in_array($key, $categories)) && (empty($created_by) || in_array($row->created_by, $created_by)) ) { $itemid = $page->id; break; } } } if (!$itemid) { foreach ($this->_getCategoriesPages() as $page) { $itemid = $page->id; break; } } return $itemid; }