103 public function create($user, $notrigger = 0)
110 $sql =
"INSERT INTO ".$this->db->prefix().$this->table_element.
" (";
111 $sql .=
"description";
113 $sql .=
", fk_element";
114 $sql .=
", element_type";
115 $sql .=
", fk_user_author";
116 $sql .=
", fk_user_modif";
118 $sql .=
", import_key";
119 $sql .=
") VALUES (";
120 $sql .=
"'".$this->db->escape($this->
description).
"'";
121 $sql .=
", ".($this->datec !=
'' ?
"'".$this->db->idate($this->datec).
"'" :
'null');
122 $sql .=
", '".(isset($this->fk_element) ? $this->fk_element :
"null").
"'";
123 $sql .=
", '".$this->db->escape($this->element_type).
"'";
124 $sql .=
", '".(isset($this->fk_user_author) ? $this->fk_user_author :
"null").
"'";
125 $sql .=
", ".((int) $user->id);
126 $sql .=
", ".(!empty($this->entity) ? $this->entity :
'1');
127 $sql .=
", ".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
135 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
136 $resql = $this->db->query($sql);
139 $this->errors[] =
"Error ".$this->db->lasterror();
143 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
147 $result = $this->
call_trigger(
'TASK_COMMENT_CREATE', $user);
157 foreach ($this->errors as $errmsg) {
158 dol_syslog(get_class($this).
"::create ".$errmsg, LOG_ERR);
159 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
161 $this->db->rollback();
177 public function fetch($id, $ref =
'')
183 $sql .=
" c.description,";
186 $sql .=
" c.fk_element,";
187 $sql .=
" c.element_type,";
188 $sql .=
" c.fk_user_author,";
189 $sql .=
" c.fk_user_modif,";
190 $sql .=
" c.entity,";
191 $sql .=
" c.import_key";
192 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as c";
193 $sql .=
" WHERE c.rowid = ".((int) $id);
195 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
196 $resql = $this->db->query($sql);
198 $num_rows = $this->db->num_rows($resql);
201 $obj = $this->db->fetch_object($resql);
203 $this->
id = $obj->rowid;
205 $this->element_type = $obj->element_type;
206 $this->datec = $this->db->jdate($obj->datec);
207 $this->tms = $this->db->jdate($obj->tms);
208 $this->fk_user_author = $obj->fk_user_author;
209 $this->fk_user_modif = $obj->fk_user_modif;
210 $this->fk_element = $obj->fk_element;
211 $this->entity = $obj->entity;
212 $this->import_key = $obj->import_key;
215 $this->db->free($resql);
223 $this->error =
"Error ".$this->db->lasterror();
242 if (isset($this->fk_element)) {
243 $this->fk_project = (int) trim((
string) $this->fk_element);
251 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
252 $sql .=
" description=".(isset($this->
description) ?
"'".$this->db->escape($this->
description).
"'" :
"null").
",";
253 $sql .=
" datec=".($this->datec !=
'' ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
254 $sql .=
" fk_element=".(isset($this->fk_element) ? $this->fk_element :
"null").
",";
255 $sql .=
" element_type='".$this->db->escape($this->element_type).
"',";
256 $sql .=
" fk_user_modif=".$user->id.
",";
257 $sql .=
" entity=".(!empty($this->entity) ? $this->entity :
'1').
",";
258 $sql .=
" import_key=".(!empty($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
259 $sql .=
" WHERE rowid=".((int) $this->
id);
263 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
264 $resql = $this->db->query($sql);
267 $this->errors[] =
"Error ".$this->db->lasterror();
273 $result = $this->
call_trigger(
'TASK_COMMENT_MODIFY', $user);
283 foreach ($this->errors as $errmsg) {
284 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
285 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
287 $this->db->rollback();
303 public function delete($user, $notrigger = 0)
305 global $conf, $langs;
306 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
312 $sql =
"DELETE FROM ".$this->db->prefix().$this->table_element;
313 $sql .=
" WHERE rowid=".((int) $this->
id);
315 $resql = $this->db->query($sql);
318 $this->errors[] =
"Error ".$this->db->lasterror();
324 $result = $this->
call_trigger(
'TASK_COMMENT_DELETE', $user);
334 foreach ($this->errors as $errmsg) {
335 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
336 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
338 $this->db->rollback();
358 $this->comments = array();
360 if (!empty($element_type) && !empty($fk_element)) {
363 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as c";
364 $sql .=
" WHERE c.fk_element = ".((int) $fk_element);
365 $sql .=
" AND c.element_type = '".$this->db->escape($element_type).
"'";
366 $sql .=
" AND c.entity = ".$conf->entity;
367 $sql .=
" ORDER BY c.tms DESC";
369 dol_syslog(get_class($this).
'::'.__METHOD__, LOG_DEBUG);
370 $resql = $this->db->query($sql);
372 $num_rows = $this->db->num_rows($resql);
374 while ($obj = $this->db->fetch_object($resql)) {
375 $comment =
new self($db);
376 $comment->fetch($obj->rowid);
377 $this->comments[] = $comment;
380 $this->db->free($resql);
382 $this->errors[] =
"Error ".$this->db->lasterror();
387 return count($this->comments);