承接 relief_applications/doc-manager-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

relief_applications/doc-manager-bundle

Composer 安装命令:

composer require relief_applications/doc-manager-bundle

包简介

A bundle to manage upload and download of documents within database context

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

DocBundle

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

$ composer require relief_applications/doc-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

For more informations about the bundle and its dependencies, please visit our packagist page : https://packagist.org/packages/relief_applications/doc-bundle .

Step 2: Enable the Bundle

Then, enable the bundle by adding it to the list of registered bundles in the app/AppKernel.php file of your project:

<?php
// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new RA\DocBundle\RADocBundle(),
        );

        // ...
    }

    // ...
}

Step 3: Usage

  1. Create a class which extends Ra\DocBundle\Model\BaseDocument

    <?php
    /**
    * @ORM\Table(name="document")
    * @ORM\Entity(repositoryClass="...")
    **/
    class Document extends BaseDocument {
        //...
        public function __construct()
        {
            parent::__construct();
            // your work
        }
        //...
    }
  2. Uploading and creating a document

    <?php
    
    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);
        }
  3. Uploading and updating a document

    <?php
    
    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);
        }
  4. Downloading a document

    <?php
    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);
        }
    }
  5. Removing a document

    <?php
    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();
    }
  6. Get document's path in the filesystem

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

Step 4: Configuration

The configuration of Vich, Gaufrette and Liip is the responsability of the developer.

Step * : Customization

You can change the default file's field by adding a custom field and declaring this field :

<?php

//...
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 required"
     * )
     * @Assert\File(
     *     maxSize= Limits::max_document_size,
     *     mimeTypes={"application/pdf", "application/x-pdf",
     *         "application/vnd.ms-excel", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
     *         "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);
    }

}

You can also define your custom requirements in the Assert\File annotation.

统计信息

  • 总下载量: 118
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-10-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固