Skip to content

Commit

Permalink
Merge pull request #75 from nicolas-eoxia/fix_ref_exportshortnerdocument
Browse files Browse the repository at this point in the history
#70 [Tools] fix: missing ref for exportshortener
  • Loading branch information
nicolas-eoxia authored Sep 20, 2024
2 parents f5615b6 + 4752d5e commit 1a3ac0c
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 20 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
//Silence is golden apple
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/* Copyright (C) 2024 EVARISK <technique@evarisk.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
* or see https://www.gnu.org/
*/

/**
* \file core/modules/easyurl/easyurldocuments/exportshortenerdocument/mod_exportshortenerdocument_standard.php
* \ingroup easyurl
* \brief File of class to manage export shortener document numbering rules standard
*/

// Load Saturne libraries
require_once __DIR__ . '/../../../../../../saturne/core/modules/saturne/modules_saturne.php';

/**
* Class to manage export shortener document numbering rules standard
*/
class mod_exportshortenerdocument_standard extends ModeleNumRefSaturne
{
/**
* @var string Numbering module ref prefix
*/
public string $prefix = 'ESD';

/**
* @var string Name
*/
public string $name = 'Titan';
}
2 changes: 2 additions & 0 deletions core/modules/easyurl/easyurldocuments/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?php
//Silence is golden apple
3 changes: 3 additions & 0 deletions core/modules/modEasyURL.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ public function __construct($db)
// CONST SHORTENER
$i++ => ['EASYURL_SHORTENER_ADDON', 'chaine', 'mod_shortener_standard', '', 0, 'current'],

// CONST EXPORT SHORTENER DOCUMENT
$i++ => ['EASYURL_EXPORTSHORTENERDOCUMENT_ADDON', 'chaine', 'mod_exportshortenerdocument_standard', '', 0, 'current'],

// CONST DOLIBARR
$i++ => ['CONTRACT_ALLOW_ONLINESIGN', 'integer', 1, '', 0, 'current'],
$i => ['FICHINTER_ALLOW_ONLINE_SIGN', 'integer', 1, '', 0, 'current']
Expand Down
41 changes: 21 additions & 20 deletions view/easyurltools.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@
// Get parameters
$action = (GETPOSTISSET('action') ? GETPOST('action', 'aZ09') : 'view');

// Initialize technical objects
$shortener = new Shortener($db);
$exportShortenerDocument = new ExportShortenerDocument($db);

// Initialize view objects
$form = new Form($db);

Expand All @@ -65,7 +69,6 @@
$urlParameters = $data['url_parameters'];

if (dol_strlen($originalUrl) > 0 || dol_strlen(getDolGlobalString('EASYURL_DEFAULT_ORIGINAL_URL')) > 0) {
$shortener = new Shortener($db);
$shortener->ref = $shortener->getNextNumRef();
if (dol_strlen($originalUrl) > 0) {
$shortener->original_url = $originalUrl . $urlParameters;
Expand All @@ -92,11 +95,15 @@
}

if ($action == 'generate_export' && $permissionToAdd) {
$export = new ExportShortenerDocument($db);
$numberingModules = [$exportShortenerDocument->module . 'documents/' . $exportShortenerDocument->element => getDolGlobalString('EASYURL_EXPORTSHORTENERDOCUMENT_ADDON')];
list($refModName) = saturne_require_objects_mod($numberingModules, 'easyurl');
$objectDocumentRef = $refModName->getNextValue($exportShortenerDocument);

$exportShortenerDocument->ref = $objectDocumentRef;

$exportShortenerDocument->create($user);

$export->create($user);
$nbUrl = GETPOST('nb_url');
$shortener = new Shortener($db);
$shorteners = $shortener->fetchAll('DESC', 'rowid', $nbUrl);
if (is_array($shorteners) && !empty($shorteners)) {
$data = [
Expand All @@ -105,8 +112,9 @@
'first_shortener_id' => end($shorteners)->id,
'number_shortener_url' => $nbUrl
];
$export->json = json_encode($data);
$export->generateFile();
$exportShortenerDocument->ref = $objectDocumentRef;
$exportShortenerDocument->json = json_encode($data);
$exportShortenerDocument->generateFile();
}
header('Location: ' . $_SERVER['PHP_SELF'] . '?success=true&successType=export');
exit;
Expand Down Expand Up @@ -134,11 +142,11 @@
<?php endif;

$translations = [
'ExportGenerating' => $langs->transnoentities('ExportGenerating'),
'ExportError' => $langs->transnoentities('ExportError'),
'ExportSuccess' => $langs->transnoentities('ExportSuccess'),
'Success' => $langs->transnoentities('Success'),
'Error' => $langs->transnoentities('Error'),
'ExportGenerating' => $langs->transnoentities('ExportGenerating'),
'ExportError' => $langs->transnoentities('ExportError'),
'ExportSuccess' => $langs->transnoentities('ExportSuccess'),
'Success' => $langs->transnoentities('Success'),
'Error' => $langs->transnoentities('Error'),
];
print saturne_show_notice('', '', 'success', 'notice-infos', 0, 1, '', $translations);

Expand Down Expand Up @@ -202,19 +210,12 @@
print '<td>' . $langs->trans('Action') . '</td>';
print '</tr>';

$exportShortenerDocument = new ExportShortenerDocument($db);
$exportShortenerDocuments = $exportShortenerDocument->fetchAll('DESC', 'rowid', 0, 0, ['customsql' => 't.type="' . $exportShortenerDocument->element . '"']);

if (is_array($exportShortenerDocuments) && !empty($exportShortenerDocuments)) {

$shortener = new Shortener($db);

foreach ($exportShortenerDocuments as $exportShortenerDocument) {

$data = json_decode($exportShortenerDocument->json, true);

$shorteners = $shortener->fetchAll('', '', $data['number_shortener_url'], 0, ['customsql' => 't.rowid >=' . $data['first_shortener_id']]);

if (is_array($shorteners) && !empty($shorteners)) {
print '<tr class="oddeven">';
print '<td>' . $exportShortenerDocument->ref . '</td>';
Expand All @@ -226,10 +227,10 @@
print '<td>' . count(array_filter($shorteners, function ($elem) {return $elem->status == Shortener::STATUS_ASSIGN;})) . '</td>';

$uploadDir = $conf->easyurl->multidir_output[$conf->entity ?? 1];
$fileDir = $uploadDir . '/' . $exportShortenerDocument->element;
$fileDir = $uploadDir . '/' . $exportShortenerDocument->element;
if (dol_is_file($fileDir . '/' . $exportShortenerDocument->last_main_doc)) {
$documentUrl = DOL_URL_ROOT . '/document.php';
$fileUrl = $documentUrl . '?modulepart=easyurl&file=' . urlencode($exportShortenerDocument->element . '/' . $exportShortenerDocument->last_main_doc);
$fileUrl = $documentUrl . '?modulepart=easyurl&file=' . urlencode($exportShortenerDocument->element . '/' . $exportShortenerDocument->last_main_doc);
print '<td><div><a class="marginleftonly" href="' . $fileUrl . '" download>' . img_picto($langs->trans('File') . ' : ' . $exportShortenerDocument->last_main_doc, 'fa-file-csv') . '</a></div></td>';
}
print '</tr>';
Expand Down

0 comments on commit 1a3ac0c

Please sign in to comment.