109 public function create($user, $notrigger = 0)
116 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
117 $sql .=
"description";
119 $sql .=
", fk_element";
120 $sql .=
", element_type";
121 $sql .=
", fk_user_author";
122 $sql .=
", fk_user_modif";
124 $sql .=
", import_key";
125 $sql .=
") VALUES (";
126 $sql .=
"'".$this->db->escape($this->
description).
"'";
127 $sql .=
", ".($this->datec !=
'' ?
"'".$this->db->idate($this->datec).
"'" :
'null');
128 $sql .=
", '".(isset($this->fk_element) ? $this->fk_element :
"null").
"'";
129 $sql .=
", '".$this->db->escape($this->element_type).
"'";
130 $sql .=
", '".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
"'";
131 $sql .=
", ".((int) $user->id);
132 $sql .=
", ".(!empty($this->entity) ? $this->entity :
'1');
133 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
141 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
142 $resql = $this->db->query($sql);
145 $this->errors[] =
"Error ".$this->db->lasterror();
149 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
153 $result = $this->
call_trigger(
'TASK_COMMENT_CREATE', $user);
163 foreach ($this->errors as $errmsg) {
164 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
165 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
167 $this->db->rollback();
183 public function fetch($id, $ref =
'')
189 $sql .=
" c.description,";
192 $sql .=
" c.fk_element,";
193 $sql .=
" c.element_type,";
194 $sql .=
" c.fk_user_author,";
195 $sql .=
" c.fk_user_modif,";
196 $sql .=
" c.entity,";
197 $sql .=
" c.import_key";
198 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as c";
199 $sql .=
" WHERE c.rowid = ".((int) $id);
201 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
202 $resql = $this->db->query($sql);
204 $num_rows = $this->db->num_rows($resql);
207 $obj = $this->db->fetch_object($resql);
209 $this->
id = $obj->rowid;
211 $this->element_type = $obj->element_type;
212 $this->datec = $this->db->jdate($obj->datec);
213 $this->tms = $this->db->jdate($obj->tms);
214 $this->fk_user_author = $obj->fk_user_author;
215 $this->fk_user_modif = $obj->fk_user_modif;
216 $this->fk_element = $obj->fk_element;
217 $this->entity = $obj->entity;
218 $this->import_key = $obj->import_key;
221 $this->db->free($resql);
229 $this->error =
"Error ".$this->db->lasterror();
248 if (isset($this->fk_element)) {
249 $this->fk_project = (int) trim($this->fk_element);
257 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
258 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
259 $sql .=
" datec=".($this->datec !=
'' ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
260 $sql .=
" fk_element=".(isset($this->fk_element) ? $this->fk_element :
"null").
",";
261 $sql .=
" element_type='".$this->db->escape($this->element_type).
"',";
262 $sql .=
" fk_user_modif=".$user->id.
",";
263 $sql .=
" entity=".(!empty($this->entity) ? $this->entity :
'1').
",";
264 $sql .=
" import_key=".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
265 $sql .=
" WHERE rowid=".((int) $this->
id);
269 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
270 $resql = $this->db->query($sql);
273 $this->errors[] =
"Error ".$this->db->lasterror();
279 $result = $this->
call_trigger(
'TASK_COMMENT_MODIFY', $user);
289 foreach ($this->errors as $errmsg) {
290 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
291 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
293 $this->db->rollback();
309 public function delete($user, $notrigger = 0)
311 global $conf, $langs;
312 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
318 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
319 $sql .=
" WHERE rowid=".((int) $this->
id);
321 $resql = $this->db->query($sql);
324 $this->errors[] =
"Error ".$this->db->lasterror();
330 $result = $this->
call_trigger(
'TASK_COMMENT_DELETE', $user);
340 foreach ($this->errors as $errmsg) {
341 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
342 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
344 $this->db->rollback();
364 $this->comments = array();
366 if (!empty($element_type) && !empty($fk_element)) {
369 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as c";
370 $sql .=
" WHERE c.fk_element = ".((int) $fk_element);
371 $sql .=
" AND c.element_type = '".$this->db->escape($element_type).
"'";
372 $sql .=
" AND c.entity = ".$conf->entity;
373 $sql .=
" ORDER BY c.tms DESC";
375 dol_syslog(get_class($this).
'::'.__METHOD__, LOG_DEBUG);
376 $resql = $this->db->query($sql);
378 $num_rows = $this->db->num_rows($resql);
380 while ($obj = $this->db->fetch_object($resql)) {
381 $comment =
new self($db);
382 $comment->fetch($obj->rowid);
383 $this->comments[] = $comment;
386 $this->db->free($resql);
388 $this->errors[] =
"Error ".$this->db->lasterror();
393 return count($this->comments);