<?php
namespace App\Controller;
use App\Utils\DocumentoService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
class DocumentoController extends AbstractController
{
private $documentoService;
public function __construct(DocumentoService $documentoService)
{
$this->documentoService = $documentoService;
}
public function public()
{
//Metaetiquetas para la pagina principal
$url = 'documentspublicfrontend';
//seo on page
$seo_on_page = $this->documentoService->DevolverSeoOnPage($url);
// categorias
$categorias = $this->documentoService->ListarCategorias();
return $this->render('frontend/documento/public.html.twig', array(
'seo_on_page' => $seo_on_page,
'categorias' => $categorias
));
}
public function private()
{
//Metaetiquetas para la pagina principal
$url = 'documentsprivatefrontend';
//seo on page
$seo_on_page = $this->documentoService->DevolverSeoOnPage($url);
// categorias
$categorias = $this->documentoService->ListarCategorias();
return $this->render('frontend/documento/private.html.twig', array(
'seo_on_page' => $seo_on_page,
'categorias' => $categorias
));
}
/**
* listarPublic Acción que lista los documentos
*
*/
public function listarPublic(Request $request)
{
// search filter by keywords
$query = !empty($request->get('query')) ? $request->get('query') : array();
$sSearch = isset($query['generalSearch']) && is_string($query['generalSearch']) ? $query['generalSearch'] : '';
$categoria_id = isset($query['categoria_id']) && is_string($query['categoria_id']) ? $query['categoria_id'] : '';
//Sort
$sort = !empty($request->get('sort')) ? $request->get('sort') : array();
$sSortDir_0 = !empty($sort['sort']) ? $sort['sort'] : 'desc';
$iSortCol_0 = !empty($sort['field']) ? $sort['field'] : 'createdAt';
//$start and $limit
$pagination = !empty($request->get('pagination')) ? $request->get('pagination') : array();
$page = !empty($pagination['page']) ? (int)$pagination['page'] : 1;
$limit = !empty($pagination['perpage']) ? (int)$pagination['perpage'] : -1;
$start = 0;
try {
$empresa_id = $this->getParameter('empresa_id');
$privado = 0;
$pages = 1;
$total = $this->documentoService->TotalDocumentos($sSearch, $empresa_id, $categoria_id, $privado);
if ($limit > 0) {
$pages = ceil($total / $limit); // calculate total pages
$page = max($page, 1); // get 1 page when $_REQUEST['page'] <= 0
$page = min($page, $pages); // get last page when $_REQUEST['page'] > $totalPages
$start = ($page - 1) * $limit;
if ($start < 0) {
$start = 0;
}
}
$meta = array(
'page' => $page,
'pages' => $pages,
'perpage' => $limit,
'total' => $total,
'field' => $iSortCol_0,
'sort' => $sSortDir_0
);
$data = $this->documentoService->ListarDocumentos($start, $limit, $sSearch, $iSortCol_0, $sSortDir_0,
$empresa_id, $categoria_id, $privado);
$resultadoJson = array(
'meta' => $meta,
'data' => $data
);
return $this->json($resultadoJson);
} catch (\Exception $e) {
$resultadoJson['success'] = false;
$resultadoJson['error'] = $e->getMessage();
return $this->json($resultadoJson);
}
}
/**
* listarPrivate Acción que lista los documentos
*
*/
public function listarPrivate(Request $request)
{
// search filter by keywords
$query = !empty($request->get('query')) ? $request->get('query') : array();
$sSearch = isset($query['generalSearch']) && is_string($query['generalSearch']) ? $query['generalSearch'] : '';
$categoria_id = isset($query['categoria_id']) && is_string($query['categoria_id']) ? $query['categoria_id'] : '';
//Sort
$sort = !empty($request->get('sort')) ? $request->get('sort') : array();
$sSortDir_0 = !empty($sort['sort']) ? $sort['sort'] : 'desc';
$iSortCol_0 = !empty($sort['field']) ? $sort['field'] : 'createdAt';
//$start and $limit
$pagination = !empty($request->get('pagination')) ? $request->get('pagination') : array();
$page = !empty($pagination['page']) ? (int)$pagination['page'] : 1;
$limit = !empty($pagination['perpage']) ? (int)$pagination['perpage'] : -1;
$start = 0;
try {
$empresa_id = $this->getParameter('empresa_id');
$privado = 1;
$pages = 1;
$total = $this->documentoService->TotalDocumentos($sSearch, $empresa_id, $categoria_id, $privado);
if ($limit > 0) {
$pages = ceil($total / $limit); // calculate total pages
$page = max($page, 1); // get 1 page when $_REQUEST['page'] <= 0
$page = min($page, $pages); // get last page when $_REQUEST['page'] > $totalPages
$start = ($page - 1) * $limit;
if ($start < 0) {
$start = 0;
}
}
$meta = array(
'page' => $page,
'pages' => $pages,
'perpage' => $limit,
'total' => $total,
'field' => $iSortCol_0,
'sort' => $sSortDir_0
);
$data = $this->documentoService->ListarDocumentos($start, $limit, $sSearch, $iSortCol_0, $sSortDir_0,
$empresa_id, $categoria_id, $privado);
$resultadoJson = array(
'meta' => $meta,
'data' => $data
);
return $this->json($resultadoJson);
} catch (\Exception $e) {
$resultadoJson['success'] = false;
$resultadoJson['error'] = $e->getMessage();
return $this->json($resultadoJson);
}
}
}