Skip to content

Commit

Permalink
Eoxia#70 [Class/Js] add: export of url in csv and reword link creatio…
Browse files Browse the repository at this point in the history
…n in js
  • Loading branch information
evarisk-kilyan committed Sep 5, 2024
1 parent cd53864 commit 19e77da
Show file tree
Hide file tree
Showing 7 changed files with 454 additions and 42 deletions.
42 changes: 24 additions & 18 deletions class/shortener.class.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php
/* Copyright (C) 2021-2023 EVARISK <technique@evarisk.com>
/* Copyright (C) 2021-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
Expand Down Expand Up @@ -107,23 +107,24 @@ class Shortener extends SaturneObject
* @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor
*/
public $fields = [
'rowid' => ['type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => 'Id'],
'ref' => ['type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' =>1, 'searchall' => 1, 'showoncombobox' => 1, 'validate' => 1, 'comment' => 'Reference of object'],
'ref_ext' => ['type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'position' => 20, 'notnull' => 0, 'visible' => 0],
'entity' => ['type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 0, 'index' => 1],
'date_creation' => ['type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 40, 'notnull' => 1, 'visible' => 2],
'tms' => ['type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 0],
'import_key' => ['type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 0],
'status' => ['type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 160, 'notnull' => 1, 'visible' => 2, 'default' => 0, 'index' => 1, 'arrayofkeyval' => [0 => 'StatusDraft', 1 => 'ValidatePendingAssignment', 10 => 'Assign'], 'css' => 'minwidth100 maxwidth300 widthcentpercentminusxx'],
'label' => ['type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 70, 'notnull' => 1, 'visible' => 5, 'searchall' => 1, 'css' => 'minwidth100 maxwidth300 widthcentpercentminusxx', 'cssview' => 'wordbreak', 'showoncombobox' => 2, 'validate' => 1],
'short_url' => ['type' => 'url', 'label' => 'ShortUrl', 'enabled' => 1, 'position' => 80, 'notnull' => 0, 'visible' => 1, 'copytoclipboard' => 1, 'css' => 'minwidth100 maxwidth300 widthcentpercentminusxx nowrap'],
'original_url' => ['type' => 'url', 'label' => 'OriginalUrl', 'enabled' => 1, 'position' => 90, 'notnull' => 0, 'visible' => 1, 'copytoclipboard' => 1, 'css' => 'minwidth100 maxwidth300 widthcentpercentminusxx nowrap'],
'type' => ['type' => 'sellist:c_shortener_url_type:label', 'label' => 'UrlType', 'enabled' => 1, 'position' => 100, 'notnull' => 0, 'visible' => 1, 'css' => 'maxwidth150 widthcentpercentminusxx'],
'methode' => ['type' => 'select', 'label' => 'UrlMethode', 'enabled' => 1, 'position' => 110, 'notnull' => 0, 'visible' => 5, 'arrayofkeyval' => ['' => '', 'yourls' => 'YOURLS', 'wordpress' => 'WordPress'], 'css' => 'maxwidth200 widthcentpercentminusxx', 'csslist' => 'minwidth150 center', 'help' => 'UrlMethodeDescription'],
'element_type' => ['type' => 'select', 'label' => 'ElementType', 'enabled' => 1, 'position' => 120, 'notnull' => 0, 'visible' => 1, 'arrayofkeyval' => ['' => ''], 'css' => 'maxwidth150 widthcentpercentminusxx'],
'fk_element' => ['type' => 'integer', 'label' => 'FkElement', 'enabled' => 1, 'position' => 130, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'css' => 'minwidth200 maxwidth300 widthcentpercentminusxx'],
'fk_user_creat' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'picto' => 'user', 'enabled' => 1, 'position' => 140, 'notnull' => 1, 'visible' => 0, 'foreignkey' => 'user.rowid'],
'fk_user_modif' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'picto' => 'user', 'enabled' => 1, 'position' => 150, 'notnull' => 0, 'visible' => 0, 'foreignkey' => 'user.rowid'],
'rowid' => ['type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'position' => 1, 'notnull' => 1, 'visible' => 0, 'noteditable' => 1, 'index' => 1, 'comment' => 'Id'],
'ref' => ['type' => 'varchar(128)', 'label' => 'Ref', 'enabled' => 1, 'position' => 10, 'notnull' => 1, 'visible' => 4, 'noteditable' => 1, 'default' => '(PROV)', 'index' =>1, 'searchall' => 1, 'showoncombobox' => 1, 'validate' => 1, 'comment' => 'Reference of object'],
'ref_ext' => ['type' => 'varchar(128)', 'label' => 'RefExt', 'enabled' => 1, 'position' => 20, 'notnull' => 0, 'visible' => 0],
'entity' => ['type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'position' => 30, 'notnull' => 1, 'visible' => 0, 'index' => 1],
'date_creation' => ['type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'position' => 40, 'notnull' => 1, 'visible' => 2],
'tms' => ['type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'position' => 50, 'notnull' => 0, 'visible' => 0],
'import_key' => ['type' => 'varchar(14)', 'label' => 'ImportId', 'enabled' => 1, 'position' => 60, 'notnull' => 0, 'visible' => 0],
'status' => ['type' => 'smallint', 'label' => 'Status', 'enabled' => 1, 'position' => 160, 'notnull' => 1, 'visible' => 2, 'default' => 0, 'index' => 1, 'arrayofkeyval' => [0 => 'StatusDraft', 1 => 'ValidatePendingAssignment', 10 => 'Assign'], 'css' => 'minwidth100 maxwidth300 widthcentpercentminusxx'],
'label' => ['type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'position' => 70, 'notnull' => 1, 'visible' => 5, 'searchall' => 1, 'css' => 'minwidth100 maxwidth300 widthcentpercentminusxx', 'cssview' => 'wordbreak', 'showoncombobox' => 2, 'validate' => 1],
'short_url' => ['type' => 'url', 'label' => 'ShortUrl', 'enabled' => 1, 'position' => 80, 'notnull' => 0, 'visible' => 1, 'copytoclipboard' => 1, 'css' => 'minwidth100 maxwidth300 widthcentpercentminusxx nowrap'],
'original_url' => ['type' => 'url', 'label' => 'OriginalUrl', 'enabled' => 1, 'position' => 90, 'notnull' => 0, 'visible' => 1, 'copytoclipboard' => 1, 'css' => 'minwidth100 maxwidth300 widthcentpercentminusxx nowrap'],
'type' => ['type' => 'sellist:c_shortener_url_type:label', 'label' => 'UrlType', 'enabled' => 1, 'position' => 100, 'notnull' => 0, 'visible' => 1, 'css' => 'maxwidth150 widthcentpercentminusxx'],
'methode' => ['type' => 'select', 'label' => 'UrlMethode', 'enabled' => 1, 'position' => 110, 'notnull' => 0, 'visible' => 5, 'arrayofkeyval' => ['' => '', 'yourls' => 'YOURLS', 'wordpress' => 'WordPress'], 'css' => 'maxwidth200 widthcentpercentminusxx', 'csslist' => 'minwidth150 center', 'help' => 'UrlMethodeDescription'],
'element_type' => ['type' => 'select', 'label' => 'ElementType', 'enabled' => 1, 'position' => 120, 'notnull' => 0, 'visible' => 1, 'arrayofkeyval' => ['' => ''], 'css' => 'maxwidth150 widthcentpercentminusxx'],
'fk_element' => ['type' => 'integer', 'label' => 'FkElement', 'enabled' => 1, 'position' => 130, 'notnull' => 0, 'visible' => 1, 'index' => 1, 'css' => 'minwidth200 maxwidth300 widthcentpercentminusxx'],
'fk_easyurl_urlexport' => ['type' => 'integer', 'label' => 'UrlExport', 'enabled' => 1, 'position' => 140, 'notnull' => 0, 'visible' => 0, 'foreignkey' => 'easyurl_urlexport.rowid'],
'fk_user_creat' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserAuthor', 'picto' => 'user', 'enabled' => 1, 'position' => 150, 'notnull' => 1, 'visible' => 0, 'foreignkey' => 'user.rowid'],
'fk_user_modif' => ['type' => 'integer:User:user/class/user.class.php', 'label' => 'UserModif', 'picto' => 'user', 'enabled' => 1, 'position' => 160, 'notnull' => 0, 'visible' => 0, 'foreignkey' => 'user.rowid'],
];

/**
Expand Down Expand Up @@ -201,6 +202,11 @@ class Shortener extends SaturneObject
*/
public $fk_element;

/**
* @var int|null URL Export
*/
public $fk_easyurl_urlexport;

/**
* @var int User ID
*/
Expand Down
75 changes: 75 additions & 0 deletions class/urlexport.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php
/* Copyright (C) 2021-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/>.
*/

/**
* \file class/shortener.class.php
* \ingroup easyurl
* \brief This file is a CRUD class file for Shortener (Create/Read/Update/Delete)
*/

// Load Saturne libraries
require_once __DIR__ . '/../../saturne/class/saturnedocuments.class.php';

/**
* Class for Shortener
*/
class UrlExport extends SaturneDocuments
{
/**
* @var string Module name
*/
public $module = 'easyurl';

/**
* @var string Element type of object
*/
public $element = 'urlexport';

/**
* Constructor.
*
* @param DoliDb $db Database handler.
*/
public function __construct(DoliDB $db)
{
parent::__construct($db, $this->module, $this->element);
}

public function generateFile()
{

global $conf, $user;

require_once __DIR__ . '/../class/shortener.class.php';

$shorteners = new Shortener($this->db);
$shorteners = $shorteners->fetchAll('', '', 0, 0, ['t.fk_easyurl_urlexport' => $this->id]);

$upload_dir = $conf->easyurl->multidir_output[$conf->entity] . '/' . $this->element;
dol_mkdir($upload_dir);
$fileName = dol_print_date(dol_now(), 'dayxcard') . '_' . $this->ref . '_exporturl.csv';
$fp = fopen($upload_dir . '/' . $fileName, 'w');
fputcsv($fp, [1 => 'ref' . ';' . 'label' . ';' . 'original_url' . ';' . 'short_url']);
foreach ($shorteners as $key => $shortener) {
fputcsv($fp, [$key => $shortener->ref . ';' . $shortener->label . ';' . $shortener->original_url . ';' . $shortener->short_url]);
}
fclose($fp);
$this->last_main_doc = $fileName;
$this->update($user);
}

}
Loading

0 comments on commit 19e77da

Please sign in to comment.