FOSSology  3.2.0rc1
Open Source License Compliance by Open Source Software
FolderNav.php
1 <?php
2 /***********************************************************
3  * Copyright (C) 2015 Siemens AG
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License
7  * version 2 as published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  ***********************************************************/
18 
19 namespace Fossology\Lib\UI;
20 
23 
24 class FolderNav
25 {
27  private $dbManager;
29  private $folderDao;
30 
31  public function __construct(DbManager $dbManager, FolderDao $folderDao)
32  {
33  $this->dbManager = $dbManager;
34  $this->folderDao = $folderDao;
35  }
36 
41  public function showFolderTree($parentFolder)
42  {
43  $uri = Traceback_uri();
44  $sql = $this->folderDao->getFolderTreeCte($parentFolder)
45  ." SELECT folder_pk, folder_name, folder_desc, depth, name_path FROM folder_tree ORDER BY name_path";
46  $stmt = __METHOD__;
47  $this->dbManager->prepare($stmt, $sql);
48  $res = $this->dbManager->execute($stmt,array($parentFolder));
49  $out = '';
50  $lastDepth = -1;
51  while ($row = $this->dbManager->fetchArray($res)) {
52  for (; $row['depth']<$lastDepth; $lastDepth--) {
53  $out .= '</li></ul>';
54  }
55  if ($row['depth']==$lastDepth) {
56  $out .= "</li>\n<li>";
57  }
58  if ($row['depth']==0) {
59  $out .= '<ul id="tree"><li>';
60  $lastDepth++;
61  }
62  for (;$row['depth']>$lastDepth;$lastDepth++) {
63  $out .= '<ul><li>';
64  }
65  $out .= $this->getFormattedItem($row, $uri);
66  }
67  for (; - 1<$lastDepth;$lastDepth--) {
68  $out .= '</li></ul>';
69  }
70  return $out;
71  }
72 
73  protected function getFormattedItem($row,$uri)
74  {
75  $title = empty($row['folder_desc']) ? '' : ' title="' . htmlspecialchars($row['folder_desc']) . '"';
76  return '<a'.$title.
77  ' href="'.$uri.'?mod=browse&folder='.$row['folder_pk'].'"'.
78  ' class="clickable-folder" data-folder="'.$row['folder_pk'].'"'.
79  '>'.htmlentities($row['folder_name']).'</a>';
80  }
81 }
Traceback_uri()
Get the URI without query to this location.
showFolderTree($parentFolder)
Definition: FolderNav.php:41
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:28