mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
PHRAS-3080 add pdf file cgu in zip
This commit is contained in:
@@ -15,6 +15,7 @@ use Alchemy\Phrasea\Authentication\ACLProvider;
|
|||||||
use Alchemy\Phrasea\Authentication\Authenticator;
|
use Alchemy\Phrasea\Authentication\Authenticator;
|
||||||
use Alchemy\Phrasea\Controller\Controller;
|
use Alchemy\Phrasea\Controller\Controller;
|
||||||
use Alchemy\Phrasea\Model\Manipulator\TaskManipulator;
|
use Alchemy\Phrasea\Model\Manipulator\TaskManipulator;
|
||||||
|
use Alchemy\Phrasea\Out\Module\PDFCgu;
|
||||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@@ -244,6 +245,10 @@ class DataboxController extends Controller
|
|||||||
foreach ($request->request->get('TOU', []) as $loc => $terms) {
|
foreach ($request->request->get('TOU', []) as $loc => $terms) {
|
||||||
$databox->update_cgus($loc, $terms, !!$request->request->get('valid', false));
|
$databox->update_cgus($loc, $terms, !!$request->request->get('valid', false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// generate cgu for the databox
|
||||||
|
$pdfCgu = new PDFCgu($this->app, $databox_id);
|
||||||
|
$pdfCgu->save();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
return $this->app->redirectPath('admin_database_display_cgus', [
|
return $this->app->redirectPath('admin_database_display_cgus', [
|
||||||
'databox_id' => $databox_id,
|
'databox_id' => $databox_id,
|
||||||
|
60
lib/Alchemy/Phrasea/Out/Module/PDFCgu.php
Normal file
60
lib/Alchemy/Phrasea/Out/Module/PDFCgu.php
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Alchemy\Phrasea\Out\Module;
|
||||||
|
|
||||||
|
use Alchemy\Phrasea\Application;
|
||||||
|
|
||||||
|
class PDFCgu extends PDF
|
||||||
|
{
|
||||||
|
private $databoxId;
|
||||||
|
|
||||||
|
public function __construct(Application $app, $databoxId)
|
||||||
|
{
|
||||||
|
parent::__construct($app);
|
||||||
|
|
||||||
|
$this->app = $app;
|
||||||
|
$this->databoxId = $databoxId;
|
||||||
|
|
||||||
|
$this->printCgu();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
$this->pdf->Close();
|
||||||
|
$pathName = self::getDataboxCguPath($this->app, $this->databoxId);
|
||||||
|
|
||||||
|
$this->pdf->Output($pathName, 'F');
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDataboxCguPath(Application $app, $databoxId)
|
||||||
|
{
|
||||||
|
|
||||||
|
return \p4string::addEndSlash($app['tmp.download.path']). self::getDataboxCguPdfName($app, $databoxId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getDataboxCguPdfName(Application $app, $databoxId)
|
||||||
|
{
|
||||||
|
$databox = $app->findDataboxById($databoxId);
|
||||||
|
|
||||||
|
return 'cgu_' . $databoxId . '_'. $databox->get_dbname() . '.pdf';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function printCgu()
|
||||||
|
{
|
||||||
|
$databox = $this->app->findDataboxById($this->databoxId);
|
||||||
|
$databox->get_dbname();
|
||||||
|
|
||||||
|
$CGUs = $databox->get_cgus();
|
||||||
|
|
||||||
|
$html = '';
|
||||||
|
|
||||||
|
foreach ($CGUs as $locale => $tou) {
|
||||||
|
$html .= '<h2> '.$this->app->trans('Terms Of Use', [], 'messages', $locale) .'</h2>';
|
||||||
|
$html .= $tou['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->pdf->AddPage();
|
||||||
|
|
||||||
|
$this->pdf->writeHTML($html);
|
||||||
|
}
|
||||||
|
}
|
@@ -14,6 +14,7 @@ use Alchemy\Phrasea\Model\Entities\User;
|
|||||||
use Alchemy\Phrasea\Model\Repositories\BasketRepository;
|
use Alchemy\Phrasea\Model\Repositories\BasketRepository;
|
||||||
use Alchemy\Phrasea\Model\Repositories\StoryWZRepository;
|
use Alchemy\Phrasea\Model\Repositories\StoryWZRepository;
|
||||||
use Alchemy\Phrasea\Model\Serializer\CaptionSerializer;
|
use Alchemy\Phrasea\Model\Serializer\CaptionSerializer;
|
||||||
|
use Alchemy\Phrasea\Out\Module\PDFCgu;
|
||||||
use Assert\Assertion;
|
use Assert\Assertion;
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use Symfony\Component\Filesystem\Filesystem;
|
use Symfony\Component\Filesystem\Filesystem;
|
||||||
@@ -418,6 +419,7 @@ class set_export extends set_abstract
|
|||||||
|
|
||||||
$files[$id] = [
|
$files[$id] = [
|
||||||
'base_id' => $download_element->getBaseId(),
|
'base_id' => $download_element->getBaseId(),
|
||||||
|
'databox_id' => $download_element->getDataboxId(),
|
||||||
'record_id' => $download_element->getRecordId(),
|
'record_id' => $download_element->getRecordId(),
|
||||||
'original_name' => '',
|
'original_name' => '',
|
||||||
'export_name' => '',
|
'export_name' => '',
|
||||||
@@ -691,6 +693,7 @@ class set_export extends set_abstract
|
|||||||
|
|
||||||
$toRemove = [];
|
$toRemove = [];
|
||||||
$archiveFiles = [];
|
$archiveFiles = [];
|
||||||
|
$databoxIds = [];
|
||||||
|
|
||||||
foreach ($files as $record) {
|
foreach ($files as $record) {
|
||||||
if (isset($record["subdefs"])) {
|
if (isset($record["subdefs"])) {
|
||||||
@@ -709,6 +712,28 @@ class set_export extends set_abstract
|
|||||||
}
|
}
|
||||||
$toRemove[] = $path;
|
$toRemove[] = $path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!in_array($record['databox_id'], $databoxIds)) {
|
||||||
|
// add also the databox cgu in the zip
|
||||||
|
$databoxIds[] = $record['databox_id'];
|
||||||
|
|
||||||
|
$databoxCguPath = PDFCgu::getDataboxCguPath($app, $record['databox_id']);
|
||||||
|
|
||||||
|
if (!is_file($databoxCguPath)) {
|
||||||
|
try {
|
||||||
|
$pdfCgu = new PDFCgu($app, $record['databox_id']);
|
||||||
|
$pdfCgu->save();
|
||||||
|
|
||||||
|
$databoxCguPath = PDFCgu::getDataboxCguPath($app, $record['databox_id']);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$app['logger']->error("Exception occurred when generating cgu pdf : " . $e->getMessage());
|
||||||
|
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$archiveFiles[$app['unicode']->remove_diacritics($obj["folder"].PDFCgu::getDataboxCguPdfName($app, $record['databox_id']))] = $databoxCguPath;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user