24require_once DOL_DOCUMENT_ROOT.
'/core/class/doldeprecationhandler.class.php';
33 const TRIGGER_PREFIX =
'OBJECTLINK';
37 public $element =
'objectlink';
42 public $table_element =
'element_element';
87 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target,";
88 $sql .=
" targettype, relationtype FROM";
89 $sql .=
" ".MAIN_DB_PREFIX.$this->table_element;
90 $sql .=
" WHERE rowid = ".((int) $rowid);
92 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
93 $result = $this->db->query($sql);
95 $obj = $this->db->fetch_object($result);
97 $this->
id = $obj->rowid;
100 $this->fk_source = (int) $obj->fk_source;
101 $this->sourcetype = (string) $obj->sourcetype;
102 $this->fk_target = (int) $obj->fk_target;
103 $this->targettype = (string) $obj->targettype;
104 $this->relationtype = $obj->relationtype;
108 $this->error =
'Object link with id '.((string) $rowid).
' not found sql='.$sql;
112 $this->error = $this->db->error();
127 public function fetchByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype =
null)
129 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target,";
130 $sql .=
" targettype, relationtype FROM";
131 $sql .=
" ".MAIN_DB_PREFIX.$this->table_element;
132 $sql .=
" WHERE fk_source=".((int) $fk_source);
133 $sql .=
" AND sourcetype='".$this->db->escape($sourcetype).
"'";
134 $sql .=
" AND fk_target=".((int) $fk_target);
135 $sql .=
" AND targettype='".$this->db->escape($targettype).
"'";
137 $sql .=
" AND relationtype='".$this->db->escape($relationtype).
"'";
140 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
141 $result = $this->db->query($sql);
143 $obj = $this->db->fetch_object($result);
145 $this->
id = $obj->rowid;
148 $this->fk_source = (int) $obj->fk_source;
149 $this->sourcetype = (string) $obj->sourcetype;
150 $this->fk_target = (int) $obj->fk_target;
151 $this->targettype = (string) $obj->targettype;
152 $this->relationtype = $obj->relationtype;
156 $this->error =
'Object link not found sql='.$sql;
160 $this->error = $this->db->error();
172 public function delete($user, $notrigger = 0)
175 global
$conf, $langs;
176 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
180 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
186 $result = $this->
call_trigger(self::TRIGGER_PREFIX.
'_DELETE', $user);
195 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
196 $res = $this->db->query($sql);
199 $this->error = $this->db->lasterror();
200 $this->errors[] = $this->error;
201 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
206 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
210 $this->db->rollback();
227 public function create($user, $fk_source, $sourcetype, $fk_target, $targettype, $relationtype =
null, $notrigger = 0)
229 global
$conf, $langs;
232 $alreadyexists = $this->
fetchByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype);
233 if ($alreadyexists == 1) {
238 $sourceobject = $this->
_makeobject($fk_source, $sourcetype);
239 if ($sourceobject < 0 ) {
240 $this->error =
"Error when looking for Object id=".$fk_source.
" of type=".$sourcetype;
243 if ($sourceobject == 0 ) {
244 $this->error =
"Object id ".$fk_source.
" of type ".$sourcetype.
" does not exist";
248 $targetobject = $this->
_makeobject($fk_target, $targettype);
249 if ($targetobject < 0 ) {
250 $this->error =
"Error when looking for Object id=".$fk_target.
" of type=".$targettype;
253 if ($targetobject == 0 ) {
254 $this->error =
"Object id ".$fk_target.
" of type ".$targettype.
" does not exist";
258 dol_syslog(get_class($this).
"::create user=".$user->id);
264 $result = $this->
call_trigger(self::TRIGGER_PREFIX.
'_CREATE', $user);
271 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"$this->table_element";
273 $sql .=
" (fk_source, sourcetype, fk_target, targettype, relationtype )";
275 $sql .=
" (fk_source, sourcetype, fk_target, targettype )";
277 $sql .=
" VALUES (".((int) $this->fk_source).
", '".$this->db->escape($sourcetype).
"', ";
278 $sql .= ((int) $this->fk_target).
", '".$this->db->escape($targettype).
"'";
280 $sql .=
", '".$this->db->escape($relationtype).
"'";
284 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
285 $resql = $this->db->query($sql);
290 $this->error = $this->db->lasterror();
291 $this->db->rollback();
307 if ($objecttype ==
'adherent') {
308 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
309 $newobject =
new Adherent($this->db);
310 $result = $newobject->fetch($objectid);
313 if ($objecttype ==
'commande') {
314 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
315 $newobject =
new Commande($this->db);
316 $result = $newobject->fetch($objectid);
319 if ($objecttype ==
'facture') {
320 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
321 $newobject =
new Facture($this->db);
322 $result = $newobject->fetch($objectid);
325 if ($objecttype ==
'propal') {
326 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
327 $newobject =
new Propal($this->db);
328 $result = $newobject->fetch($objectid);
331 if ($objecttype ==
'subscription') {
332 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
334 $result = $newobject->fetch($objectid);
337 dol_syslog(
"objectlink->_makeobject called with unknown objecttype=".$objecttype, LOG_ERR);
Class to manage members of a foundation.
Class to manage customers orders.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage invoices.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
__construct($db)
Constructor of the class.
_makeobject($objectid, $objecttype)
Creates an object of the right kind and try to fetch it to make sure the id exists.
fetch($rowid)
Get object link from database.
fetchByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype=null)
fetch object link By Values, not id
create($user, $fk_source, $sourcetype, $fk_target, $targettype, $relationtype=null, $notrigger=0)
Create object link.
Class to manage proposals.
Class to manage subscriptions of foundation members.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...