8 namespace Fossology\Lib\Dao;
19 function __construct(
DbManager $dbManager)
42 public function GetResults($Item, $Filename, $Upload, $tag, $Page, $Limit, $SizeMin, $SizeMax, $searchtype, $License, $Copyright, $uploadDao, $groupID)
44 $UploadtreeRecs = array();
45 $totalUploadtreeRecs = array();
46 $totalUploadtreeRecsCount = 0;
47 $NeedTagfileTable =
true;
48 $NeedTaguploadtreeTable =
true;
52 $row = $uploadDao->getUploadEntry($Item);
54 $text = _(
"Invalid URL, nonexistant item");
55 return "<h2>$text $Item</h2>";
59 $upload_pk = $row[
"upload_fk"];
62 if (!$uploadDao->isAccessible($upload_pk, $groupID)) {
63 return array($UploadtreeRecs, $totalUploadtreeRecsCount);
67 $SQLBase =
"SELECT DISTINCT uploadtree_pk, parent, upload_fk, uploadtree.pfile_fk, ufile_mode, ufile_name FROM uploadtree";
69 $SQLOrderLimitOffset =
"";
71 if ($searchtype !=
"directory") {
72 if (!empty($License)) {
73 $SQLWhere .=
", ( SELECT license_ref.rf_shortname, license_file.rf_fk, license_file.pfile_fk
74 FROM license_file JOIN license_ref ON license_file.rf_fk = license_ref.rf_pk) AS pfile_ref";
76 if (!empty($Copyright)) {
77 $SQLWhere .=
",copyright";
83 $stmt = __METHOD__.$Filename;
84 $sql =
"select tag_pk from tag where tag ilike '" . pg_escape_string($tag) .
"'";
85 $tag_pk_array = $this->
dbManager->getRows($sql, [], $stmt);
86 if (empty($tag_pk_array)) {
88 return array($UploadtreeRecs, $totalUploadtreeRecsCount);
92 $sql =
"select tag_file_pk from tag_file limit 1";
93 $result = $this->
dbManager->getRows($sql, [], $stmt);
96 $NeedTagfileTable =
false;
98 $SQLWhere .=
", tag_file";
102 $sql =
"select tag_uploadtree_pk from tag_uploadtree limit 1";
103 $result = $this->
dbManager->getRows($sql, [], $stmt);
104 if (empty($result)) {
106 $NeedTaguploadtreeTable =
false;
108 $SQLWhere .=
", tag_uploadtree";
111 if (!$NeedTagfileTable && !$NeedTaguploadtreeTable) {
112 $SQLWhere .=
", tag_file, tag_uploadtree";
117 if (!empty($SizeMin) or !empty($SizeMax)) {
118 $SQLWhere .=
", pfile where pfile_pk=uploadtree.pfile_fk ";
121 $SQLWhere .=
" where ";
132 foreach ($tag_pk_array as $tagRec) {
137 $tag_pk = $tagRec[
'tag_pk'];
138 if ($NeedTagfileTable && $NeedTaguploadtreeTable) {
139 $SQLWhere .=
"(uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk=$tag_pk) or (uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk=$tag_pk) ";
140 }
else if ($NeedTaguploadtreeTable) {
141 $SQLWhere .=
"uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk=$tag_pk";
142 }
else if ($NeedTagfileTable) {
143 $SQLWhere .=
"uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk=$tag_pk";
145 $SQLWhere .=
"(uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk=$tag_pk) or (uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk=$tag_pk) ";
158 $SQLWhere .=
" ufile_name ilike '" . $Filename .
"'";
166 $SQLWhere .=
" upload_fk = " . $Upload .
"";
170 if (!empty($SizeMin) && is_numeric($SizeMin)) {
174 $SQLWhere .=
" pfile.pfile_size >= " . $SizeMin;
178 if (!empty($SizeMax) && is_numeric($SizeMax)) {
182 $SQLWhere .=
" pfile.pfile_size <= " . $SizeMax;
190 $SQLWhere .=
" upload_fk = $upload_pk AND lft >= $lft AND rgt <= $rgt";
195 if ($searchtype ==
'containers') {
199 $SQLWhere .=
" ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0)";
202 $dir_ufile_mode = 536888320;
203 if ($searchtype ==
'directory') {
207 $SQLWhere .=
" ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0) AND (ufile_mode != $dir_ufile_mode) and pfile_fk != 0";
212 if ($searchtype !=
"directory") {
213 if (!empty($License)) {
218 $SQLWhere .=
" uploadtree.pfile_fk=pfile_ref.pfile_fk and pfile_ref.rf_shortname ilike '" .
219 pg_escape_string($License) .
"'";
222 if (!empty($Copyright)) {
226 $SQLWhere .=
" uploadtree.pfile_fk=copyright.pfile_fk and copyright.content ilike '%" .
227 pg_escape_string($Copyright) .
"%'";
231 $Offset = $Page * $Limit;
233 $SQLOrderLimitOffset =
" ORDER BY ufile_name, uploadtree.pfile_fk LIMIT $Limit OFFSET $Offset";
234 $PaginatedSQL = $SQLBase . $SQLWhere . $SQLOrderLimitOffset;
236 $CountSQL =
"SELECT COUNT(DISTINCT uploadtree_pk) FROM uploadtree" . $SQLWhere;
238 $stmt = __METHOD__ .
"_count";
239 $countRow = $this->
dbManager->getSingleRow($CountSQL, [], $stmt);
240 $totalUploadtreeRecsCount = $countRow ? reset($countRow) : 0;
242 $stmt = __METHOD__ .
"_paginated";
243 $rows = $this->
dbManager->getRows($PaginatedSQL, [], $stmt);
245 foreach ($rows as $row) {
246 if (!$uploadDao->isAccessible($row[
'upload_fk'], $groupID)) {
249 $totalUploadtreeRecs[] = $row;
252 return array($totalUploadtreeRecs, $totalUploadtreeRecsCount);
GetResults($Item, $Filename, $Upload, $tag, $Page, $Limit, $SizeMin, $SizeMax, $searchtype, $License, $Copyright, $uploadDao, $groupID)
Given a filename, return all uploadtree.
fo_dbManager * dbManager
fo_dbManager object