PHP code example of relief_applications / doc-manager-bundle

1. Go to this page and download the library: Download relief_applications/doc-manager-bundle library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?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();
    }

    

    
    try{
        $path = $this->get('ra_doc.transfert')->getFilePath($document);
    } catch (DocumentException $e) {
        //...
    }

    



//...
use RA\DocBundle\Model\BaseDocument;
use RA\DocBundle\Model\Limits;
use Symfony\Component\HttpFoundation\File\File;
//...

class Document extends BaseDocument {
    //...
    /**
     * @Assert\NotNull(
     *     message = "The file is ,
     *         "image/jpeg", "image/png",
     *         "application/vnd.ms-powerpoint", "application/vnd.openxmlformats-officedocument.presentationml.presentation",
     *         "application/msword", "application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-powerpoint.addin.macroEnabled.12",
     *         "application/vnd.openxmlformats-officedocument.presentationml.template", "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
     *         "text/plain", "image/pjpeg","application/vnd.oasis.opendocument.spreadsheet"
     *     },
     *     mimeTypesMessage="ra.document.type-of-file-is-invalid"
     * )
     * @Vich\UploadableField(mapping="upload_file", fileNameProperty="name")
     *
     * @var File $customFile
     */
    protected $customFile;

    //...

    //overrides inherited function
    public function getFileField()
    {
        return 'customFile';
    }

    //overrides inherited function
    public function getFile()
    {
        return $this->getCustomFile();
    }

    //overrides inherited function
    public function setFile(\Symfony\Component\HttpFoundation\File\UploadedFile $file)
    {
        parent::setFile($file);
        $this->setCustomFile($file);
    }

}