Ajouter "Objets liés" dans "Ressources"

Bonjour,

Je suis sous Dolibarr 10.0.6 PHP 7.3.27
Je voudrais utiliser le module Ressource pour des outils/matériel informatique interne
Pour ajouter marque/numero de série/modèle, j’ai utilisé les attributs supplémentaires,
Pour lié à une personne, j’utilise Contact/Adresse,
Mais j’aimerais lié chaque objet à une commande fournisseur, pour, en cas, de problème, connaître directement la commande fournisseur de la ressource,
J’ai ajouté le tableau « Objets liés » et « Les derniers évenements crées »
Mais il me manque l’action et l’affichage « Lier à … », il n’est pas affiché,

Pour l’instant, voici les modifs dans le card.php de ressource:

include DOL_DOCUMENT_ROOT.’/core/actions_dellink.inc.php’; // Must be include, not include_once
$upload_dir = $conf->resource->dir_output;
include DOL_DOCUMENT_ROOT.’/core/actions_builddoc.inc.php’;

et

print ‹ 

 ›;
print ‹  ›; // ancre

		// Show links to link elements
		$linktoelem = $form->showLinkToObjectBlock($object, null, array('ticket'));
		$somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);

		print '</div><div class="fichehalfright"><div class="ficheaddleft">';

		// List of actions on element
		include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
		$formactions = new FormActions($db);
		$somethingshown = $formactions->showactions($object, 'ticket', $socid, 1);

		print '</div></div></div>';

Merci de votre aide
Cdlt

Bonjour,
Est ce que quelqu’un aurait une idée?
J’ai déterminé que la ligne
$linktoelem = $form->showLinkToObjectBlock($object, null, array(‹ contrat ›));
affiche le « Lié à » sur le card.php du module Contrat par exemple
mais il ne s’affiche pas sur le module Ressources

merci de votre retour

J’ai trouvé la définition du hooks dans html.form.class.php mais je ne comprend pas pourquoi il ne se déclenche pas dans le module Ressources
public function showLinkToObjectBlock($object, $restrictlinksto = array(), $excludelinksto = array())
{
global $conf, $langs, $hookmanager;
global $bc, $action;

	$linktoelem='';
	$linktoelemlist='';
	$listofidcompanytoscan='';

	if (! is_object($object->thirdparty)) $object->fetch_thirdparty();

	$possiblelinks=array();
	if (is_object($object->thirdparty) && ! empty($object->thirdparty->id) && $object->thirdparty->id > 0)
	{
		$listofidcompanytoscan=$object->thirdparty->id;
		if (($object->thirdparty->parent > 0) && ! empty($conf->global->THIRDPARTY_INCLUDE_PARENT_IN_LINKTO)) $listofidcompanytoscan.=','.$object->thirdparty->parent;
		if (($object->fk_project > 0) && ! empty($conf->global->THIRDPARTY_INCLUDE_PROJECT_THIRDPARY_IN_LINKTO))
		{
			include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
			$tmpproject=new Project($this->db);
			$tmpproject->fetch($object->fk_project);
			if ($tmpproject->socid > 0 && ($tmpproject->socid != $object->thirdparty->id)) $listofidcompanytoscan.=','.$tmpproject->socid;
			unset($tmpproject);
		}

		$possiblelinks=array(
			'propal'=>array('enabled'=>$conf->propal->enabled, 'perms'=>1, 'label'=>'LinkToProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('propal').')'),
			'order'=>array('enabled'=>$conf->commande->enabled, 'perms'=>1, 'label'=>'LinkToOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande').')'),
			'invoice'=>array('enabled'=>$conf->facture->enabled, 'perms'=>1, 'label'=>'LinkToInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_client, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('invoice').')'),
			'invoice_template'=>array('enabled'=>$conf->facture->enabled, 'perms'=>1, 'label'=>'LinkToTemplateInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.titre as ref, t.total as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_rec as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('invoice').')'),
			'contrat'=>array('enabled'=>$conf->contrat->enabled , 'perms'=>1, 'label'=>'LinkToContract', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, '' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('contract').')'),
			'fichinter'=>array('enabled'=>$conf->ficheinter->enabled, 'perms'=>1, 'label'=>'LinkToIntervention', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('intervention').')'),
			'supplier_proposal'=>array('enabled'=>$conf->supplier_proposal->enabled , 'perms'=>1, 'label'=>'LinkToSupplierProposal', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, '' as ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."supplier_proposal as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('supplier_proposal').')'),
			'order_supplier'=>array('enabled'=>$conf->supplier_order->enabled , 'perms'=>1, 'label'=>'LinkToSupplierOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('commande_fournisseur').')'),
			'invoice_supplier'=>array('enabled'=>$conf->supplier_invoice->enabled , 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('facture_fourn').')'),
			'ticket'=>array('enabled'=>$conf->ticket->enabled , 'perms'=>1, 'label'=>'LinkToTicket', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.track_id, '0' as total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."ticket as t WHERE t.fk_soc = s.rowid AND t.fk_soc IN (".$listofidcompanytoscan.') AND t.entity IN ('.getEntity('ticket').')')
		);
	}

	// Can complete the possiblelink array
	$hookmanager->initHooks(array('commonobject'));
	$parameters=array('listofidcompanytoscan' => $listofidcompanytoscan);

	if (! empty($listofidcompanytoscan))  // If empty, we don't have criteria to scan the object we can link to
	{
        $reshook=$hookmanager->executeHooks('showLinkToObjectBlock', $parameters, $object, $action);    // Note that $action and $object may have been modified by hook
	}

	if (empty($reshook))
	{
		if (is_array($hookmanager->resArray) && count($hookmanager->resArray))
		{
			$possiblelinks=array_merge($possiblelinks, $hookmanager->resArray);
		}
	}
	elseif ($reshook > 0)
	{
		if (is_array($hookmanager->resArray) && count($hookmanager->resArray))
		{
			$possiblelinks=$hookmanager->resArray;
		}
	}

	foreach($possiblelinks as $key => $possiblelink)
	{
		$num = 0;

		if (empty($possiblelink['enabled'])) continue;

		if (! empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || ! in_array($key, $excludelinksto)))
		{
			print '<div id="'.$key.'list"'.(empty($conf->use_javascript_ajax)?'':' style="display:none"').'>';
			$sql = $possiblelink['sql'];

			$resqllist = $this->db->query($sql);
			if ($resqllist)
			{
				$num = $this->db->num_rows($resqllist);
				$i = 0;

				print '<br>';
				print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formlinked'.$key.'">';
				print '<input type="hidden" name="action" value="addlink">';
				print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
				print '<input type="hidden" name="id" value="'.$object->id.'">';
				print '<input type="hidden" name="addlink" value="'.$key.'">';
				print '<table class="noborder">';
				print '<tr class="liste_titre">';
				print '<td class="nowrap"></td>';
				print '<td class="center">' . $langs->trans("Ref") . '</td>';
				print '<td class="left">' . $langs->trans("RefCustomer") . '</td>';
				print '<td class="right">' . $langs->trans("AmountHTShort") . '</td>';
				print '<td class="left">' . $langs->trans("Company") . '</td>';
				print '</tr>';
				while ($i < $num)
				{
					$objp = $this->db->fetch_object($resqllist);

					print '<tr class="oddeven">';
					print '<td class="left">';
					print '<input type="radio" name="idtolinkto" value=' . $objp->rowid . '>';
					print '</td>';
					print '<td class="center">' . $objp->ref . '</td>';
					print '<td>' . $objp->ref_client . '</td>';
					print '<td class="right">' . price($objp->total_ht) . '</td>';
					print '<td>' . $objp->name . '</td>';
					print '</tr>';
					$i++;
				}
				print '</table>';
				print '<div class="center"><input type="submit" class="button valignmiddle" value="' . $langs->trans('ToLink') . '">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="button" name="cancel" value="' . $langs->trans('Cancel') . '"></div>';

				print '</form>';
				$this->db->free($resqllist);
			} else {
				dol_print_error($this->db);
			}
			print '</div>';
			if ($num > 0)
			{
			}

			//$linktoelem.=($linktoelem?' &nbsp; ':'');
			if ($num > 0) $linktoelemlist.='<li><a href="#linkto'.$key.'" class="linkto dropdowncloseonclick" rel="'.$key.'">' . $langs->trans($possiblelink['label']) .' ('.$num.')</a></li>';
			//else $linktoelem.=$langs->trans($possiblelink['label']);
			else $linktoelemlist.='<li><span class="linktodisabled">' . $langs->trans($possiblelink['label']) . ' (0)</span></li>';
		}
	}

	if ($linktoelemlist)
	{
		$linktoelem='
		<dl class="dropdown" id="linktoobjectname">
		';
		if (! empty($conf->use_javascript_ajax)) $linktoelem.='<dt><a href="#linktoobjectname">'.$langs->trans("LinkTo").'...</a></dt>';
		$linktoelem.='<dd>
		<div class="multiselectlinkto">
		<ul class="ulselectedfields">'.$linktoelemlist.'
		</ul>
		</div>
		</dd>
		</dl>';
	}
	else
	{
		$linktoelem='';
	}

	if (! empty($conf->use_javascript_ajax))
	{
	  print '<!-- Add js to show linkto box -->
			<script>
			jQuery(document).ready(function() {
				jQuery(".linkto").click(function() {
					console.log("We choose to show/hide link for rel="+jQuery(this).attr(\'rel\'));
				    jQuery("#"+jQuery(this).attr(\'rel\')+"list").toggle();
					jQuery(this).toggle();
				});
			});
			</script>
	  ';
	}

	return $linktoelem;
}

Bonjour,

Pour info, la seule solution que j’ai trouvé est de créer un nouveau hook, modifié à partir du hook ShowLinkToObjectBlock