13 namespace Fossology\UI\Api\Controllers;
20 use Psr\Http\Message\ServerRequestInterface;
29 private $searchHelperDao;
42 $this->searchHelperDao = $this->container->get(
'dao.searchhelperdao');
45 if ($apiVersion == ApiVersion::V2) {
46 $query = $request->getQueryParams();
47 $searchType = $query[
"searchType"] ??
"";
48 $filename = $query[
"filename"] ??
"";
49 $tag = $query[
"tag"] ??
"";
50 $filesizeMin = $query[
"filesizemin"] ??
"";
51 $filesizeMax = $query[
"filesizemax"] ??
"";
52 $license = $query[
"license"] ??
"";
53 $copyright = $query[
"copyright"] ??
"";
54 $uploadId = $query[
"uploadId"] ??
"";
55 $page = $query[
"page"] ??
"";
56 $limit = $query[
"limit"] ??
"";
58 $searchType = $request->getHeaderLine(
"searchType");
59 $filename = $request->getHeaderLine(
"filename");
60 $tag = $request->getHeaderLine(
"tag");
61 $filesizeMin = $request->getHeaderLine(
"filesizemin");
62 $filesizeMax = $request->getHeaderLine(
"filesizemax");
63 $license = $request->getHeaderLine(
"license");
64 $copyright = $request->getHeaderLine(
"copyright");
65 $uploadId = $request->getHeaderLine(
"uploadId");
66 $page = $request->getHeaderLine(
"page");
67 $limit = $request->getHeaderLine(
"limit");
71 if (empty($searchType)) {
72 $searchType =
"allfiles";
76 if (empty($uploadId)) {
83 if (empty($filename) && empty($tag) && empty($filesizeMin) &&
84 empty($filesizeMax) && empty($license) && empty($copyright)) {
86 "At least one parameter, containing a value is required");
92 if ((! empty($filesizeMin) && (! is_numeric($filesizeMin) || $filesizeMin < 0)) ||
93 (! empty($filesizeMax) && (! is_numeric($filesizeMax) || $filesizeMax < 0))) {
95 "filesizemin and filesizemax need to be positive integers!");
101 if ((! ($page===
'') && (! is_numeric($page) || $page < 1)) ||
102 (! ($limit===
'') && (! is_numeric($limit) || $limit < 1))) {
104 "page and limit need to be positive integers!");
115 }
else if ($limit > 100) {
120 list($results, $count) = $this->searchHelperDao->GetResults($item,
121 $filename, $uploadId, $tag, $page-1, $limit,
122 $filesizeMin, $filesizeMax, $searchType, $license, $copyright,
123 $this->restHelper->getUploadDao(), $this->restHelper->getGroupId());
124 $totalPages = intval(ceil($count / $limit));
128 foreach ($results as $result) {
129 $currentUpload = $this->dbHelper->getUploads(
130 $this->restHelper->getUserId(), $this->restHelper->getGroupId(), 1, 1,
131 $result[
"upload_fk"],
null,
true)[1];
132 if (! empty($currentUpload)) {
133 $currentUpload = $currentUpload[0];
137 $uploadTreePk = $result[
"uploadtree_pk"];
138 $filename = $this->dbHelper->getFilenameFromUploadTree($uploadTreePk);
139 $currentResult =
new SearchResult($currentUpload, $uploadTreePk, $filename);
140 $searchResults[] = $currentResult->getArray();
142 return $response->withHeader(
"X-Total-Pages", $totalPages)->withJson($searchResults, 200);
Base controller for REST calls.
Controller for Search model.
performSearch($request, $response, $args)
Override Slim response for withJson function.
static getVersion(ServerRequestInterface $request)
Model to hold search results.
GetParm($parameterName, $parameterType)
This function will retrieve the variables and check data types.