Loading module/Oscar/config/module.config.php +5 −1 Original line number Diff line number Diff line Loading @@ -104,7 +104,11 @@ return array( ], [ 'controller' => 'Project', 'action' => ['currentUserProjects', 'currentUserStructureProjects'], 'action' => [ 'currentUserProjects', 'currentUserStructureProjects', 'exportMany' ], 'privileges' => \Oscar\Provider\Privileges::PROJECT_DASHBOARD, 'roles' => ['user'], ], Loading module/Oscar/config/routes.yml +9 −0 Original line number Diff line number Diff line Loading @@ -458,6 +458,15 @@ project: action: export may_terminate: true ### Exporter des PROJETS export-many: type: segment options: route: '/export-projects' defaults: action: exportMany may_terminate: true ### Fiche du projet :id show: type: segment Loading module/Oscar/src/Oscar/Controller/ProjectController.php +62 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ namespace Oscar\Controller; use BjyAuthorize\Exception\UnAuthorizedException; use Doctrine\ORM\Query; use Oscar\Entity\ActivityOrganization; use Oscar\Entity\ActivityPayment; use Oscar\Entity\ActivityPerson; use Oscar\Entity\ContractDocument; use Oscar\Entity\LogActivity; Loading @@ -25,6 +26,9 @@ use Oscar\Entity\ProjectRepository; use Oscar\Exception\OscarException; use Oscar\Form\ProjectForm; use Oscar\Form\ProjectIdentificationForm; use Oscar\Formatter\CSVDownloader; use Oscar\Formatter\OscarFormatterConst; use Oscar\Formatter\ProjectFormatterFactory; use Oscar\Formatter\ProjectToArrayFormatter; use Oscar\Provider\Privileges; use Oscar\Service\ProjectGrantService; Loading Loading @@ -121,6 +125,63 @@ class ProjectController extends AbstractOscarController $this->redirect()->toRoute('project/mine'); } public function exportManyAction() { try { // Récupération des données $ids = $this->params()->fromPost('ids', ''); $format = $this->params()->fromPost('format', OscarFormatterConst::FORMAT_IO_JSON); $fields = $this->params()->fromPost('fields', null); if( $this->params()->fromQuery('f') ){ $format = $this->params()->fromQuery('f'); } $allowedFormat = [OscarFormatterConst::FORMAT_IO_CSV, OscarFormatterConst::FORMAT_IO_JSON]; if( !in_array($format, $allowedFormat) ){ return $this->getResponseInternalError(sprintf(_("Format '%s' inconnue"), $format)); } $projectIds = explode(',', $ids); if( count($projectIds) == 0 ){ return $this->getResponseInternalError("Aucun projet à exporter"); } // Récupération des projets $projects = $this->getProjectService()->getProjectsByIds($projectIds); $formatter = $this->getProjectService()->getFormatter($format); $csv = []; // Fichier temporaire $filename = uniqid('oscar_export_project_') . '.csv'; $filePath = '/tmp/' . $filename; $handler = fopen($filePath, 'w'); $delimiter = "\t"; fputcsv($handler, $formatter->headers(), $delimiter); foreach ($projects as $p) { fputcsv($handler, $formatter->format($p), $delimiter); } fclose($handler); $downloader = new CSVDownloader(); $downloader->downloadCSVToExcel($filePath); unlink($filePath); die(); } catch (\Exception $e) { throw new OscarException($e->getMessage()); } } public function exportAction() { $id = $this->params()->fromRoute('id', null); Loading @@ -137,6 +198,7 @@ class ProjectController extends AbstractOscarController $formatter->configure($rolesPerson, $rolesOrganizations, $milestones); $data = $formatter->format($project); echo '<table border="1">'; foreach ($data as $key=>$value) { echo "<tr>"; Loading module/Oscar/src/Oscar/Controller/ProjectGrantController.php +9 −0 Original line number Diff line number Diff line Loading @@ -2779,6 +2779,14 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif $activities = new UnicaenDoctrinePaginator($qb, $page); } $projectsIds = []; if( $projectview == 'on' ){ foreach ($activities as $p) { $projectsIds[] = $p->getId(); } } if ($this->getRequest()->isXmlHttpRequest()) { $json = [ 'datas' => [] Loading Loading @@ -2814,6 +2822,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif 'sortIgnoreNull' => $sortIgnoreNull, 'types' => $this->getActivityTypeService()->getActivityTypes(true), 'disciplines' => $this->getActivityService()->getDisciplines(), 'projectsIds' => $projectsIds, ] ); $view->setTemplate('oscar/project-grant/advanced-search.phtml'); Loading module/Oscar/src/Oscar/Formatter/IProjectFormater.php 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php namespace Oscar\Formatter; use Oscar\Entity\Project; interface IProjectFormater { public function formatProject( Project $project ); } No newline at end of file Loading
module/Oscar/config/module.config.php +5 −1 Original line number Diff line number Diff line Loading @@ -104,7 +104,11 @@ return array( ], [ 'controller' => 'Project', 'action' => ['currentUserProjects', 'currentUserStructureProjects'], 'action' => [ 'currentUserProjects', 'currentUserStructureProjects', 'exportMany' ], 'privileges' => \Oscar\Provider\Privileges::PROJECT_DASHBOARD, 'roles' => ['user'], ], Loading
module/Oscar/config/routes.yml +9 −0 Original line number Diff line number Diff line Loading @@ -458,6 +458,15 @@ project: action: export may_terminate: true ### Exporter des PROJETS export-many: type: segment options: route: '/export-projects' defaults: action: exportMany may_terminate: true ### Fiche du projet :id show: type: segment Loading
module/Oscar/src/Oscar/Controller/ProjectController.php +62 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ namespace Oscar\Controller; use BjyAuthorize\Exception\UnAuthorizedException; use Doctrine\ORM\Query; use Oscar\Entity\ActivityOrganization; use Oscar\Entity\ActivityPayment; use Oscar\Entity\ActivityPerson; use Oscar\Entity\ContractDocument; use Oscar\Entity\LogActivity; Loading @@ -25,6 +26,9 @@ use Oscar\Entity\ProjectRepository; use Oscar\Exception\OscarException; use Oscar\Form\ProjectForm; use Oscar\Form\ProjectIdentificationForm; use Oscar\Formatter\CSVDownloader; use Oscar\Formatter\OscarFormatterConst; use Oscar\Formatter\ProjectFormatterFactory; use Oscar\Formatter\ProjectToArrayFormatter; use Oscar\Provider\Privileges; use Oscar\Service\ProjectGrantService; Loading Loading @@ -121,6 +125,63 @@ class ProjectController extends AbstractOscarController $this->redirect()->toRoute('project/mine'); } public function exportManyAction() { try { // Récupération des données $ids = $this->params()->fromPost('ids', ''); $format = $this->params()->fromPost('format', OscarFormatterConst::FORMAT_IO_JSON); $fields = $this->params()->fromPost('fields', null); if( $this->params()->fromQuery('f') ){ $format = $this->params()->fromQuery('f'); } $allowedFormat = [OscarFormatterConst::FORMAT_IO_CSV, OscarFormatterConst::FORMAT_IO_JSON]; if( !in_array($format, $allowedFormat) ){ return $this->getResponseInternalError(sprintf(_("Format '%s' inconnue"), $format)); } $projectIds = explode(',', $ids); if( count($projectIds) == 0 ){ return $this->getResponseInternalError("Aucun projet à exporter"); } // Récupération des projets $projects = $this->getProjectService()->getProjectsByIds($projectIds); $formatter = $this->getProjectService()->getFormatter($format); $csv = []; // Fichier temporaire $filename = uniqid('oscar_export_project_') . '.csv'; $filePath = '/tmp/' . $filename; $handler = fopen($filePath, 'w'); $delimiter = "\t"; fputcsv($handler, $formatter->headers(), $delimiter); foreach ($projects as $p) { fputcsv($handler, $formatter->format($p), $delimiter); } fclose($handler); $downloader = new CSVDownloader(); $downloader->downloadCSVToExcel($filePath); unlink($filePath); die(); } catch (\Exception $e) { throw new OscarException($e->getMessage()); } } public function exportAction() { $id = $this->params()->fromRoute('id', null); Loading @@ -137,6 +198,7 @@ class ProjectController extends AbstractOscarController $formatter->configure($rolesPerson, $rolesOrganizations, $milestones); $data = $formatter->format($project); echo '<table border="1">'; foreach ($data as $key=>$value) { echo "<tr>"; Loading
module/Oscar/src/Oscar/Controller/ProjectGrantController.php +9 −0 Original line number Diff line number Diff line Loading @@ -2779,6 +2779,14 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif $activities = new UnicaenDoctrinePaginator($qb, $page); } $projectsIds = []; if( $projectview == 'on' ){ foreach ($activities as $p) { $projectsIds[] = $p->getId(); } } if ($this->getRequest()->isXmlHttpRequest()) { $json = [ 'datas' => [] Loading Loading @@ -2814,6 +2822,7 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif 'sortIgnoreNull' => $sortIgnoreNull, 'types' => $this->getActivityTypeService()->getActivityTypes(true), 'disciplines' => $this->getActivityService()->getDisciplines(), 'projectsIds' => $projectsIds, ] ); $view->setTemplate('oscar/project-grant/advanced-search.phtml'); Loading
module/Oscar/src/Oscar/Formatter/IProjectFormater.php 0 → 100644 +12 −0 Original line number Diff line number Diff line <?php namespace Oscar\Formatter; use Oscar\Entity\Project; interface IProjectFormater { public function formatProject( Project $project ); } No newline at end of file