public function __invoke(Attachment $attachment)
 {
     $folder = "uploads/entities/" . $attachment->getEntityName() . '/' . $attachment->getEntityId();
     $filePath = dirname(__DIR__) . "/../../../../../public/" . $folder;
     $grid = new Grid();
     $grid->setHasEntity(false);
     $grid->addColumn(new GridColumn('file', "Arquivo", 50));
     $grid->addColumn(new GridColumn('title', "Título"));
     $grid->addColumn(new GridColumn('type', "Tipo"));
     $grid->addColumn(new GridColumn('path', "Caminho"));
     $grid->addColumn(new GridColumn('size', "Tamanho"));
     $gridData = array();
     if (is_dir($filePath)) {
         $dir = opendir($filePath);
         while ($read = readdir($dir)) {
             if ($read != '.' && $read != '..') {
                 $fileName = $filePath . '/' . $read;
                 $path = $this->view->basePath($folder . '/' . $read);
                 $pathInfo = pathinfo($path);
                 $mimeType = $pathInfo['extension'];
                 $fileSize = number_format(filesize($fileName) / 1048576, 2) . ' MB';
                 $gridData[] = array('file' => "<a href=\"javascript:popupImage('{$path}');\">\n                                       <img src='{$path}' title='Clique para ampliar' width='50' height='50'/>\n                                   </a>", 'title' => $pathInfo['basename'], 'type' => strtoupper($mimeType), 'path' => $path, 'size' => $fileSize, GridColumn::GRID_IDENTITY_COLUMN_DEFAULT => $attachment->getEntityId(), 'attachment' => $pathInfo['basename']);
             }
         }
         $grid->setData($gridData);
     }
     $route = $this->getCurrentRoute();
     $grid->hideDefaultGridActions(true);
     $grid->addGridAction(new GridAction(GridAction::GRID_ACTION_DELETE_ID, "Excluir anexo", $route, 'removeattachment', "fa-trash-o"));
     $grid->setIdentityColumns(array(GridColumn::GRID_IDENTITY_COLUMN_DEFAULT, 'attachment'));
     return $this->view->GridHelper($grid);
 }
 public function __invoke(Attachment $attachment)
 {
     $folder = "uploads/entities/" . $attachment->getEntityName() . '/' . $attachment->getEntityId();
     $filePath = dirname(__DIR__) . "/../../../../../public/" . $folder;
     if (!is_dir($filePath)) {
         mkdir($filePath, 0777, true);
     }
     $applicationConfig = $this->getView()->getHelperPluginManager()->getServiceLocator()->get('config');
     $uploadImageBasePath = $this->view->basePath($applicationConfig['upload_image_base_path']);
     $folder = $uploadImageBasePath . $folder;
     $content = "\n            <script>\n                \$(document).ready(function() {\n                    \$('#file_upload').uploadify({\n                        'uploader'  : '{$this->view->basePath('uploadify/uploadify.swf')}',\n                        'script'    : '{$this->view->basePath('uploadify/uploadify.php')}',\n                        'cancelImg' : '{$this->view->basePath('uploadify/cancel.png')}',\n                        'folder'    : '{$this->view->basePath($folder)}',\n                        'auto'      : false, // False para não começar automaticamente, e True para começar o upload automaticamente.\n                        'multi'     : true, // False para fazer upload apenas de um arquivo e True para vários arquivos.\n                        'onAllComplete' : function(event, data) \n                        {   \n                            swal(\n                            {\n                                title: 'Ok!',   \n                                text: 'Upload dos anexos efetuados com sucesso!',   \n                                type: 'success',   \n                                showCancelButton: false,   \n                                confirmButtonColor: 'rgb(174, 222, 244)',   \n                                confirmButtonText: 'OK',    \n                                closeOnConfirm: false\n                            }, \n                            function ( isConfirm )\n                            {   \n                                if ( isConfirm ) \n                                {   \n                                    window.location.reload();\n                                } \n                            });\n                        } \n                    });\n                });\n            </script>\n            \n            \n            <div class='multiupload'>\n                <a style='float:right; margin-left: 5px;' href=\"javascript:\$('#file_upload').uploadifyUpload();\" >\n                    <button class='btn btn-primary loading'>Salvar arquivos</button>\n                </a>\n                <a style='float:right; margin-left: 10px;' href=\"javascript:\$('#file_upload').uploadifyClearQueue();\" >\n                    <button class='btn btn-danger'>Cancelar arquivos</button>\n                </a>\n                <input type='file' class='input-text btn' id='file_upload'/>\n            </div>";
     return $content;
 }