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);
127 dol_syslog(get_class($this).
"::Create echec update ".$this->error, LOG_ERR);
128 $this->
db->rollback();
132 if ($this->
db->errno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS')
134 $this->error = $langs->trans(
"ErrorCompanyNameAlreadyExists", $this->
name);
137 $this->error = $this->
db->lasterror();
140 $this->
db->rollback();
152 public function update($user =
'', $call_trigger = 1)
154 global $langs, $conf;
155 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
157 $langs->load(
"errors");
160 dol_syslog(get_class($this).
"::Update id = ".$this->
id.
" call_trigger = ".$call_trigger);
163 if (empty($this->url))
165 $this->error = $langs->trans(
"NoURL");
171 if (empty($this->label)) $this->label = basename($this->url);
172 $this->label = trim($this->label);
177 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"links SET ";
178 $sql .=
"entity = ".$conf->entity;
179 $sql .=
", datea = '".$this->db->idate(
dol_now()).
"'";
180 $sql .=
", url = '".$this->db->escape($this->url).
"'";
181 $sql .=
", label = '".$this->db->escape($this->label).
"'";
182 $sql .=
", objecttype = '".$this->db->escape($this->objecttype).
"'";
183 $sql .=
", objectid = ".$this->objectid;
184 $sql .=
" WHERE rowid = ".$this->id;
186 dol_syslog(get_class($this).
"::update sql = ".$sql);
194 if ($result < 0) $error++;
200 dol_syslog(get_class($this).
"::Update success");
205 $this->
db->rollback();
209 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 ".MAIN_DB_PREFIX.
"links";
238 $sql .=
" WHERE objecttype = '".$this->db->escape($objecttype).
"' AND objectid = ".$objectid;
239 if ($conf->entity != 0) $sql .=
" AND entity = ".$conf->entity;
241 if (empty($sortorder)) {
244 $sql .=
" ORDER BY ".$sortfield.
" ".$sortorder;
247 dol_syslog(get_class($this).
"::fetchAll", LOG_DEBUG);
252 dol_syslog(get_class($this).
"::fetchAll ".$num.
"records", LOG_DEBUG);
255 while ($obj = $this->
db->fetch_object(
$resql))
257 $link =
new Link($this->
db);
258 $link->id = $obj->rowid;
259 $link->entity = $obj->entity;
260 $link->datea = $this->
db->jdate($obj->datea);
261 $link->url = $obj->url;
262 $link->label = $obj->label;
263 $link->objecttype = $obj->objecttype;
264 $link->objectid = $obj->objectid;
284 public static function count($db, $objecttype, $objectid)
288 $sql =
"SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.
"links";
289 $sql .=
" WHERE objecttype = '".$db->escape($objecttype).
"' AND objectid = ".$objectid;
290 if ($conf->entity != 0) $sql .=
" AND entity = ".$conf->entity;
292 $resql = $db->query($sql);
295 $obj = $db->fetch_object(
$resql);
296 if ($obj)
return $obj->nb;
307 public function fetch($rowid = null)
315 $sql =
"SELECT rowid, entity, datea, url, label, objecttype, objectid FROM ".MAIN_DB_PREFIX.
"links";
316 $sql .=
" WHERE rowid = ".$rowid;
317 if ($conf->entity != 0) $sql .=
" AND entity = ".$conf->entity;
319 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
323 if ($this->
db->num_rows(
$resql) > 0)
325 $obj = $this->
db->fetch_object(
$resql);
327 $this->
id = $obj->rowid;
328 $this->entity = $obj->entity;
329 $this->datea = $this->
db->jdate($obj->datea);
330 $this->url = $obj->url;
331 $this->label = $obj->label;
332 $this->objecttype = $obj->objecttype;
333 $this->objectid = $obj->objectid;
339 $this->error = $this->
db->lasterror();
350 public function delete($user)
352 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
361 $this->
db->rollback();
367 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"links";
368 $sql .=
" WHERE rowid = ".$this->id;
370 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
371 if (!$this->
db->query($sql))
374 $this->error = $this->
db->lasterror();
382 $this->
db->rollback();
fetch($rowid=null)
Loads a link from database.
__construct($db)
Constructor.
dol_now($mode= 'auto')
Return date for now.
clean_url($url, $http=1)
Clean an url string.
$conf db name
Only used if Module[ID]Name translation string is not found.
$conf db
API class for accounts.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
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.
create($user= '')
Create link in database.
update($user= '', $call_trigger=1)
Update parameters of third party.
static count($db, $objecttype, $objectid)
Return nb of links.
call_trigger($triggerName, $user)
Call trigger based on this instance.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
fetchAll(&$links, $objecttype, $objectid, $sortfield=null, $sortorder=null)
Loads all links from database.