FOSSology  4.4.0
Open Source License Compliance by Open Source Software
FolderNav.php
1 <?php
2 /*
3  SPDX-FileCopyrightText: © 2015 Siemens AG
4 
5  SPDX-License-Identifier: GPL-2.0-only
6 */
7 
8 namespace Fossology\Lib\UI;
9 
12 
13 class FolderNav
14 {
16  private $dbManager;
18  private $folderDao;
19 
20  public function __construct(DbManager $dbManager, FolderDao $folderDao)
21  {
22  $this->dbManager = $dbManager;
23  $this->folderDao = $folderDao;
24  }
25 
30  public function showFolderTree($parentFolder)
31  {
32  $uri = Traceback_uri();
33  $sql = $this->folderDao->getFolderTreeCte($parentFolder)
34  ." SELECT folder_pk, folder_name, folder_desc, depth, name_path FROM folder_tree ORDER BY name_path";
35  $stmt = __METHOD__;
36  $this->dbManager->prepare($stmt, $sql);
37  $res = $this->dbManager->execute($stmt,array($parentFolder));
38  $out = '';
39  $lastDepth = -1;
40  while ($row = $this->dbManager->fetchArray($res)) {
41  for (; $row['depth']<$lastDepth; $lastDepth--) {
42  $out .= '</li></ul>';
43  }
44  if ($row['depth']==$lastDepth) {
45  $out .= "</li>\n<li>";
46  }
47  if ($row['depth']==0) {
48  $out .= '<ul id="tree"><li>';
49  $lastDepth++;
50  }
51  for (;$row['depth']>$lastDepth;$lastDepth++) {
52  $out .= '<ul><li>';
53  }
54  $out .= $this->getFormattedItem($row, $uri);
55  }
56  for (; - 1<$lastDepth;$lastDepth--) {
57  $out .= '</li></ul>';
58  }
59  return $out;
60  }
61 
62  protected function getFormattedItem($row,$uri)
63  {
64  $title = empty($row['folder_desc']) ? '' : ' title="' . htmlspecialchars($row['folder_desc']) . '"';
65  return '<a'.$title.
66  ' href="'.$uri.'?mod=browse&folder='.$row['folder_pk'].'"'.
67  ' class="clickable-folder text-info stretched-link" style="padding:2px;" data-folder="'.$row['folder_pk'].'"'.
68  '>'.htmlentities($row['folder_name']).'</a>';
69  }
70 }
showFolderTree($parentFolder)
Definition: FolderNav.php:30
Traceback_uri()
Get the URI without query to this location.
Definition: common-parm.php:97
fo_dbManager * dbManager
fo_dbManager object
Definition: process.c:16