25require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'link';
41 public $table_element =
'links';
96 $langs->load(
"errors");
98 if (empty($this->label)) {
99 $this->label = trim(basename($this->url));
101 if (empty($this->datea)) {
104 $this->url = trim($this->url);
106 dol_syslog(get_class($this).
"::create ".$this->url);
109 if (empty($this->url)) {
110 $this->error = $langs->trans(
"NoURL");
116 $sql =
"INSERT INTO ".$this->db->prefix().
"links (entity, datea, url, label, objecttype, objectid)";
117 $sql .=
" VALUES (".$conf->entity.
", '".$this->db->idate($this->datea).
"'";
118 $sql .=
", '".$this->db->escape($this->url).
"'";
119 $sql .=
", '".$this->db->escape($this->label).
"'";
120 $sql .=
", '".$this->db->escape($this->objecttype).
"'";
121 $sql .=
", ".((int) $this->objectid).
")";
123 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
124 $result = $this->db->query($sql);
126 $this->
id = $this->db->last_insert_id($this->db->prefix().
"links");
140 dol_syslog(get_class($this).
"::Create success id=".$this->
id);
144 dol_syslog(get_class($this).
"::Create echec update ".$this->error, LOG_ERR);
145 $this->db->rollback();
149 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
150 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->
name);
153 $this->error = $this->db->lasterror();
156 $this->db->rollback();
170 global $langs, $conf;
171 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
173 $langs->load(
"errors");
176 dol_syslog(get_class($this).
"::Update id = ".$this->
id.
" call_trigger = ".$call_trigger);
179 if (empty($this->url)) {
180 $this->error = $langs->trans(
"NoURL");
186 if (empty($this->label)) {
187 $this->label = basename($this->url);
189 $this->label = trim($this->label);
194 $sql =
"UPDATE ".$this->db->prefix().
"links SET ";
195 $sql .=
"entity = ".((int) $conf->entity);
196 $sql .=
", datea = '".$this->db->idate(
dol_now()).
"'";
197 $sql .=
", url = '".$this->db->escape($this->url).
"'";
198 $sql .=
", label = '".$this->db->escape($this->label).
"'";
199 $sql .=
", objecttype = '".$this->db->escape($this->objecttype).
"'";
200 $sql .=
", objectid = ".$this->objectid;
201 $sql .=
" WHERE rowid = ".((int) $this->
id);
203 dol_syslog(get_class($this).
"::update sql = ".$sql);
204 $resql = $this->db->query($sql);
216 dol_syslog(get_class($this).
"::Update success");
221 $this->db->rollback();
225 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
227 $this->error = $langs->trans(
"ErrorDuplicateField");
230 $this->error = $langs->trans(
"Error sql").
"= $sql";
233 $this->db->rollback();
248 public function fetchAll(&$links, $objecttype, $objectid, $sortfield =
null, $sortorder =
null)
252 $sql =
"SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".$this->db->prefix().
"links";
253 $sql .=
" WHERE objecttype = '".$this->db->escape($objecttype).
"' AND objectid = ".((int) $objectid);
254 if ($conf->entity != 0) {
255 $sql .=
" AND entity = ".((int) $conf->entity);
258 if (empty($sortorder)) {
261 $sql .=
" ORDER BY ".$sortfield.
" ".$sortorder;
264 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
265 $resql = $this->db->query($sql);
267 $num = $this->db->num_rows($resql);
268 dol_syslog(get_class($this).
"::fetchAll num=".((
int) $num), LOG_DEBUG);
270 while ($obj = $this->db->fetch_object($resql)) {
271 $link =
new Link($this->db);
272 $link->id = (int) $obj->rowid;
273 $link->entity = $obj->entity;
274 $link->datea = $this->db->jdate($obj->datea);
275 $link->url = $obj->url;
276 $link->label = $obj->label;
277 $link->objecttype = $obj->objecttype;
278 $link->objectid = $obj->objectid;
298 public static function count($dbs, $objecttype, $objectid)
302 $sql =
"SELECT COUNT(rowid) as nb FROM ".$dbs->prefix().
"links";
303 $sql .=
" WHERE objecttype = '".$dbs->escape($objecttype).
"' AND objectid = ".((int) $objectid);
304 if ($conf->entity != 0) {
305 $sql .=
" AND entity = ".$conf->entity;
308 $resql = $dbs->query($sql);
310 $obj = $dbs->fetch_object($resql);
324 public function fetch($rowid =
null)
332 $sql =
"SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".$this->db->prefix().
"links";
333 $sql .=
" WHERE rowid = ".((int) $rowid);
334 if ($conf->entity != 0) {
335 $sql .=
" AND entity = ".$conf->entity;
338 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
339 $resql = $this->db->query($sql);
341 if ($this->db->num_rows($resql) > 0) {
342 $obj = $this->db->fetch_object($resql);
344 $this->
id = $obj->rowid;
345 $this->entity = $obj->entity;
346 $this->datea = $this->db->jdate($obj->datea);
347 $this->url = $obj->url;
348 $this->label = $obj->label;
349 $this->objecttype = $obj->objecttype;
350 $this->objectid = $obj->objectid;
356 $this->error = $this->db->lasterror();
367 public function delete($user)
369 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
377 $this->db->rollback();
383 $sql =
"DELETE FROM ".$this->db->prefix().
"links";
384 $sql .=
" WHERE rowid = ".((int) $this->
id);
386 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
387 if (!$this->db->query($sql)) {
389 $this->error = $this->db->lasterror();
397 $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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
dol_now($mode='auto')
Return date for now.
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.