23 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
34 public $element =
'link';
39 public $table_element =
'links';
80 $langs->load(
"errors");
82 if (empty($this->
label)) {
83 $this->
label = trim(basename($this->url));
85 if (empty($this->datea)) {
88 $this->url = trim($this->url);
90 dol_syslog(get_class($this).
"::create ".$this->url);
93 if (empty($this->url)) {
94 $this->error = $langs->trans(
"NoUrl");
100 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"links (entity, datea, url, label, objecttype, objectid)";
101 $sql .=
" VALUES ('".$conf->entity.
"', '".$this->db->idate($this->datea).
"'";
102 $sql .=
", '" . $this->db->escape($this->url) .
"'";
103 $sql .=
", '" . $this->db->escape($this->
label) .
"'";
104 $sql .=
", '" . $this->db->escape($this->objecttype) .
"'";
105 $sql .=
", " . $this->objectid .
")";
107 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
108 $result = $this->db->query($sql);
110 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX .
"links");
115 if ($result < 0) $error++;
123 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();
136 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS')
139 $this->error=$langs->trans(
"ErrorCompanyNameAlreadyExists",$this->
name);
144 $this->error=$this->db->lasterror();
147 $this->db->rollback();
159 public function update($user=
'', $call_trigger=1)
162 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
164 $langs->load(
"errors");
167 dol_syslog(get_class($this).
"::Update id = " . $this->
id .
" call_trigger = " . $call_trigger);
170 if (empty($this->url))
172 $this->error = $langs->trans(
"NoURL");
178 if (empty($this->
label)) $this->
label = basename($this->url);
184 $sql =
"UPDATE " . MAIN_DB_PREFIX .
"links SET ";
185 $sql .=
"entity = '" . $conf->entity .
"'";
186 $sql .=
", datea = '" . $this->db->idate(
dol_now()) .
"'";
187 $sql .=
", url = '" . $this->db->escape($this->url) .
"'";
188 $sql .=
", label = '" . $this->db->escape($this->
label) .
"'";
189 $sql .=
", objecttype = '" . $this->db->escape($this->objecttype) .
"'";
190 $sql .=
", objectid = " . $this->objectid;
191 $sql .=
" WHERE rowid = " . $this->id;
193 dol_syslog(get_class($this).
"::update sql = " .$sql);
194 $resql = $this->db->query($sql);
201 if ($result < 0) $error++;
207 dol_syslog(get_class($this) .
"::Update success");
212 $this->db->rollback();
218 if ($this->db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS')
221 $this->error = $langs->trans(
"ErrorDuplicateField");
226 $this->error = $langs->trans(
"Error sql = " . $sql);
229 $this->db->rollback();
244 public function fetchAll(&$links, $objecttype, $objectid, $sortfield=null, $sortorder=null)
248 $sql =
"SELECT rowid, entity, datea, url, label, objecttype, objectid FROM " . MAIN_DB_PREFIX .
"links";
249 $sql .=
" WHERE objecttype = '" . $objecttype .
"' AND objectid = " . $objectid;
250 if ($conf->entity != 0) $sql .=
" AND entity = " . $conf->entity;
252 if (empty($sortorder)) {
255 $sql .=
" ORDER BY " . $sortfield .
" " . $sortorder;
258 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
259 $resql = $this->db->query($sql);
262 $num = $this->db->num_rows(
$resql);
263 dol_syslog(get_class($this).
"::fetchAll " . $num .
"records", LOG_DEBUG);
266 while ($obj = $this->db->fetch_object(
$resql))
268 $link =
new Link($this->db);
269 $link->id = $obj->rowid;
270 $link->entity = $obj->entity;
271 $link->datea = $this->db->jdate($obj->datea);
272 $link->url = $obj->url;
273 $link->label = $obj->label;
274 $link->objecttype = $obj->objecttype;
275 $link->objectid = $obj->objectid;
295 public static function count($db, $objecttype, $objectid)
299 $sql =
"SELECT COUNT(rowid) as nb FROM " . MAIN_DB_PREFIX .
"links";
300 $sql .=
" WHERE objecttype = '" . $objecttype .
"' AND objectid = " . $objectid;
301 if ($conf->entity != 0) $sql .=
" AND entity = " . $conf->entity;
303 $resql = $db->query($sql);
306 $obj = $db->fetch_object(
$resql);
307 if ($obj)
return $obj->nb;
326 $sql =
"SELECT rowid, entity, datea, url, label, objecttype, objectid FROM " . MAIN_DB_PREFIX .
"links";
327 $sql .=
" WHERE rowid = " . $rowid;
328 if($conf->entity != 0) $sql .=
" AND entity = " . $conf->entity;
330 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
331 $resql = $this->db->query($sql);
334 if($this->db->num_rows(
$resql) > 0)
336 $obj = $this->db->fetch_object(
$resql);
337 $this->entity = $obj->entity;
338 $this->datea = $this->db->jdate($obj->datea);
339 $this->url = $obj->url;
340 $this->
label = $obj->label;
341 $this->objecttype = $obj->objecttype;
342 $this->objectid = $obj->objectid;
350 $this->error=$this->db->lasterror();
360 public function delete()
362 global $user, $langs, $conf;
364 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
369 if ($result < 0)
return -1;
375 $sql =
"DELETE FROM " . MAIN_DB_PREFIX .
"links";
376 $sql.=
" WHERE rowid = " . $this->id;
378 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
379 if (! $this->db->query($sql))
382 $this->error = $this->db->lasterror();
390 $this->db->rollback();
print $object label
hash of file content (md5_file(dol_osencode($destfull))
fetch($rowid=null)
Loads a link from database.
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
__construct($db)
Constructor.
clean_url($url, $http=1)
Clean an url string.
$conf db name
Only used if Module[ID]Name translation string is not found.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
dol_now($mode='gmt')
Return date for now.
static count($db, $objecttype, $objectid)
Return nb of links.
update($user='', $call_trigger=1)
Update parameters of third party.
create($user='')
Create link in database.
call_trigger($trigger_name, $user)
Call trigger based on this instance.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchAll(&$links, $objecttype, $objectid, $sortfield=null, $sortorder=null)
Loads all links from database.