Add file attachements to projects
This commit is contained in:
@@ -201,6 +201,36 @@ abstract class Base extends \Kanboard\Core\Base
|
||||
return $task;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Task or Project file
|
||||
*
|
||||
* @access protected
|
||||
*/
|
||||
protected function getFile()
|
||||
{
|
||||
$task_id = $this->request->getIntegerParam('task_id');
|
||||
$file_id = $this->request->getIntegerParam('file_id');
|
||||
$model = 'projectFile';
|
||||
|
||||
if ($task_id > 0) {
|
||||
$model = 'taskFile';
|
||||
$project_id = $this->taskFinder->getProjectId($task_id);
|
||||
|
||||
if ($project_id !== $this->request->getIntegerParam('project_id')) {
|
||||
$this->forbidden();
|
||||
}
|
||||
}
|
||||
|
||||
$file = $this->$model->getById($file_id);
|
||||
|
||||
if (empty($file)) {
|
||||
$this->notfound();
|
||||
}
|
||||
|
||||
$file['model'] = $model;
|
||||
return $file;
|
||||
}
|
||||
|
||||
/**
|
||||
* Common method to get a project
|
||||
*
|
||||
|
||||
89
app/Controller/FileViewer.php
Normal file
89
app/Controller/FileViewer.php
Normal file
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
use Kanboard\Core\ObjectStorage\ObjectStorageException;
|
||||
|
||||
/**
|
||||
* File Viewer Controller
|
||||
*
|
||||
* @package controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class FileViewer extends Base
|
||||
{
|
||||
/**
|
||||
* Show file content in a popover
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
$file = $this->getFile();
|
||||
$params = array('file_id' => $file['id'], 'project_id' => $this->request->getIntegerParam('project_id'));
|
||||
|
||||
if ($file['model'] === 'taskFile') {
|
||||
$params['task_id'] = $file['task_id'];
|
||||
}
|
||||
|
||||
$this->response->html($this->template->render('file_viewer/show', array(
|
||||
'file' => $file,
|
||||
'params' => $params,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Display image
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
try {
|
||||
$file = $this->getFile();
|
||||
$this->response->contentType($this->helper->file->getImageMimeType($file['name']));
|
||||
$this->objectStorage->output($file['path']);
|
||||
} catch (ObjectStorageException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display image thumbnail
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function thumbnail()
|
||||
{
|
||||
$this->response->contentType('image/jpeg');
|
||||
|
||||
try {
|
||||
$file = $this->getFile();
|
||||
$model = $file['model'];
|
||||
$this->objectStorage->output($this->$model->getThumbnailPath($file['path']));
|
||||
} catch (ObjectStorageException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
|
||||
// Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19
|
||||
$data = $this->objectStorage->get($file['path']);
|
||||
$this->$model->generateThumbnailFromData($file['path'], $data);
|
||||
$this->objectStorage->output($this->$model->getThumbnailPath($file['path']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* File download
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function download()
|
||||
{
|
||||
try {
|
||||
$file = $this->getFile();
|
||||
$this->response->forceDownload($file['name']);
|
||||
$this->objectStorage->output($file['path']);
|
||||
} catch (ObjectStorageException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
79
app/Controller/ProjectFile.php
Normal file
79
app/Controller/ProjectFile.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
/**
|
||||
* Project File Controller
|
||||
*
|
||||
* @package controller
|
||||
* @author Frederic Guillot
|
||||
*/
|
||||
class ProjectFile extends Base
|
||||
{
|
||||
/**
|
||||
* File upload form
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
|
||||
$this->response->html($this->template->render('project_file/create', array(
|
||||
'project' => $project,
|
||||
'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')),
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Save uploaded files
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function save()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
|
||||
if (! $this->projectFile->uploadFiles($project['id'], $this->request->getFileInfo('files'))) {
|
||||
$this->flash->failure(t('Unable to upload the file.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('ProjectOverview', 'show', array('project_id' => $project['id'])), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a file
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function remove()
|
||||
{
|
||||
$this->checkCSRFParam();
|
||||
$project = $this->getProject();
|
||||
$file = $this->projectFile->getById($this->request->getIntegerParam('file_id'));
|
||||
|
||||
if ($this->projectFile->remove($file['id'])) {
|
||||
$this->flash->success(t('File removed successfully.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to remove this file.'));
|
||||
}
|
||||
|
||||
$this->response->redirect($this->helper->url->to('ProjectOverview', 'show', array('project_id' => $project['id'])));
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirmation dialog before removing a file
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function confirm()
|
||||
{
|
||||
$project = $this->getProject();
|
||||
$file = $this->projectFile->getById($this->request->getIntegerParam('file_id'));
|
||||
|
||||
$this->response->html($this->template->render('project_file/remove', array(
|
||||
'project' => $project,
|
||||
'file' => $file,
|
||||
)));
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,8 @@ class ProjectOverview extends Base
|
||||
$params['users'] = $this->projectUserRole->getAllUsersGroupedByRole($params['project']['id']);
|
||||
$params['roles'] = $this->role->getProjectRoles();
|
||||
$params['events'] = $this->projectActivity->getProject($params['project']['id'], 10);
|
||||
$params['images'] = $this->projectFile->getAllImages($params['project']['id']);
|
||||
$params['files'] = $this->projectFile->getAllDocuments($params['project']['id']);
|
||||
|
||||
$this->project->getColumnStats($params['project']);
|
||||
|
||||
|
||||
@@ -2,10 +2,8 @@
|
||||
|
||||
namespace Kanboard\Controller;
|
||||
|
||||
use Kanboard\Core\ObjectStorage\ObjectStorageException;
|
||||
|
||||
/**
|
||||
* File File Controller
|
||||
* Task File Controller
|
||||
*
|
||||
* @package controller
|
||||
* @author Frederic Guillot
|
||||
@@ -26,7 +24,7 @@ class TaskFile extends Base
|
||||
return $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true);
|
||||
}
|
||||
|
||||
$this->response->html($this->helper->layout->task('task_file/screenshot', array(
|
||||
$this->response->html($this->template->render('task_file/screenshot', array(
|
||||
'task' => $task,
|
||||
)));
|
||||
}
|
||||
@@ -40,7 +38,7 @@ class TaskFile extends Base
|
||||
{
|
||||
$task = $this->getTask();
|
||||
|
||||
$this->response->html($this->helper->layout->task('task_file/new', array(
|
||||
$this->response->html($this->template->render('task_file/create', array(
|
||||
'task' => $task,
|
||||
'max_size' => $this->helper->text->phpToBytes(ini_get('upload_max_filesize')),
|
||||
)));
|
||||
@@ -62,92 +60,6 @@ class TaskFile extends Base
|
||||
$this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true);
|
||||
}
|
||||
|
||||
/**
|
||||
* File download
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function download()
|
||||
{
|
||||
try {
|
||||
$task = $this->getTask();
|
||||
$file = $this->taskFile->getById($this->request->getIntegerParam('file_id'));
|
||||
|
||||
if ($file['task_id'] != $task['id']) {
|
||||
$this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])));
|
||||
}
|
||||
|
||||
$this->response->forceDownload($file['name']);
|
||||
$this->objectStorage->output($file['path']);
|
||||
} catch (ObjectStorageException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Open a file (show the content in a popover)
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function open()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
$file = $this->taskFile->getById($this->request->getIntegerParam('file_id'));
|
||||
|
||||
if ($file['task_id'] == $task['id']) {
|
||||
$this->response->html($this->template->render('task_file/open', array(
|
||||
'file' => $file,
|
||||
'task' => $task,
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display image
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function image()
|
||||
{
|
||||
try {
|
||||
$task = $this->getTask();
|
||||
$file = $this->taskFile->getById($this->request->getIntegerParam('file_id'));
|
||||
|
||||
if ($file['task_id'] == $task['id']) {
|
||||
$this->response->contentType($this->taskFile->getImageMimeType($file['name']));
|
||||
$this->objectStorage->output($file['path']);
|
||||
}
|
||||
} catch (ObjectStorageException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display image thumbnails
|
||||
*
|
||||
* @access public
|
||||
*/
|
||||
public function thumbnail()
|
||||
{
|
||||
$this->response->contentType('image/jpeg');
|
||||
|
||||
try {
|
||||
$task = $this->getTask();
|
||||
$file = $this->taskFile->getById($this->request->getIntegerParam('file_id'));
|
||||
|
||||
if ($file['task_id'] == $task['id']) {
|
||||
$this->objectStorage->output($this->taskFile->getThumbnailPath($file['path']));
|
||||
}
|
||||
} catch (ObjectStorageException $e) {
|
||||
$this->logger->error($e->getMessage());
|
||||
|
||||
// Try to generate thumbnail on the fly for images uploaded before Kanboard < 1.0.19
|
||||
$data = $this->objectStorage->get($file['path']);
|
||||
$this->taskFile->generateThumbnailFromData($file['path'], $data);
|
||||
$this->objectStorage->output($this->taskFile->getThumbnailPath($file['path']));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a file
|
||||
*
|
||||
@@ -178,7 +90,7 @@ class TaskFile extends Base
|
||||
$task = $this->getTask();
|
||||
$file = $this->taskFile->getById($this->request->getIntegerParam('file_id'));
|
||||
|
||||
$this->response->html($this->helper->layout->task('task_file/remove', array(
|
||||
$this->response->html($this->template->render('task_file/remove', array(
|
||||
'task' => $task,
|
||||
'file' => $file,
|
||||
)));
|
||||
|
||||
Reference in New Issue
Block a user