dolibarr  9.0.0
comment.class.php
1 <?php
2 /*
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  * or see http://www.gnu.org/
17  */
18 
22 class Comment extends CommonObject
23 {
27  public $element='comment';
28 
32  public $table_element='comment';
33 
37  public $fk_element ='';
38 
39  public $element_type;
40 
44  public $description;
45 
46  public $tms;
47 
48  public $datec;
49 
53  public $fk_user_author;
54 
58  public $entity;
59 
60  public $import_key;
61 
62  public $comments = array();
63 
64  public $oldcopy;
65 
66 
72  function __construct($db)
73  {
74  $this->db = $db;
75  }
76 
77 
85  function create($user, $notrigger=0)
86  {
87  global $conf, $langs;
88 
89  $error=0;
90 
91  // Insert request
92  $sql = "INSERT INTO ".MAIN_DB_PREFIX."comment (";
93  $sql.= "description";
94  $sql.= ", datec";
95  $sql.= ", fk_element";
96  $sql.= ", element_type";
97  $sql.= ", fk_user_author";
98  $sql.= ", entity";
99  $sql.= ", import_key";
100  $sql.= ") VALUES (";
101  $sql.= "'".$this->db->escape($this->description)."'";
102  $sql.= ", ".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null');
103  $sql.= ", '".(isset($this->fk_element)?$this->fk_element:"null")."'";
104  $sql.= ", '".$this->db->escape($this->element_type)."'";
105  $sql.= ", '".(isset($this->fk_user_author)?$this->fk_user_author:"null")."'";
106  $sql.= ", ".(!empty($this->entity)?$this->entity:'1');
107  $sql.= ", ".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
108  $sql.= ")";
109 
110  //var_dump($this->db);
111  //echo $sql;
112 
113  $this->db->begin();
114 
115  dol_syslog(get_class($this)."::create", LOG_DEBUG);
116  $resql=$this->db->query($sql);
117  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
118 
119  if (! $error)
120  {
121  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_comment");
122 
123  if (! $notrigger)
124  {
125  // Call trigger
126  $result=$this->call_trigger('TASK_COMMENT_CREATE',$user);
127  if ($result < 0) { $error++; }
128  // End call triggers
129  }
130  }
131 
132  // Commit or rollback
133  if ($error)
134  {
135  foreach($this->errors as $errmsg)
136  {
137  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
138  $this->error.=($this->error?', '.$errmsg:$errmsg);
139  }
140  $this->db->rollback();
141  return -1*$error;
142  }
143  else
144  {
145  $this->db->commit();
146  return $this->id;
147  }
148  }
149 
150 
158  function fetch($id, $ref='')
159  {
160  global $langs;
161 
162  $sql = "SELECT";
163  $sql.= " c.rowid,";
164  $sql.= " c.description,";
165  $sql.= " c.datec,";
166  $sql.= " c.tms,";
167  $sql.= " c.fk_element,";
168  $sql.= " c.element_type,";
169  $sql.= " c.fk_user_author,";
170  $sql.= " c.entity,";
171  $sql.= " c.import_key";
172  $sql.= " FROM ".MAIN_DB_PREFIX."comment as c";
173  $sql.= " WHERE c.rowid = ".$id;
174 
175  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
176  $resql=$this->db->query($sql);
177  if ($resql)
178  {
179  $num_rows = $this->db->num_rows($resql);
180 
181  if ($num_rows)
182  {
183  $obj = $this->db->fetch_object($resql);
184 
185  $this->id = $obj->rowid;
186  $this->description = $obj->description;
187  $this->element_type = $obj->element_type;
188  $this->datec = $this->db->jdate($obj->datec);
189  $this->tms = $obj->tms;
190  $this->fk_user_author = $obj->fk_user_author;
191  $this->fk_element = $obj->fk_element;
192  $this->entity = $obj->entity;
193  $this->import_key = $obj->import_key;
194  }
195 
196  $this->db->free($resql);
197 
198  if ($num_rows) return 1;
199  else return 0;
200  }
201  else
202  {
203  $this->error="Error ".$this->db->lasterror();
204  return -1;
205  }
206  }
207 
208 
216  function update(User $user, $notrigger=0)
217  {
218  global $conf, $langs;
219  $error=0;
220 
221  // Clean parameters
222  if (isset($this->fk_element)) $this->fk_project=(int) trim($this->fk_element);
223  if (isset($this->fk_user_author)) $this->fk_user_author=(int) trim($this->fk_user_author);
224  if (isset($this->description)) $this->description=trim($this->description);
225 
226 
227  // Update request
228  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_comment SET";
229  $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").",";
230  $sql.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').",";
231  $sql.= " fk_element=".(isset($this->fk_element)?$this->fk_element:"null").",";
232  $sql.= " element_type='".$this->db->escape($this->element_type)."',";
233  $sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").",";
234  $sql.= " entity=".(!empty($this->entity)?$this->entity:'1').",";
235  $sql.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
236  $sql.= " WHERE rowid=".$this->id;
237 
238  $this->db->begin();
239 
240  dol_syslog(get_class($this)."::update", LOG_DEBUG);
241  $resql = $this->db->query($sql);
242  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
243 
244  if (! $error)
245  {
246  if (! $notrigger)
247  {
248  // Call trigger
249  $result=$this->call_trigger('TASK_COMMENT_MODIFY',$user);
250  if ($result < 0) { $error++; }
251  // End call triggers
252  }
253  }
254 
255  // Commit or rollback
256  if ($error)
257  {
258  foreach($this->errors as $errmsg)
259  {
260  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
261  $this->error.=($this->error?', '.$errmsg:$errmsg);
262  }
263  $this->db->rollback();
264  return -1*$error;
265  }
266  else
267  {
268  $this->db->commit();
269  return 1;
270  }
271  }
272 
273 
281  function delete($user, $notrigger=0)
282  {
283  global $conf, $langs;
284  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
285 
286  $error=0;
287 
288  $this->db->begin();
289 
290  $sql = "DELETE FROM ".MAIN_DB_PREFIX."comment";
291  $sql.= " WHERE rowid=".$this->id;
292 
293  $resql = $this->db->query($sql);
294  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
295 
296  if (! $error)
297  {
298  if (! $notrigger)
299  {
300  // Call trigger
301  $result=$this->call_trigger('TASK_COMMENT_DELETE',$user);
302  if ($result < 0) { $error++; }
303  // End call triggers
304  }
305  }
306 
307  // Commit or rollback
308  if ($error)
309  {
310  foreach($this->errors as $errmsg)
311  {
312  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
313  $this->error.=($this->error?', '.$errmsg:$errmsg);
314  }
315  $this->db->rollback();
316  return -1*$error;
317  }else{
318  $this->db->commit();
319  return 1;
320  }
321  }
322 
323 
331  public function fetchAllFor($element_type, $fk_element)
332  {
333  global $db,$conf;
334  $this->comments = array();
335  if(!empty($element_type) && !empty($fk_element)) {
336  $sql = "SELECT";
337  $sql.= " c.rowid";
338  $sql.= " FROM ".MAIN_DB_PREFIX."comment as c";
339  $sql.= " WHERE c.fk_element = ".$fk_element;
340  $sql.= " AND c.element_type = '".$db->escape($element_type)."'";
341  $sql.= " AND c.entity = ".$conf->entity;
342  $sql.= " ORDER BY c.tms DESC";
343 
344  dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG);
345  $resql=$db->query($sql);
346  if ($resql)
347  {
348  $num_rows = $db->num_rows($resql);
349  if ($num_rows > 0)
350  {
351  while($obj = $db->fetch_object($resql))
352  {
353  $comment = new self($db);
354  $comment->fetch($obj->rowid);
355  $this->comments[] = $comment;
356  }
357  }
358  $db->free($resql);
359  } else {
360  $error++; $this->errors[]="Error ".$this->db->lasterror();
361  return -1;
362  }
363  }
364 
365  return count($this->comments);
366  }
367 }
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.
Definition: index.php:1053
</td >< td class="liste_titre" align="right"></td ></tr >< tr class="liste_titre">< input type="checkbox" onClick="toggle(this)"/> Ref p ref Label p label Duration p duration warehouseinternal SELECT description FROM product_lang WHERE qty< br > qty qty qty StockTooLow img yes disabled img no img no< tr class="oddeven">< td >< input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td >< td >< input type="checkbox" class="check" name="choose'.$i.'"></td >< td class="nowrap"></td >< td >< input type="hidden" name="desc' . $i . '" value="' . dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:573
Class to manage Dolibarr users.
Definition: user.class.php:41
fetch($id, $ref='')
Load object in memory from database.
__construct($db)
Constructor.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
update(User $user, $notrigger=0)
Update database.
fetchAllFor($element_type, $fk_element)
Load comments linked with current task.
Class to manage comment.
create($user, $notrigger=0)
Create into database.
call_trigger($trigger_name, $user)
Call trigger based on this instance.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)