28 public $element =
'comment';
33 public $table_element =
'comment';
60 public $fk_user_author;
65 public $fk_user_modif;
77 public $comments = array();
98 public function create($user, $notrigger = 0)
105 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
106 $sql .=
"description";
108 $sql .=
", fk_element";
109 $sql .=
", element_type";
110 $sql .=
", fk_user_author";
111 $sql .=
", fk_user_modif";
113 $sql .=
", import_key";
114 $sql .=
") VALUES (";
115 $sql .=
"'".$this->db->escape($this->
description).
"'";
116 $sql .=
", ".($this->datec !=
'' ?
"'".$this->db->idate($this->datec).
"'" :
'null');
117 $sql .=
", '".(isset($this->fk_element) ? $this->fk_element :
"null").
"'";
118 $sql .=
", '".$this->db->escape($this->element_type).
"'";
119 $sql .=
", '".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
"'";
120 $sql .=
", ".((int) $user->id);
121 $sql .=
", ".(!empty($this->entity) ? $this->entity :
'1');
122 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
130 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
131 $resql = $this->db->query($sql);
134 $this->errors[] =
"Error ".$this->db->lasterror();
138 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
142 $result = $this->
call_trigger(
'TASK_COMMENT_CREATE', $user);
152 foreach ($this->errors as $errmsg) {
153 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
154 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
156 $this->db->rollback();
172 public function fetch($id, $ref =
'')
178 $sql .=
" c.description,";
181 $sql .=
" c.fk_element,";
182 $sql .=
" c.element_type,";
183 $sql .=
" c.fk_user_author,";
184 $sql .=
" c.fk_user_modif,";
185 $sql .=
" c.entity,";
186 $sql .=
" c.import_key";
187 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as c";
188 $sql .=
" WHERE c.rowid = ".((int) $id);
190 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
191 $resql = $this->db->query($sql);
193 $num_rows = $this->db->num_rows($resql);
196 $obj = $this->db->fetch_object($resql);
198 $this->
id = $obj->rowid;
200 $this->element_type = $obj->element_type;
201 $this->datec = $this->db->jdate($obj->datec);
202 $this->tms = $this->db->jdate($obj->tms);
203 $this->fk_user_author = $obj->fk_user_author;
204 $this->fk_user_modif = $obj->fk_user_modif;
205 $this->fk_element = $obj->fk_element;
206 $this->entity = $obj->entity;
207 $this->import_key = $obj->import_key;
210 $this->db->free($resql);
218 $this->error =
"Error ".$this->db->lasterror();
237 if (isset($this->fk_element)) {
238 $this->fk_project = (int) trim((
string) $this->fk_element);
246 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
247 $sql .=
" description = ".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
248 $sql .=
" datec = ".($this->datec !=
'' ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
249 $sql .=
" fk_element = ".(isset($this->fk_element) ? $this->fk_element :
"null").
",";
250 $sql .=
" element_type = '".$this->db->escape($this->element_type).
"',";
251 $sql .=
" fk_user_modif = ".((int) $user->id).
",";
252 $sql .=
" entity = ".(!empty($this->entity) ? $this->entity :
'1').
",";
253 $sql .=
" import_key = ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
254 $sql .=
" WHERE rowid = ".((int) $this->
id);
258 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
259 $resql = $this->db->query($sql);
262 $this->errors[] =
"Error ".$this->db->lasterror();
268 $result = $this->
call_trigger(
'TASK_COMMENT_MODIFY', $user);
278 foreach ($this->errors as $errmsg) {
279 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
280 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
282 $this->db->rollback();
298 public function delete($user, $notrigger = 0)
300 global
$conf, $langs;
301 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
307 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
308 $sql .=
" WHERE rowid=".((int) $this->
id);
310 $resql = $this->db->query($sql);
313 $this->errors[] =
"Error ".$this->db->lasterror();
319 $result = $this->
call_trigger(
'TASK_COMMENT_DELETE', $user);
329 foreach ($this->errors as $errmsg) {
330 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
331 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
333 $this->db->rollback();
353 $this->comments = array();
355 if (!empty($element_type) && !empty($fk_element)) {
358 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as c";
359 $sql .=
" WHERE c.fk_element = ".((int) $fk_element);
360 $sql .=
" AND c.element_type = '".$this->db->escape($element_type).
"'";
361 $sql .=
" AND c.entity = ".$conf->entity;
362 $sql .=
" ORDER BY c.tms DESC";
364 dol_syslog(get_class($this).
'::'.__METHOD__, LOG_DEBUG);
365 $resql = $this->db->query($sql);
367 $num_rows = $this->db->num_rows($resql);
369 while ($obj = $this->db->fetch_object($resql)) {
370 $comment =
new self($db);
371 $comment->fetch($obj->rowid);
372 $this->comments[] = $comment;
375 $this->db->free($resql);
377 $this->errors[] =
"Error ".$this->db->lasterror();
382 return count($this->comments);
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr users.
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...