37 const NAME =
"browse-processPost";
46 private $dataTablesUtility;
48 private $filterParams;
54 function __construct()
56 parent::__construct(self::NAME, array(
57 self::REQUIRES_LOGIN =>
false,
61 $this->uploadDao = $container->get(
'dao.upload');
62 $this->userDao = $container->get(
'dao.user');
63 $this->
dbManager = $container->get(
'db.manager');
64 $this->dataTablesUtility = $container->get(
'utils.data_tables_utility');
70 protected function handle(Request $request)
73 $gup = $this->
dbManager->getSingleRow(
'SELECT group_perm FROM group_user_member WHERE user_fk=$1 AND group_fk=$2',
76 throw new \Exception(
'You are assigned to wrong group.');
78 $this->userPerm = $gup[
'group_perm'];
80 $uploadId = intval($request->get(
'uploadId'));
81 if ($uploadId && !$this->uploadDao->isAccessible($uploadId, $groupId)) {
82 throw new \Exception(
'You cannot access to this upload');
85 $columnName = $request->get(
'columnName');
86 $statusId = intval($request->get(
'statusId'));
87 $value = intval($request->get(
'value'));
88 $moveUpload = intval($request->get(
"move"));
89 $beyondUpload = intval($request->get(
"beyond"));
90 $commentText = $request->get(
'commentText');
91 $direction = $request->get(
'direction');
93 if (! empty($columnName) && ! empty($uploadId) && ! empty($value)) {
95 $uploadBrowseProxy->updateTable($columnName, $uploadId, $value);
96 }
else if (! empty($moveUpload) && ! empty($beyondUpload)) {
98 $uploadBrowseProxy->moveUploadBeyond($moveUpload, $beyondUpload);
99 }
else if (! empty($uploadId) && ! empty($direction)) {
101 $uploadBrowseProxy->moveUploadToInfinity($uploadId, $direction ==
'top');
102 }
else if (!empty($uploadId) && !empty($commentText) && !empty($statusId)) {
104 $uploadBrowseProxy->setStatusAndComment($uploadId, $statusId, $commentText);
108 return new Response(
'');
123 $menuPfile =
menu_find(
"Browse-Pfile", $menuDepth);
125 $menuPfileNoCompare =
menu_remove($menuPfile,
"Compare");
127 $users = $this->userDao->getUserChoices();
129 $statusTypesAvailable = $this->uploadDao->getStatusTypeMap();
130 if (!$this->userPerm) {
131 unset($statusTypesAvailable[4]);
136 while ($row = $this->
dbManager->fetchArray($result)) {
137 if (empty($row[
'upload_pk']) || !$this->uploadDao->isAccessible($row[
'upload_pk'],
Auth::getGroupId())) {
141 $output[] = $this->
showRow($row, $request, $uri, $menuPfile, $menuPfileNoCompare, $statusTypesAvailable, $users, $rowCounter);
144 return new JsonResponse(array(
145 'sEcho' => intval($request->get(
'sEcho')),
147 'iTotalRecords' => $iTotalRecords,
148 'iTotalDisplayRecords' => $iTotalDisplayRecords
164 private function showRow($row,Request $request, $uri, $menuPfile, $menuPfileNoCompare, $statusTypesAvailable, $users, $rowCounter)
166 $show = $request->get(
'show');
167 $folder = $request->get(
'folder');
169 $uploadId = intval($row[
'upload_pk']);
170 $description = htmlentities($row[
'upload_desc']);
172 $fileName = $row[
'ufile_name'];
173 if (empty($fileName)) {
174 $fileName = $row[
'upload_filename'];
179 $nameColumn =
"<b>$fileName</b>";
180 if (IsContainer($row[
'ufile_mode'])) {
181 $nameColumn =
"<a href='$uri&upload=$uploadId&folder=$folder&item=$itemId&show=$show'>$nameColumn</a>";
183 $nameColumn .=
"<br>";
184 if (!empty($description)) {
185 $nameColumn .=
"<i>$description</i><br>";
187 $Parm =
"upload=$uploadId&show=$show&item=" . $row[
'uploadtree_pk'];
195 if (!empty($modsUploadMulti)) {
196 $nameColumn =
'<input type="checkbox" name="uploads[]" class="browse-upload-checkbox" value="'.$uploadId.
'"/>'.$nameColumn;
200 $pairIdPrio = array($uploadId, floatval($row[UploadBrowseProxy::PRIO_COLUMN]));
201 if (!$this->userPerm && 4 == $row[
'status_fk']) {
202 $currentStatus = $this->statusTypes[4];
204 $statusAction =
" onchange =\"changeTableEntry(this, $uploadId,'status_fk' )\" ";
205 $currentStatus = $this->createSelect(
"Status" . $this->userPerm .
"Of_$rowCounter", $statusTypesAvailable, $row[
'status_fk'], $statusAction);
207 if ($this->userPerm) {
208 $action =
" onchange =\"changeTableEntry(this, $uploadId, 'assignee')\"";
209 $currentAssignee = $this->
createSelectUsers(
"AssignedTo_$rowCounter", $users, $row[
'assignee'], $action );
211 $currentAssignee = array_key_exists($row[
'assignee'], $users) ? $users[$row[
'assignee']] : _(
'Unassigned');
213 $rejectableUploadId = ($this->userPerm || $row[
'status_fk'] < 4) ? $uploadId : 0;
214 $tripleComment = array($rejectableUploadId, $row[
'status_fk'], htmlspecialchars($row[
'status_comment']));
216 $sql =
"SELECT rf_pk, rf_shortname FROM upload_clearing_license ucl, license_ref" 217 .
" WHERE ucl.group_fk=$1 AND upload_fk=$2 AND ucl.rf_fk=rf_pk";
218 $stmt = __METHOD__.
'.collectMainLicenses';
221 $mainLicenses = array();
222 while ($lic=$this->
dbManager->fetchArray($res)) {
223 $mainLicenses[] =
'<a onclick="javascript:window.open(\''.Traceback_uri()
224 .
"?mod=popup-license&rf=$lic[rf_pk]','License text','width=600,height=400,toolbar=no,scrollbars=yes,resizable=yes');" 225 .
'" href="javascript:;">'.$lic[
'rf_shortname'].
'</a>' 226 .
"<img onclick=\"removeMainLicense($uploadId,$lic[rf_pk]);\" class=\"delete\" src=\"images/space_16.png\" alt=\"\"/></img>";
230 $output = array($nameColumn, $currentStatus, $tripleComment, implode(
', ', $mainLicenses), $currentAssignee, $dateCol, $pairIdPrio);
240 private function createSelectUsers($selectElementName, $databaseMap, $selectedValue, $action =
"")
242 if (array_key_exists($_SESSION[
'UserId'], $databaseMap)) {
243 $databaseMap[$_SESSION[
'UserId']] = _(
'-- Me --');
245 $databaseMap[1] = _(
'Unassigned');
246 return $this->createSelect($selectElementName,$databaseMap, $selectedValue,$action);
250 private function createSelect($id,$options,$select=
'',$action=
'')
252 $html =
"<select name=\"$id\" id=\"$id\" $action class=\"ui-render-select2\">";
253 foreach ($options as $key=>$disp) {
254 $html .=
'<option value="'.$key.
'"';
255 if ($key == $select) {
256 $html .=
' selected';
258 $html .=
">$disp</option>";
260 $html .=
'</select>';
272 $params = array($request->get(
'folder'));
273 $partQuery = $uploadBrowseProxy->getFolderPartialQuery($params);
275 $iTotalRecordsRow = $this->
dbManager->getSingleRow(
"SELECT count(*) FROM $partQuery", $params, __METHOD__ .
"count.all");
276 $iTotalRecords = $iTotalRecordsRow[
'count'];
278 $this->filterParams = $params;
279 $filter = $this->getSearchString($request->get(
'sSearch'));
280 $filter .= $this->
getIntegerFilter(intval($request->get(
'assigneeSelected')),
'assignee');
281 $filter .= $this->
getIntegerFilter(intval($request->get(
'statusSelected')),
'status_fk');
283 $iTotalDisplayRecordsRow = $this->
dbManager->getSingleRow(
"SELECT count(*) FROM $partQuery $filter",
284 $this->filterParams, __METHOD__ .
".count.". $filter);
285 $iTotalDisplayRecords = $iTotalDisplayRecordsRow[
'count'];
287 $orderString = $this->getOrderString();
288 $stmt = __METHOD__ .
"getFolderContents" . $orderString . $filter;
290 $statementString =
"SELECT upload.*,upload_clearing.*,uploadtree.ufile_name,uploadtree.ufile_mode,uploadtree.uploadtree_pk" 291 .
" FROM $partQuery $filter $orderString";
292 $rangedFilterParams = $this->filterParams;
293 $rangedFilterParams[] = intval($request->get(
'iDisplayStart'));
294 $statementString .=
' OFFSET $' . count($rangedFilterParams);
295 $rangedFilterParams[] = intval($request->get(
'iDisplayLength'));
296 $statementString .=
' LIMIT $' . count($rangedFilterParams);
298 $this->
dbManager->prepare($stmt, $statementString);
299 $result = $this->
dbManager->execute($stmt, $rangedFilterParams);
301 return array($result, $iTotalDisplayRecords, $iTotalRecords);
304 private function getOrderString()
306 $columnNamesInDatabase = array(
'upload_filename',
'upload_clearing.status_fk',
'UNUSED',
'UNUSED',
'upload_clearing.assignee',
'upload_ts',
'upload_clearing.priority');
308 $orderString = $this->dataTablesUtility->getSortingString($_GET, $columnNamesInDatabase);
313 private function getSearchString($searchPattern)
315 if (empty($searchPattern)) {
318 $this->filterParams[] =
"%$searchPattern%";
319 return ' AND upload_filename ilike $' . count($this->filterParams) .
' ';
331 $this->filterParams[] = $var;
332 return " AND $columnName=$" . count($this->filterParams) .
' ';
getIntegerFilter($var, $columnName)
Traceback_uri()
Get the URI without query to this location.
static getUserId()
Get the current user's id.
getListOfUploadsOfFolder(Request $request)
respondFolderGetTableData(Request $request)
Convert2BrowserTime($server_time)
Convert the server time to browser time.
createSelectUsers($selectElementName, $databaseMap, $selectedValue, $action="")
DirGetNonArtifact($UploadtreePk, $uploadtree_tablename='uploadtree')
Given an artifact directory (uploadtree_pk), return the first non-artifact directory (uploadtree_pk)...
showRow($row, Request $request, $uri, $menuPfile, $menuPfileNoCompare, $statusTypesAvailable, $users, $rowCounter)
fo_dbManager * dbManager
fo_dbManager object
static getGroupId()
Get the current user's group id.
handle(Request $request)
Display the loaded menu and plugins.