dolibarr  7.0.0-beta
comment.class.php
1 <?php
5 class Comment extends CommonObject
6 {
7  public $element='comment';
8  public $table_element='comment';
9 
10  var $fk_element;
11  var $element_type;
12 
13  var $description;
14 
15  var $tms;
16 
17  var $datec;
18 
19  var $fk_user_author;
20 
21  var $entity;
22 
23  var $import_key;
24 
25  public $oldcopy;
26 
27 
33  function __construct($db)
34  {
35  $this->db = $db;
36  }
37 
38 
46  function create($user, $notrigger=0)
47  {
48  global $conf, $langs;
49 
50  $error=0;
51 
52  // Insert request
53  $sql = "INSERT INTO ".MAIN_DB_PREFIX."comment (";
54  $sql.= "description";
55  $sql.= ", datec";
56  $sql.= ", fk_element";
57  $sql.= ", element_type";
58  $sql.= ", fk_user_author";
59  $sql.= ", entity";
60  $sql.= ", import_key";
61  $sql.= ") VALUES (";
62  $sql.= "'".$this->db->escape($this->description)."'";
63  $sql.= ", ".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null');
64  $sql.= ", '".(isset($this->fk_element)?$this->fk_element:"null")."'";
65  $sql.= ", '".$this->db->escape($this->element_type)."'";
66  $sql.= ", '".(isset($this->fk_user_author)?$this->fk_user_author:"null")."'";
67  $sql.= ", ".(!empty($this->entity)?$this->entity:'1');
68  $sql.= ", ".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
69  $sql.= ")";
70 
71  //var_dump($this->db);
72  //echo $sql;
73 
74  $this->db->begin();
75 
76  dol_syslog(get_class($this)."::create", LOG_DEBUG);
77  $resql=$this->db->query($sql);
78  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
79 
80  if (! $error)
81  {
82  $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."projet_task_comment");
83 
84  if (! $notrigger)
85  {
86  // Call trigger
87  $result=$this->call_trigger('TASK_COMMENT_CREATE',$user);
88  if ($result < 0) { $error++; }
89  // End call triggers
90  }
91  }
92 
93  // Commit or rollback
94  if ($error)
95  {
96  foreach($this->errors as $errmsg)
97  {
98  dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
99  $this->error.=($this->error?', '.$errmsg:$errmsg);
100  }
101  $this->db->rollback();
102  return -1*$error;
103  }
104  else
105  {
106  $this->db->commit();
107  return $this->id;
108  }
109  }
110 
111 
119  function fetch($id, $ref='')
120  {
121  global $langs;
122 
123  $sql = "SELECT";
124  $sql.= " c.rowid,";
125  $sql.= " c.description,";
126  $sql.= " c.datec,";
127  $sql.= " c.tms,";
128  $sql.= " c.fk_element,";
129  $sql.= " c.element_type,";
130  $sql.= " c.fk_user_author,";
131  $sql.= " c.entity,";
132  $sql.= " c.import_key";
133  $sql.= " FROM ".MAIN_DB_PREFIX."comment as c";
134  $sql.= " WHERE c.rowid = ".$id;
135 
136  dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
137  $resql=$this->db->query($sql);
138  if ($resql)
139  {
140  $num_rows = $this->db->num_rows($resql);
141 
142  if ($num_rows)
143  {
144  $obj = $this->db->fetch_object($resql);
145 
146  $this->id = $obj->rowid;
147  $this->description = $obj->description;
148  $this->element_type = $obj->element_type;
149  $this->datec = $this->db->jdate($obj->datec);
150  $this->tms = $obj->tms;
151  $this->fk_user_author = $obj->fk_user_author;
152  $this->fk_element = $obj->fk_element;
153  $this->entity = $obj->entity;
154  $this->import_key = $obj->import_key;
155  }
156 
157  $this->db->free($resql);
158 
159  if ($num_rows) return 1;
160  else return 0;
161  }
162  else
163  {
164  $this->error="Error ".$this->db->lasterror();
165  return -1;
166  }
167  }
168 
169 
177  function update(User $user, $notrigger=0)
178  {
179  global $conf, $langs;
180  $error=0;
181 
182  // Clean parameters
183  if (isset($this->fk_element)) $this->fk_project=(int) trim($this->fk_element);
184  if (isset($this->fk_user_author)) $this->fk_user_author=(int) trim($this->fk_user_author);
185  if (isset($this->description)) $this->description=trim($this->description);
186 
187 
188  // Update request
189  $sql = "UPDATE ".MAIN_DB_PREFIX."projet_task_comment SET";
190  $sql.= " description=".(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").",";
191  $sql.= " datec=".($this->datec!=''?"'".$this->db->idate($this->datec)."'":'null').",";
192  $sql.= " fk_element=".(isset($this->fk_element)?$this->fk_element:"null").",";
193  $sql.= " element_type='".$this->db->escape($this->element_type)."',";
194  $sql.= " fk_user_author=".(isset($this->fk_user_author)?$this->fk_user_author:"null").",";
195  $sql.= " entity=".(!empty($this->entity)?$this->entity:'1').",";
196  $sql.= " import_key=".(!empty($this->import_key)?"'".$this->db->escape($this->import_key)."'":"null");
197  $sql.= " WHERE rowid=".$this->id;
198 
199  $this->db->begin();
200 
201  dol_syslog(get_class($this)."::update", LOG_DEBUG);
202  $resql = $this->db->query($sql);
203  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
204 
205  if (! $error)
206  {
207  if (! $notrigger)
208  {
209  // Call trigger
210  $result=$this->call_trigger('TASK_COMMENT_MODIFY',$user);
211  if ($result < 0) { $error++; }
212  // End call triggers
213  }
214  }
215 
216  // Commit or rollback
217  if ($error)
218  {
219  foreach($this->errors as $errmsg)
220  {
221  dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
222  $this->error.=($this->error?', '.$errmsg:$errmsg);
223  }
224  $this->db->rollback();
225  return -1*$error;
226  }
227  else
228  {
229  $this->db->commit();
230  return 1;
231  }
232  }
233 
234 
242  function delete($user, $notrigger=0)
243  {
244  global $conf, $langs;
245  require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
246 
247  $error=0;
248 
249  $this->db->begin();
250 
251  $sql = "DELETE FROM ".MAIN_DB_PREFIX."comment";
252  $sql.= " WHERE rowid=".$this->id;
253 
254  $resql = $this->db->query($sql);
255  if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
256 
257  if (! $error)
258  {
259  if (! $notrigger)
260  {
261  // Call trigger
262  $result=$this->call_trigger('TASK_COMMENT_DELETE',$user);
263  if ($result < 0) { $error++; }
264  // End call triggers
265  }
266  }
267 
268  // Commit or rollback
269  if ($error)
270  {
271  foreach($this->errors as $errmsg)
272  {
273  dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
274  $this->error.=($this->error?', '.$errmsg:$errmsg);
275  }
276  $this->db->rollback();
277  return -1*$error;
278  }else{
279  $this->db->commit();
280  return 1;
281  }
282  }
283 
284 
292  public static function fetchAllFor($element_type, $fk_element)
293  {
294  global $db,$conf;
295  $TComments = array();
296  if(!empty($element_type) && !empty($fk_element)) {
297  $sql = "SELECT";
298  $sql.= " c.rowid";
299  $sql.= " FROM ".MAIN_DB_PREFIX."comment as c";
300  $sql.= " WHERE c.fk_element = ".$fk_element;
301  $sql.= " AND c.element_type = '".$db->escape($element_type)."'";
302  $sql.= " AND c.entity = ".$conf->entity;
303  $sql.= " ORDER BY c.tms DESC";
304 
305  dol_syslog("Comment::fetchAllFor", LOG_DEBUG);
306  $resql=$db->query($sql);
307  if ($resql)
308  {
309  $num_rows = $db->num_rows($resql);
310  if ($num_rows > 0)
311  {
312  while($obj = $db->fetch_object($resql))
313  {
314  $comment = new self($db);
315  $comment->fetch($obj->rowid);
316  $TComments[] = $comment;
317  }
318  }
319  $db->free($resql);
320  }
321  }
322  return $TComments;
323  }
324 }
static fetchAllFor($element_type, $fk_element)
Load comments linked with current task.
$table_element
Name of table without prefix where object is stored.
</td >< tdclass="liste_titre"align="right"></td ></tr >< trclass="liste_titre">< inputtype="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< trclass="oddeven">< td >< inputtype="checkbox"class="check"name="'.$i.'"'.$disabled.'></td >< td >< inputtype="checkbox"class="check"name="choose'.$i.'"></td >< tdclass="nowrap"></td >< td >< inputtype="hidden"name="desc'.$i.'"value="'.dol_escape_htmltag($objp-> description
Only used if Module[ID]Desc translation string is not found.
Definition: replenish.php:554
Class to manage Dolibarr users.
Definition: user.class.php:39
fetch($id, $ref='')
Load object in memory from database.
__construct($db)
Constructor.
$element
Id that identify managed objects.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
update(User $user, $notrigger=0)
Update database.
Class to manage comment.
create($user, $notrigger=0)
Create into database.
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:1013
call_trigger($trigger_name, $user)
Call trigger based on this instance.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)