<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
relief_applications / doc-manager-bundle example snippets
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new RA\DocBundle\RADocBundle(),
);
// ...
}
// ...
}
/**
* @ORM\Table(name="document")
* @ORM\Entity(repositoryClass="...")
**/
class Document extends BaseDocument {
//...
public function __construct()
{
parent::__construct();
// your work
}
//...
}
public function createAction(Request $request){
//build Document
$document = new Document();
$file = $request->files->get('file');
try {
$this->get('ra_doc.transfert')->createDocument($document, $file);
} catch (DocumentException $e) {
return new JsonResponse($e->getMessage(), Response::HTTP_BAD_REQUEST);
}
public function updateAction(Request $request, Document $document) {
$name = $request->request->get('name');
$file = $request->files->get('file'); //doesn't care if the file is empty or not
//if the file is empty, there won't be any upload
//changing metaname
$document->getDocumentMeta()->setName($name);
try {
$this->get('ra_doc.transfert')->updateDocument($document, $file);
} catch (DocumentException $e) {
return new JsonResponse($e->getMessage(), Response::HTTP_BAD_REQUEST);
}
public function downloadAction(Request $request, Document $document)
{
try {
return $this->get('ra_doc.transfert')->download($document);
} catch (DocumentException $e) {
return new JsonResponse($e->getMessage(), Response::HTTP_BAD_REQUEST);
}
}
public function deleteAction(Request $request, Document $document)
{
try{
$this->get('ra_doc.transfert')->deleteDocument($document);
} catch (DocumentException $e) {
return new Response($e->getMessage(), Response::HTTP_BAD_REQUEST);
}
return new Response();
}