mirror of
https://github.com/Dolibarr/dolibarr.git
synced 2025-12-05 17:18:13 +01:00
New: add possibility to linked other objects from external modules
This commit is contained in:
@@ -86,6 +86,7 @@ class Commande extends CommonObject
|
||||
|
||||
var $origin;
|
||||
var $origin_id;
|
||||
var $linked_objects=array();
|
||||
|
||||
var $user_author_id;
|
||||
|
||||
@@ -706,37 +707,44 @@ class Commande extends CommonObject
|
||||
if ($this->id)
|
||||
{
|
||||
$this->ref="(PROV".$this->id.")";
|
||||
|
||||
// Add linked object
|
||||
if ($this->origin && $this->origin_id)
|
||||
|
||||
// Add object linked
|
||||
if (is_array($this->linked_objects) && ! empty($this->linked_objects))
|
||||
{
|
||||
$ret = $this->add_object_linked();
|
||||
if (! $ret) dol_print_error($this->db);
|
||||
}
|
||||
|
||||
// TODO mutualiser
|
||||
if ($this->origin == 'propal' && $this->origin_id)
|
||||
{
|
||||
// On recupere les differents contact interne et externe
|
||||
$prop = new Propal($this->db, $this->socid, $this->origin_id);
|
||||
|
||||
// On recupere le commercial suivi propale
|
||||
$this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL');
|
||||
|
||||
if ($this->userid)
|
||||
{
|
||||
//On passe le commercial suivi propale en commercial suivi commande
|
||||
$this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal');
|
||||
}
|
||||
|
||||
// On recupere le contact client suivi propale
|
||||
$this->contactid = $prop->getIdcontact('external', 'CUSTOMER');
|
||||
|
||||
if ($this->contactid)
|
||||
{
|
||||
//On passe le contact client suivi propale en contact client suivi commande
|
||||
$this->add_contact($this->contactid[0], 'CUSTOMER', 'external');
|
||||
}
|
||||
foreach($this->linked_objects as $origin => $origin_id)
|
||||
{
|
||||
$ret = $this->add_object_linked($origin, $origin_id);
|
||||
if (! $ret)
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
$error++;
|
||||
}
|
||||
|
||||
// TODO mutualiser
|
||||
if ($origin == 'propal' && $origin_id)
|
||||
{
|
||||
// On recupere les differents contact interne et externe
|
||||
$prop = new Propal($this->db, $this->socid, $origin_id);
|
||||
|
||||
// On recupere le commercial suivi propale
|
||||
$this->userid = $prop->getIdcontact('internal', 'SALESREPFOLL');
|
||||
|
||||
if ($this->userid)
|
||||
{
|
||||
//On passe le commercial suivi propale en commercial suivi commande
|
||||
$this->add_contact($this->userid[0], 'SALESREPFOLL', 'internal');
|
||||
}
|
||||
|
||||
// On recupere le contact client suivi propale
|
||||
$this->contactid = $prop->getIdcontact('external', 'CUSTOMER');
|
||||
|
||||
if ($this->contactid)
|
||||
{
|
||||
//On passe le contact client suivi propale en contact client suivi commande
|
||||
$this->add_contact($this->contactid[0], 'CUSTOMER', 'external');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
/* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2011 Philippe Grand <philippe.grand@atoo-net.com>
|
||||
@@ -229,6 +229,13 @@ if ($action == 'add' && $user->rights->commande->creer)
|
||||
|
||||
$object->origin = $_POST['origin'];
|
||||
$object->origin_id = $_POST['originid'];
|
||||
|
||||
// Possibility to add external linked objects with hooks
|
||||
$object->linked_objects[$object->origin] = $object->origin_id;
|
||||
if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects']))
|
||||
{
|
||||
$object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
|
||||
}
|
||||
|
||||
$object_id = $object->create($user);
|
||||
|
||||
@@ -1368,7 +1375,7 @@ if ($action == 'create' && $user->rights->commande->creer)
|
||||
}
|
||||
|
||||
// Other attributes
|
||||
$parameters=array('colspan' => ' colspan="3"');
|
||||
$parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
|
||||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
|
||||
if (empty($reshook) && ! empty($extrafields->attribute_label))
|
||||
{
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
|
||||
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
|
||||
* Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
|
||||
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
|
||||
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
|
||||
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@2byte.es>
|
||||
* Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
|
||||
@@ -742,6 +742,13 @@ if ($action == 'add' && $user->rights->facture->creer)
|
||||
|
||||
$object->origin = $_POST['origin'];
|
||||
$object->origin_id = $_POST['originid'];
|
||||
|
||||
// Possibility to add external linked objects with hooks
|
||||
$object->linked_objects[$object->origin] = $object->origin_id;
|
||||
if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects']))
|
||||
{
|
||||
$object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']);
|
||||
}
|
||||
|
||||
$id = $object->create($user);
|
||||
|
||||
@@ -1802,7 +1809,7 @@ if ($action == 'create')
|
||||
}
|
||||
|
||||
// Other attributes
|
||||
$parameters=array('colspan' => ' colspan="3"');
|
||||
$parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
|
||||
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
|
||||
if (empty($reshook) && ! empty($extrafields->attribute_label))
|
||||
{
|
||||
|
||||
@@ -90,6 +90,7 @@ class Facture extends CommonObject
|
||||
var $fk_facture_source;
|
||||
var $origin;
|
||||
var $origin_id;
|
||||
var $linked_objects=array();
|
||||
var $fk_project;
|
||||
var $date_lim_reglement;
|
||||
var $cond_reglement_id; // Id in llx_c_paiement
|
||||
@@ -242,14 +243,17 @@ class Facture extends CommonObject
|
||||
if (! $resql) $error++;
|
||||
|
||||
// Add object linked
|
||||
if (! $error && $this->id && $this->origin && $this->origin_id)
|
||||
if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects))
|
||||
{
|
||||
$ret = $this->add_object_linked();
|
||||
if (! $ret)
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
$error++;
|
||||
}
|
||||
foreach($this->linked_objects as $origin => $origin_id)
|
||||
{
|
||||
$ret = $this->add_object_linked($origin, $origin_id);
|
||||
if (! $ret)
|
||||
{
|
||||
dol_print_error($this->db);
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1458,12 +1458,17 @@ abstract class CommonObject
|
||||
}
|
||||
|
||||
/**
|
||||
* Add objects linked in llx_element_element.
|
||||
* Add objects linked in llx_element_element.
|
||||
*
|
||||
* @return int <=0 if KO, >0 if OK
|
||||
* @param string $origin Linked element type
|
||||
* @param int $origin_id Linked element id
|
||||
* @return int <=0 if KO, >0 if OK
|
||||
*/
|
||||
function add_object_linked()
|
||||
function add_object_linked($origin=null, $origin_id=null)
|
||||
{
|
||||
$origin = (! empty($origin) ? $origin : $this->origin);
|
||||
$origin_id = (! empty($origin_id) ? $origin_id : $this->origin_id);
|
||||
|
||||
$this->db->begin();
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element (";
|
||||
@@ -1472,8 +1477,8 @@ abstract class CommonObject
|
||||
$sql.= ", fk_target";
|
||||
$sql.= ", targettype";
|
||||
$sql.= ") VALUES (";
|
||||
$sql.= $this->origin_id;
|
||||
$sql.= ", '".$this->origin."'";
|
||||
$sql.= $origin_id;
|
||||
$sql.= ", '".$origin."'";
|
||||
$sql.= ", ".$this->id;
|
||||
$sql.= ", '".$this->element."'";
|
||||
$sql.= ")";
|
||||
|
||||
Reference in New Issue
Block a user