public function listForJob($job_id) { try { $files = File::fetchAllFilesForWorkitem($job_id); $user = User::find(Session::uid()); if (!$user->getId()) { throw new Exception('Not enough rights'); } $job = WorkItem::getById($job_id); $data = array(); foreach ($files as $file) { if (!File::isAllowed($file->getStatus(), $user) || !$file->getIs_scanned()) { continue; } $fileUrl = $file->getUrl(); $iconUrl = $file->getUrl(); $userInvolved = $user->getId() == $file->getUserid() || $user->getId() == $job->getCreatorId() || $user->getId() == $job->getMechanicId() || $user->getId() == $job->getRunnerId(); $icon = File::getIconFromMime($file->getMime()); $data[] = array('fileid' => $file->getId(), 'url' => $fileUrl, 'can_delete' => $user->isRunner() || $user->isPayer() || $userInvolved, 'title' => $file->getTitle(), 'description' => $file->getDescription()); } return $this->setOutput(array('success' => true, 'data' => $data)); } catch (Exception $e) { return $this->setOutput(array('success' => false, 'message' => $e->getMessage())); } }