25require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $TRIGGER_PREFIX =
'OBJECTLINK';
43 public $element =
'objectlink';
48 public $table_element =
'element_element';
93 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target,";
94 $sql .=
" targettype, relationtype FROM";
95 $sql .=
" ".MAIN_DB_PREFIX.$this->table_element;
96 $sql .=
" WHERE rowid = ".((int) $rowid);
98 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
99 $result = $this->db->query($sql);
101 $obj = $this->db->fetch_object($result);
103 $this->
id = $obj->rowid;
106 $this->fk_source = (int) $obj->fk_source;
107 $this->sourcetype = (string) $obj->sourcetype;
108 $this->fk_target = (int) $obj->fk_target;
109 $this->targettype = (string) $obj->targettype;
110 $this->relationtype = $obj->relationtype;
114 $this->error =
'Object link with id '.((string) $rowid).
' not found sql='.$sql;
118 $this->error = $this->db->error();
133 public function fetchByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype =
null)
135 $sql =
"SELECT rowid, fk_source, sourcetype, fk_target,";
136 $sql .=
" targettype, relationtype FROM";
137 $sql .=
" ".MAIN_DB_PREFIX.$this->table_element;
138 $sql .=
" WHERE fk_source=".((int) $fk_source);
139 $sql .=
" AND sourcetype='".$this->db->escape($sourcetype).
"'";
140 $sql .=
" AND fk_target=".((int) $fk_target);
141 $sql .=
" AND targettype='".$this->db->escape($targettype).
"'";
143 $sql .=
" AND relationtype='".$this->db->escape($relationtype).
"'";
146 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
147 $result = $this->db->query($sql);
149 $obj = $this->db->fetch_object($result);
151 $this->
id = $obj->rowid;
154 $this->fk_source = (int) $obj->fk_source;
155 $this->sourcetype = (string) $obj->sourcetype;
156 $this->fk_target = (int) $obj->fk_target;
157 $this->targettype = (string) $obj->targettype;
158 $this->relationtype = $obj->relationtype;
162 $this->error =
'Object link not found sql='.$sql;
166 $this->error = $this->db->error();
178 public function delete($user, $notrigger = 0)
181 global $conf, $langs;
182 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
186 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
192 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_DELETE', $user);
201 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
202 $res = $this->db->query($sql);
205 $this->error = $this->db->lasterror();
206 $this->errors[] = $this->error;
207 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
212 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
216 $this->db->rollback();
233 public function create($user, $fk_source, $sourcetype, $fk_target, $targettype, $relationtype =
null, $notrigger = 0)
235 global $conf, $langs;
238 $alreadyexists = $this->
fetchByValues($fk_source, $sourcetype, $fk_target, $targettype, $relationtype);
239 if ($alreadyexists == 1) {
244 $sourceobject = $this->
_makeobject($fk_source, $sourcetype);
245 if ($sourceobject < 0 ) {
246 $this->error =
"Error when looking for Object id=".$fk_source.
" of type=".$sourcetype;
249 if ($sourceobject == 0 ) {
250 $this->error =
"Object id ".$fk_source.
" of type ".$sourcetype.
" does not exist";
254 $targetobject = $this->
_makeobject($fk_target, $targettype);
255 if ($targetobject < 0 ) {
256 $this->error =
"Error when looking for Object id=".$fk_target.
" of type=".$targettype;
259 if ($targetobject == 0 ) {
260 $this->error =
"Object id ".$fk_target.
" of type ".$targettype.
" does not exist";
264 dol_syslog(get_class($this).
"::create user=".$user->id);
270 $result = $this->call_trigger($this->TRIGGER_PREFIX.
'_CREATE', $user);
277 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"$this->table_element";
279 $sql .=
" (fk_source, sourcetype, fk_target, targettype, relationtype )";
281 $sql .=
" (fk_source, sourcetype, fk_target, targettype )";
283 $sql .=
" VALUES (".((int) $this->fk_source).
", '".$this->db->escape($sourcetype).
"', ";
284 $sql .= ((int) $this->fk_target).
", '".$this->db->escape($targettype).
"'";
286 $sql .=
", '".$this->db->escape($relationtype).
"'";
290 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
291 $resql = $this->db->query($sql);
296 $this->error = $this->db->lasterror();
297 $this->db->rollback();
313 if ($objecttype ==
'adherent') {
314 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/adherent.class.php';
315 $newobject =
new Adherent($this->db);
316 $result = $newobject->fetch($objectid);
319 if ($objecttype ==
'commande') {
320 require_once DOL_DOCUMENT_ROOT.
'/commande/class/commande.class.php';
321 $newobject =
new Commande($this->db);
322 $result = $newobject->fetch($objectid);
325 if ($objecttype ==
'facture') {
326 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
327 $newobject =
new Facture($this->db);
328 $result = $newobject->fetch($objectid);
331 if ($objecttype ==
'propal') {
332 require_once DOL_DOCUMENT_ROOT.
'/comm/propal/class/propal.class.php';
333 $newobject =
new Propal($this->db);
334 $result = $newobject->fetch($objectid);
337 if ($objecttype ==
'subscription') {
338 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
340 $result = $newobject->fetch($objectid);
343 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,...
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.