24require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
35 public $element =
'link';
40 public $table_element =
'links';
81 $langs->load(
"errors");
83 if (empty($this->label)) {
84 $this->label = trim(basename($this->url));
86 if (empty($this->datea)) {
89 $this->url = trim($this->url);
91 dol_syslog(get_class($this).
"::create ".$this->url);
94 if (empty($this->url)) {
95 $this->error = $langs->trans(
"NoURL");
101 $sql =
"INSERT INTO ".$this->db->prefix().
"links (entity, datea, url, label, objecttype, objectid)";
102 $sql .=
" VALUES (".$conf->entity.
", '".$this->db->idate($this->datea).
"'";
103 $sql .=
", '".$this->db->escape($this->url).
"'";
104 $sql .=
", '".$this->db->escape($this->label).
"'";
105 $sql .=
", '".$this->db->escape($this->objecttype).
"'";
106 $sql .=
", ".((int) $this->objectid).
")";
108 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
109 $result = $this->db->query($sql);
111 $this->
id = $this->db->last_insert_id($this->db->prefix().
"links");
125 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
129 dol_syslog(get_class($this).
"::Create echec update ".$this->error, LOG_ERR);
130 $this->db->rollback();
134 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
135 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->
name);
138 $this->error = $this->db->lasterror();
141 $this->db->rollback();
155 global $langs, $conf;
156 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
158 $langs->load(
"errors");
161 dol_syslog(get_class($this).
"::Update id = ".$this->
id.
" call_trigger = ".$call_trigger);
164 if (empty($this->url)) {
165 $this->error = $langs->trans(
"NoURL");
171 if (empty($this->label)) {
172 $this->label = basename($this->url);
174 $this->label = trim($this->label);
179 $sql =
"UPDATE ".$this->db->prefix().
"links SET ";
180 $sql .=
"entity = ".$conf->entity;
181 $sql .=
", datea = '".$this->db->idate(
dol_now()).
"'";
182 $sql .=
", url = '".$this->db->escape($this->url).
"'";
183 $sql .=
", label = '".$this->db->escape($this->label).
"'";
184 $sql .=
", objecttype = '".$this->db->escape($this->objecttype).
"'";
185 $sql .=
", objectid = ".$this->objectid;
186 $sql .=
" WHERE rowid = ".((int) $this->
id);
188 dol_syslog(get_class($this).
"::update sql = ".$sql);
189 $resql = $this->db->query($sql);
201 dol_syslog(get_class($this).
"::Update success");
206 $this->db->rollback();
210 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
212 $this->error = $langs->trans(
"ErrorDuplicateField");
215 $this->error = $langs->trans(
"Error sql").
"= $sql";
218 $this->db->rollback();
233 public function fetchAll(&$links, $objecttype, $objectid, $sortfield =
null, $sortorder =
null)
237 $sql =
"SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".$this->db->prefix().
"links";
238 $sql .=
" WHERE objecttype = '".$this->db->escape($objecttype).
"' AND objectid = ".((int) $objectid);
239 if ($conf->entity != 0) {
240 $sql .=
" AND entity = ".((int) $conf->entity);
243 if (empty($sortorder)) {
246 $sql .=
" ORDER BY ".$sortfield.
" ".$sortorder;
249 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
250 $resql = $this->db->query($sql);
252 $num = $this->db->num_rows($resql);
253 dol_syslog(get_class($this).
"::fetchAll num=".((
int) $num), LOG_DEBUG);
255 while ($obj = $this->db->fetch_object($resql)) {
256 $link =
new Link($this->db);
257 $link->id = $obj->rowid;
258 $link->entity = $obj->entity;
259 $link->datea = $this->db->jdate($obj->datea);
260 $link->url = $obj->url;
261 $link->label = $obj->label;
262 $link->objecttype = $obj->objecttype;
263 $link->objectid = $obj->objectid;
283 public static function count($dbs, $objecttype, $objectid)
287 $sql =
"SELECT COUNT(rowid) as nb FROM ".$dbs->prefix().
"links";
288 $sql .=
" WHERE objecttype = '".$dbs->escape($objecttype).
"' AND objectid = ".((int) $objectid);
289 if ($conf->entity != 0) {
290 $sql .=
" AND entity = ".$conf->entity;
293 $resql = $dbs->query($sql);
295 $obj = $dbs->fetch_object($resql);
309 public function fetch($rowid =
null)
317 $sql =
"SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".$this->db->prefix().
"links";
318 $sql .=
" WHERE rowid = ".((int) $rowid);
319 if ($conf->entity != 0) {
320 $sql .=
" AND entity = ".$conf->entity;
323 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
324 $resql = $this->db->query($sql);
326 if ($this->db->num_rows($resql) > 0) {
327 $obj = $this->db->fetch_object($resql);
329 $this->
id = $obj->rowid;
330 $this->entity = $obj->entity;
331 $this->datea = $this->db->jdate($obj->datea);
332 $this->url = $obj->url;
333 $this->label = $obj->label;
334 $this->objecttype = $obj->objecttype;
335 $this->objectid = $obj->objectid;
341 $this->error = $this->db->lasterror();
352 public function delete($user)
354 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
362 $this->db->rollback();
368 $sql =
"DELETE FROM ".$this->db->prefix().
"links";
369 $sql .=
" WHERE rowid = ".((int) $this->
id);
371 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
372 if (!$this->db->query($sql)) {
374 $this->error = $this->db->lasterror();
382 $this->db->rollback();
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
static count($dbs, $objecttype, $objectid)
Return nb of links.
fetch($rowid=null)
Loads a link from database.
update(User $user, $call_trigger=1)
Update parameters of third party.
__construct($db)
Constructor.
fetchAll(&$links, $objecttype, $objectid, $sortfield=null, $sortorder=null)
Loads all links from database.
create(User $user)
Create link in database.
Class to manage Dolibarr users.
clean_url($url, $http=1)
Clean an url string.
dol_now($mode='auto')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db name
Only used if Module[ID]Name translation string is not found.