Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#49 [Hook] add: unassign shortener action and fix edit action #54

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion class/actions_easyurl.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

// Load EasyURL libraries
require_once __DIR__ . '/../lib/easyurl_function.lib.php';
require_once __DIR__ . '/shortener.class.php';

/**
* Class ActionsEasyurl
Expand Down Expand Up @@ -163,7 +164,7 @@ public function printCommonFooter(array $parameters): int
*/
public function doActions(array $parameters, $object, string $action): int
{
global $conf, $user;
global $conf, $langs, $user;

if (in_array($parameters['currentcontext'], ['propalcard', 'ordercard', 'invoicecard', 'contractcard', 'interventioncard'])) {
if ($action == 'set_easy_url') {
Expand All @@ -190,6 +191,22 @@ public function doActions(array $parameters, $object, string $action): int

dol_set_user_param($this->db, $conf, $user, $tabParam);
}

if ($action == 'unassignShortener') {
$shortenerID = GETPOST('shortener_id');
$shortener = new Shortener($this->db);
$shortener->fetch($shortenerID);

$shortener->status = Shortener::STATUS_VALIDATED;
$shortener->element_type = '';
$shortener->fk_element = null;
$shortener->update($user, true);
$shortener->call_trigger('SHORTENER_UNASSIGN', $user);

setEventMessages($langs->trans('UnassignShortenerSuccess', $shortener->ref), []);
header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id);
exit;
}
}
}
}
Expand Down
27 changes: 24 additions & 3 deletions class/shortener.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Shortener extends SaturneObject
'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'],
'short_url' => ['type' => 'url', 'label' => 'ShortUrl', 'enabled' => 1, 'position' => 80, 'notnull' => 0, 'visible' => 1, 'noteditable' => 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'],
Expand Down Expand Up @@ -281,6 +281,26 @@ public function setCategories($categories): string
return '';
}

/**
* Write information of trigger description
*
* @param SaturneObject $object Object calling the trigger
* @return string Description to display in actioncomm->note_private
*/
public function getTriggerDescription(SaturneObject $object): string
{
global $langs;

$ret = parent::getTriggerDescription($object);
$ret .= (dol_strlen($object->short_url) > 0 ? $langs->transnoentities('ShortUrl') . ' : ' . $object->short_url . '</br>' : '');
$ret .= (dol_strlen($object->original_url) > 0 ? $langs->transnoentities('OriginalUrl') . ' : ' . $object->original_url . '</br>' : '');
$ret .= (!empty($object->methode) ? $langs->transnoentities('UrlMethode') . ' : ' . $object->methode . '</br>' : '');
$ret .= (!empty($object->element_type) ? $langs->transnoentities('ElementType') . ' : ' . $object->element_type . '</br>' : '');
$ret .= (!empty($object->fk_element) ? $langs->transnoentities('FkElement') . ' : ' . $object->fk_element . '</br>' : '');

return $ret;
}

/**
* Load dashboard info
*
Expand Down Expand Up @@ -442,7 +462,7 @@ public function displayObjectDetails(CommonObject $object): string
$out .= $form->textwithpicto('', $langs->trans('ShowQRCode'));
$out .= '</td>';
$out .= '<td>' . $langs->trans('OriginalUrl') . '</td>';
$out .= '<td class="center">' . dolButtonToOpenUrlInDialogPopup('assignShortener', $langs->transnoentities('AssignShortener'), '<span class="fa fa fa-link valignmiddle btnTitle-icon" title="' . $langs->trans('Assign') . '"></span>', '/custom/easyurl/view/shortener/shortener_card.php?element_type=' . $element_type . '&fk_element=' . $object->id . '&from_element=1&action=edit_assign&backtopage=' . urlencode($_SERVER['PHP_SELF'] . '?id=' . $object->id), '', 'btnTitle') . '</td>';
$out .= '<td class="center">' . dolButtonToOpenUrlInDialogPopup('assignShortener', $langs->transnoentities('AssignShortener'), '<span class="fas fa-link fa-2x valignmiddle btnTitle-icon" title="' . $langs->trans('Assign') . '"></span>', '/custom/easyurl/view/shortener/shortener_card.php?element_type=' . $element_type . '&fk_element=' . $object->id . '&from_element=1&action=edit_assign', '', 'btnTitle') . '</td>';
$out .= '</thead></tr>';
$out .= '<tbody>';

Expand All @@ -453,7 +473,8 @@ public function displayObjectDetails(CommonObject $object): string
$out .= '<td class="minwidth100">' . getDictionaryValue('c_shortener_url_type', 'label', $shortener->type) . '</td>';
$out .= '<td>' . ($user->conf->EASYURL_SHOW_QRCODE ? saturne_show_medias_linked('easyurl', $conf->easyurl->multidir_output[$conf->entity] . '/shortener/' . $shortener->ref . '/qrcode/', 'small', 1, 0, 0, 0, 80, 80, 0, 0, 1, 'shortener/'. $shortener->ref . '/qrcode/', $shortener, '', 0, 0) : $shortener->showOutputField($this->fields['short_url'], 'short_url', $shortener->short_url)) . '</td>';
$out .= '<td>' . $shortener->showOutputField($this->fields['original_url'], 'original_url', $shortener->original_url) . '</td>';
$out .= '<td class="center">' . ($user->rights->easyurl->shortener->write > 0 ? '<a class="editfielda" href="' . dol_buildpath('/custom/easyurl/view/shortener/shortener_card.php?id='. $shortener->id . '&element_type=' . $element_type . '&fk_element=' . $object->id . '&from_element_type=1&token=' . newToken() . '&action=edit&backtopage=' . urlencode($_SERVER['PHP_SELF'] . '?id=' . $object->id), 1) . '">' . img_edit($langs->trans('Modify')) . '</a>' : '') . '</td>';
$out .= '<td class="center">' . ($user->rights->easyurl->shortener->write > 0 ? '<a class="editfielda" href="' . dol_buildpath('/custom/easyurl/view/shortener/shortener_card.php?id='. $shortener->id . '&element_type=' . $element_type . '&fk_element=' . $object->id . '&from_element=1&token=' . newToken() . '&action=edit&backtopage=' . urlencode($_SERVER['PHP_SELF'] . '?id=' . $object->id), 1) . '">' . img_picto($langs->trans('Modify'), 'edit', 'class="paddingright"') . '</a>' : '');
$out .= ($user->rights->easyurl->shortener->delete > 0 ? '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&shortener_id=' . $shortener->id . '&action=unassignShortener&token=' . newToken() . '">' . img_picto($langs->trans('Unassign'), 'unlink') . '</a>' : '') . '</td>';
$out .= '</tr>';
}
} else {
Expand Down
2 changes: 1 addition & 1 deletion core/modules/modEasyURL.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function __construct($db)
$this->hidden = false;

// List of module class names as string that must be enabled if this module is enabled. Example: array('always1'=>'modModuleToEnable1','always2'=>'modModuleToEnable2', 'FR1'=>'modModuleToEnableFR'...)
$this->depends = ['modAgenda', 'modSaturne'];
$this->depends = ['modAgenda', 'modSaturne', 'modExport'];
$this->requiredby = []; // List of module class names as string to disable if this one is disabled. Example: array('modModuleToDisable1', ...)
$this->conflictwith = []; // List of module class names as string this module is in conflict with. Example: array('modModuleToDisable1', ...)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,12 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
$actioncomm->create($user);
break;

// UNASSIGN
case 'SHORTENER_UNASSIGN' :
$actioncomm->label = $langs->trans('ObjectUnAssignTrigger', $langs->transnoentities(ucfirst($object->element)), $object->ref);
$actioncomm->create($user);
break;

// DELETE
case 'SHORTENER_DELETE' :
$actioncomm->label = $langs->trans('ObjectDeleteTrigger', $langs->transnoentities(ucfirst($object->element)), $object->ref);
Expand Down
3 changes: 3 additions & 0 deletions langs/fr_FR/easyurl.lang
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ NoLinkedElement = Aucun élément lié
ShortenerRepartition = Répartition des raccourcissements d'URLs par %s
ShortenerUrlType = Liste des types d'URLs
ShowQRCode = Afficher le QRCode de l'URL raccourcie
Unassign = Désaffecter
UnassignShortenerSuccess = Désaffectation du raccourcissement d'URL <strong>%s</strong>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Désaffectation du raccourci URL"

ObjectUnAssignTrigger = %s %s désaffectée
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Si c'est UN url désaffecté alors il n'y a pas de e à la fin

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aussi si c'est une traduction générique d'objet elle devrait plutôt aller sur Saturne


# Fiels - Champ
ShortUrl = URL raccourcie
Expand Down
6 changes: 4 additions & 2 deletions view/shortener/shortener_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,8 +224,10 @@
$object->fields['fk_element']['label'] = $langs->trans($objectsMetadata['langs']);

if (GETPOST('from_element', 'int') > 0) {
$object->fields['element_type']['visible'] = 0;
$object->fields['fk_element']['visible'] = 0;
$object->fields['label']['noteditable'] = 1;
$object->fields['element_type']['noteditable'] = 1;
$object->fields['fk_element']['picto'] = '';
$object->fields['fk_element']['noteditable'] = 1;
}
}

Expand Down