Skip to content

Commit

Permalink
#49 [Hook] add: unassign shortener action trigger and disable fields
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-eoxia committed Apr 11, 2024
1 parent 17bd982 commit 68d10df
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 5 deletions.
3 changes: 2 additions & 1 deletion class/actions_easyurl.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ public function doActions(array $parameters, $object, string $action): int
$shortener->status = Shortener::STATUS_VALIDATED;
$shortener->element_type = '';
$shortener->fk_element = null;
$shortener->update($user);
$shortener->update($user, true);
$shortener->call_trigger('SHORTENER_UNASSIGN', $user);

setEventMessages($langs->trans('UnassignShortenerSuccess', $shortener->ref), []);
header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id);
Expand Down
22 changes: 21 additions & 1 deletion 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
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ 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);
echo '<pre>'; print_r( $actioncomm ); echo '</pre>'; exit;
$actioncomm->create($user);
break;

// DELETE
case 'SHORTENER_DELETE' :
$actioncomm->label = $langs->trans('ObjectDeleteTrigger', $langs->transnoentities(ucfirst($object->element)), $object->ref);
Expand Down
1 change: 1 addition & 0 deletions langs/fr_FR/easyurl.lang
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ 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>
ObjectUnAssignTrigger = %s %s désaffectée

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

if (GETPOST('from_element', 'int') > 0) {
$object->fields['short_url']['visible'] = 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

0 comments on commit 68d10df

Please sign in to comment.