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);
68 $SQL =
"SELECT DISTINCT uploadtree_pk, parent, upload_fk, uploadtree.pfile_fk, ufile_mode, ufile_name FROM uploadtree";
70 if ($searchtype !=
"directory") {
71 if (!empty($License)) {
72 $SQL .=
", ( SELECT license_ref.rf_shortname, license_file.rf_fk, license_file.pfile_fk
73 FROM license_file JOIN license_ref ON license_file.rf_fk = license_ref.rf_pk) AS pfile_ref";
75 if (!empty($Copyright)) {
82 $stmt = __METHOD__.$Filename;
83 $sql =
"select tag_pk from tag where tag ilike '" . pg_escape_string($tag) .
"'";
84 $tag_pk_array = $this->
dbManager->getRows($sql, [], $stmt);
85 if (empty($tag_pk_array)) {
87 return array($UploadtreeRecs, $totalUploadtreeRecsCount);
91 $sql =
"select tag_file_pk from tag_file limit 1";
92 $result = $this->
dbManager->getRows($sql, [], $stmt);
95 $NeedTagfileTable =
false;
101 $sql =
"select tag_uploadtree_pk from tag_uploadtree limit 1";
102 $result = $this->
dbManager->getRows($sql, [], $stmt);
103 if (empty($result)) {
105 $NeedTaguploadtreeTable =
false;
107 $SQL .=
", tag_uploadtree";
110 if (!$NeedTagfileTable && !$NeedTaguploadtreeTable) {
111 $SQL .=
", tag_file, tag_uploadtree";
116 if (!empty($SizeMin) or !empty($SizeMax)) {
117 $SQL .=
", pfile where pfile_pk=uploadtree.pfile_fk ";
131 foreach ($tag_pk_array as $tagRec) {
136 $tag_pk = $tagRec[
'tag_pk'];
137 if ($NeedTagfileTable && $NeedTaguploadtreeTable) {
138 $SQL .=
"(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) ";
139 }
else if ($NeedTaguploadtreeTable) {
140 $SQL .=
"uploadtree_pk=tag_uploadtree.uploadtree_fk and tag_uploadtree.tag_fk=$tag_pk";
141 }
else if ($NeedTagfileTable) {
142 $SQL .=
"uploadtree.pfile_fk=tag_file.pfile_fk and tag_file.tag_fk=$tag_pk";
144 $SQL .=
"(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) ";
157 $SQL .=
" ufile_name ilike '" . $Filename .
"'";
165 $SQL .=
" upload_fk = " . $Upload .
"";
169 if (!empty($SizeMin) && is_numeric($SizeMin)) {
173 $SQL .=
" pfile.pfile_size >= " . $SizeMin;
177 if (!empty($SizeMax) && is_numeric($SizeMax)) {
181 $SQL .=
" pfile.pfile_size <= " . $SizeMax;
189 $SQL .=
" upload_fk = $upload_pk AND lft >= $lft AND rgt <= $rgt";
194 if ($searchtype ==
'containers') {
198 $SQL .=
" ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0)";
201 $dir_ufile_mode = 536888320;
202 if ($searchtype ==
'directory') {
206 $SQL .=
" ((ufile_mode & (1<<29))!=0) AND ((ufile_mode & (1<<28))=0) AND (ufile_mode != $dir_ufile_mode) and pfile_fk != 0";
211 if ($searchtype !=
"directory") {
212 if (!empty($License)) {
217 $SQL .=
" uploadtree.pfile_fk=pfile_ref.pfile_fk and pfile_ref.rf_shortname ilike '" .
218 pg_escape_string($License) .
"'";
221 if (!empty($Copyright)) {
225 $SQL .=
" uploadtree.pfile_fk=copyright.pfile_fk and copyright.content ilike '%" .
226 pg_escape_string($Copyright) .
"%'";
230 $Offset = $Page * $Limit;
231 $stmt = __METHOD__.$Filename;
232 $SQL .=
" ORDER BY ufile_name, uploadtree.pfile_fk";
233 $rows = $this->
dbManager->getRows($SQL, [], $stmt);
235 foreach ($rows as $row) {
236 if (!$uploadDao->isAccessible($row[
'upload_fk'], $groupID)) {
239 $totalUploadtreeRecs[] = $row;
242 $UploadtreeRecs = array_slice($totalUploadtreeRecs, $Offset, $Limit);
243 $totalUploadtreeRecsCount =
sizeof($totalUploadtreeRecs);
244 return array($UploadtreeRecs, $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