dolibarr 19.0.3
opensurveysondage.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013-2014 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Marcos García <marcosgdf@gmail.com>
4 * Copyright (C) 2020 Frédéric France <frederic.france@netlogic.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
27// Put here all includes required by your class file
28require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
29
30
35{
39 public $element = 'opensurvey_sondage';
40
44 public $table_element = 'opensurvey_sondage';
45
49 public $picto = 'poll';
50
51
55 public $description;
56
60 public $date_m;
61
62
102 // BEGIN MODULEBUILDER PROPERTIES
106 public $fields=array(
107 'id_sondage' => array('type'=>'varchar(16)', 'label'=>'Idsondage', 'enabled'=>'1', 'position'=>10, 'notnull'=>1, 'visible'=>-1,),
108 'commentaires' => array('type'=>'mediumtext', 'label'=>'Commentaires', 'enabled'=>'1', 'position'=>15, 'notnull'=>0, 'visible'=>-1,),
109 'mail_admin' => array('type'=>'varchar(128)', 'label'=>'Mailadmin', 'enabled'=>'1', 'position'=>20, 'notnull'=>0, 'visible'=>-1,),
110 'nom_admin' => array('type'=>'varchar(64)', 'label'=>'Nomadmin', 'enabled'=>'1', 'position'=>25, 'notnull'=>0, 'visible'=>-1,),
111 'fk_user_creat' => array('type'=>'integer:User:user/class/user.class.php', 'label'=>'UserAuthor', 'enabled'=>'1', 'position'=>30, 'notnull'=>1, 'visible'=>-2, 'css'=>'maxwidth500 widthcentpercentminusxx', 'csslist'=>'tdoverflowmax150',),
112 'title' => array('type'=>'mediumtext', 'label'=>'Titre', 'enabled'=>'1', 'position'=>35, 'notnull'=>1, 'visible'=>-1,),
113 'date_fin' => array('type'=>'datetime', 'label'=>'Datefin', 'enabled'=>'1', 'position'=>40, 'notnull'=>1, 'visible'=>-1,),
114 'status' => array('type'=>'integer', 'label'=>'Status', 'enabled'=>'1', 'position'=>500, 'notnull'=>0, 'visible'=>-1,),
115 'format' => array('type'=>'varchar(2)', 'label'=>'Format', 'enabled'=>'1', 'position'=>50, 'notnull'=>1, 'visible'=>-1,),
116 'mailsonde' => array('type'=>'integer', 'label'=>'Mailsonde', 'enabled'=>'1', 'position'=>55, 'notnull'=>1, 'visible'=>-1,),
117 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>'1', 'position'=>60, 'notnull'=>1, 'visible'=>-1,),
118 'entity' => array('type'=>'integer', 'label'=>'Entity', 'enabled'=>'1', 'position'=>65, 'notnull'=>1, 'visible'=>-2, 'default'=>'1', 'index'=>1,),
119 'allow_comments' => array('type'=>'integer', 'label'=>'Allowcomments', 'enabled'=>'1', 'position'=>70, 'notnull'=>1, 'visible'=>-1,),
120 'allow_spy' => array('type'=>'integer', 'label'=>'Allowspy', 'enabled'=>'1', 'position'=>75, 'notnull'=>1, 'visible'=>-1,),
121 'sujet' => array('type'=>'mediumtext', 'label'=>'Sujet', 'enabled'=>'1', 'position'=>80, 'notnull'=>0, 'visible'=>-1,),
122 'id_sondage_admin' => array('type'=>'char(24)', 'label'=>'Idsondageadmin', 'enabled'=>'1', 'position'=>85, 'notnull'=>0, 'visible'=>-1,),
123 );
124 public $id_sondage;
129 public $commentaires;
130 public $mail_admin;
131 public $nom_admin;
132 public $fk_user_creat;
133 public $title;
134 public $date_fin = '';
135 public $status;
136 public $format;
137 public $mailsonde;
138 public $tms;
139 public $entity;
143 public $allow_comments;
144
148 public $allow_spy;
149 public $sujet;
150 public $id_sondage_admin;
151 // END MODULEBUILDER PROPERTIES
152
153
157 const STATUS_DRAFT = 0;
165 const STATUS_CLOSED = 2;
166
167
173 public function __construct($db)
174 {
175 $this->db = $db;
176 }
177
178
186 public function create(User $user, $notrigger = 0)
187 {
188 global $conf;
189
190 $error = 0;
191
192 // Clean parameters
193 $this->cleanParameters();
194
195 // Check parameters
196 if (!$this->date_fin > 0) {
197 $this->error = 'BadValueForEndDate';
198 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
199 return -1;
200 }
201
202 // Insert request
203 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_sondage(";
204 $sql .= "id_sondage,";
205 $sql .= "commentaires,";
206 $sql .= "fk_user_creat,";
207 $sql .= "titre,";
208 $sql .= "date_fin,";
209 $sql .= "status,";
210 $sql .= "format,";
211 $sql .= "mailsonde,";
212 $sql .= "allow_comments,";
213 $sql .= "allow_spy,";
214 $sql .= "sujet,";
215 $sql .= "entity";
216 $sql .= ") VALUES (";
217 $sql .= "'".$this->db->escape($this->id_sondage)."',";
218 $sql .= " ".(empty($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").",";
219 $sql .= " ".(int) $user->id.",";
220 $sql .= " '".$this->db->escape($this->title)."',";
221 $sql .= " '".$this->db->idate($this->date_fin)."',";
222 $sql .= " ".(int) $this->status.",";
223 $sql .= " '".$this->db->escape($this->format)."',";
224 $sql .= " ".((int) $this->mailsonde).",";
225 $sql .= " ".((int) $this->allow_comments).",";
226 $sql .= " ".((int) $this->allow_spy).",";
227 $sql .= " '".$this->db->escape($this->sujet)."',";
228 $sql .= " ".((int) $conf->entity);
229 $sql .= ")";
230
231 $this->db->begin();
232
233 dol_syslog(get_class($this)."::create", LOG_DEBUG);
234 $resql = $this->db->query($sql);
235 if (!$resql) {
236 $error++;
237 $this->errors[] = "Error ".$this->db->lasterror();
238 }
239
240 if (!$error && !$notrigger) {
241 // Call trigger
242 $result = $this->call_trigger('OPENSURVEY_CREATE', $user);
243 if ($result < 0) {
244 $error++;
245 }
246 // End call triggers
247 }
248
249 // Commit or rollback
250 if ($error) {
251 foreach ($this->errors as $errmsg) {
252 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
253 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
254 }
255 $this->db->rollback();
256 return -1 * $error;
257 } else {
258 $this->db->commit();
259 return $this->id;
260 }
261 }
262
263
271 public function fetch($id, $numsurvey = '')
272 {
273 $sql = "SELECT";
274 $sql .= " t.id_sondage,";
275 $sql .= " t.titre as title,";
276 $sql .= " t.commentaires as description,";
277 $sql .= " t.mail_admin,";
278 $sql .= " t.nom_admin,";
279 $sql .= " t.fk_user_creat,";
280 $sql .= " t.date_fin,";
281 $sql .= " t.status,";
282 $sql .= " t.format,";
283 $sql .= " t.mailsonde,";
284 $sql .= " t.allow_comments,";
285 $sql .= " t.allow_spy,";
286 $sql .= " t.sujet,";
287 $sql .= " t.tms";
288 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as t";
289 $sql .= " WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey)."'";
290
291 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
292 $resql = $this->db->query($sql);
293 if ($resql) {
294 if ($this->db->num_rows($resql)) {
295 $obj = $this->db->fetch_object($resql);
296
297 $this->id_sondage = $obj->id_sondage;
298 $this->ref = $this->id_sondage; //For compatibility
299
300 $this->description = $obj->description;
301 $this->mail_admin = $obj->mail_admin;
302 $this->nom_admin = $obj->nom_admin;
303 $this->title = $obj->title;
304 $this->date_fin = $this->db->jdate($obj->date_fin);
305 $this->status = $obj->status;
306 $this->format = $obj->format;
307 $this->mailsonde = $obj->mailsonde;
308 $this->allow_comments = $obj->allow_comments;
309 $this->allow_spy = $obj->allow_spy;
310 $this->sujet = $obj->sujet;
311 $this->fk_user_creat = $obj->fk_user_creat;
312
313 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms : "");
314 $ret = 1;
315 } else {
316 $sondage = ($id ? 'id='.$id : 'sondageid='.$numsurvey);
317 $this->error = 'Fetch no poll found for '.$sondage;
318 dol_syslog($this->error, LOG_ERR);
319 $ret = 0;
320 }
321
322 $this->db->free($resql);
323 } else {
324 $this->error = "Error ".$this->db->lasterror();
325 $ret = -1;
326 }
327
328 return $ret;
329 }
330
331
339 public function update(User $user, $notrigger = 0)
340 {
341 $error = 0;
342
343 // Clean parameters
344 $this->cleanParameters();
345
346 // Check parameters
347 // Put here code to add a control on parameters values
348
349 // Update request
350 $sql = "UPDATE ".MAIN_DB_PREFIX."opensurvey_sondage SET";
351 $sql .= " id_sondage=".(isset($this->id_sondage) ? "'".$this->db->escape($this->id_sondage)."'" : "null").",";
352 $sql .= " commentaires=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").",";
353 $sql .= " mail_admin=".(isset($this->mail_admin) ? "'".$this->db->escape($this->mail_admin)."'" : "null").",";
354 $sql .= " nom_admin=".(isset($this->nom_admin) ? "'".$this->db->escape($this->nom_admin)."'" : "null").",";
355 $sql .= " titre=".(isset($this->title) ? "'".$this->db->escape($this->title)."'" : "null").",";
356 $sql .= " date_fin=".(dol_strlen($this->date_fin) != 0 ? "'".$this->db->idate($this->date_fin)."'" : 'null').",";
357 $sql .= " status=".(isset($this->status) ? "'".$this->db->escape($this->status)."'" : "null").",";
358 $sql .= " format=".(isset($this->format) ? "'".$this->db->escape($this->format)."'" : "null").",";
359 $sql .= " mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) : "null").",";
360 $sql .= " allow_comments=".((int) $this->allow_comments).",";
361 $sql .= " allow_spy=".((int) $this->allow_spy);
362 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
363
364 $this->db->begin();
365
366 dol_syslog(get_class($this)."::update", LOG_DEBUG);
367 $resql = $this->db->query($sql);
368 if (!$resql) {
369 $error++;
370 $this->errors[] = "Error ".$this->db->lasterror();
371 }
372
373 if (!$error && !$notrigger) {
374 // Call trigger
375 $result = $this->call_trigger('OPENSURVEY_MODIFY', $user);
376 if ($result < 0) {
377 $error++;
378 }
379 // End call triggers
380 }
381
382 // Commit or rollback
383 if ($error) {
384 foreach ($this->errors as $errmsg) {
385 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
386 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
387 }
388 $this->db->rollback();
389 return -1 * $error;
390 } else {
391 $this->db->commit();
392 return 1;
393 }
394 }
395
404 public function delete(User $user, $notrigger = 0, $numsondage = '')
405 {
406 global $conf, $langs;
407 $error = 0;
408
409 if (empty($numsondage)) {
410 $numsondage = $this->id_sondage;
411 }
412
413 $this->db->begin();
414
415 if (!$error && !$notrigger) {
416 // Call trigger
417 $result = $this->call_trigger('OPENSURVEY_DELETE', $user);
418 if ($result < 0) {
419 $error++;
420 }
421 // End call triggers
422 }
423
424 if (!$error) {
425 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage)."'";
426 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
427 $resql = $this->db->query($sql);
428 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage)."'";
429 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
430 $resql = $this->db->query($sql);
431
432 $sql = "DELETE FROM ".MAIN_DB_PREFIX."opensurvey_sondage";
433 $sql .= " WHERE id_sondage = '".$this->db->escape($numsondage)."'";
434
435 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
436 $resql = $this->db->query($sql);
437 if (!$resql) {
438 $error++;
439 $this->errors[] = "Error ".$this->db->lasterror();
440 }
441 }
442
443 // Commit or rollback
444 if ($error) {
445 foreach ($this->errors as $errmsg) {
446 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
447 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
448 }
449 $this->db->rollback();
450 return -1 * $error;
451 } else {
452 $this->db->commit();
453 return 1;
454 }
455 }
456
464 public function getTooltipContentArray($params)
465 {
466 global $conf, $langs;
467
468 $langs->load('opensurvey');
469
470 $datas = [];
471 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("ShowSurvey").'</u>';
472 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
473 $datas['title'] = '<br><b>'.$langs->trans('Title').':</b> '.$this->title;
474
475 return $datas;
476 }
477
487 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
488 {
489 global $conf, $langs;
490
491 if (!empty($conf->dol_no_mouse_hover)) {
492 $notooltip = 1; // Force disable tooltips
493 }
494
495 $result = '';
496 $params = [
497 'id' => $this->id,
498 'objecttype' => $this->element,
499 ];
500 $classfortooltip = 'classfortooltip';
501 $dataparams = '';
502 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
503 $classfortooltip = 'classforajaxtooltip';
504 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
505 $label = '';
506 } else {
507 $label = implode($this->getTooltipContentArray($params));
508 }
509
510 $url = DOL_URL_ROOT.'/opensurvey/card.php?id='.$this->id;
511
512 // Add param to save lastsearch_values or not
513 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
514 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
515 $add_save_lastsearch_values = 1;
516 }
517 if ($add_save_lastsearch_values) {
518 $url .= '&save_lastsearch_values=1';
519 }
520
521 $linkclose = '';
522 if (empty($notooltip)) {
523 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
524 $label = $langs->trans("ShowMyObject");
525 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
526 }
527 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
528 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
529 } else {
530 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
531 }
532
533 $linkstart = '<a href="'.$url.'"';
534 $linkstart .= $linkclose.'>';
535 $linkend = '</a>';
536
537 $result .= $linkstart;
538 if ($withpicto) {
539 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
540 }
541 if ($withpicto != 2) {
542 $result .= $this->ref;
543 }
544 $result .= $linkend;
545
546 return $result;
547 }
548
549 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
555 public function fetch_lines()
556 {
557 // phpcs:enable
558 $this->lines = array();
559
560 $sql = "SELECT id_users, nom as name, reponses";
561 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
562 $sql .= " WHERE id_sondage = '".$this->db->escape($this->id_sondage)."'";
563
564 $resql = $this->db->query($sql);
565
566 if ($resql) {
567 $num = $this->db->num_rows($resql);
568 $i = 0;
569 while ($i < $num) {
570 $obj = $this->db->fetch_object($resql);
571 $tmp = array('id_users'=>$obj->id_users, 'nom'=>$obj->name, 'reponses'=>$obj->reponses);
572
573 $this->lines[] = $tmp;
574 $i++;
575 }
576 } else {
577 dol_print_error($this->db);
578 }
579
580 return count($this->lines);
581 }
582
589 public function initAsSpecimen()
590 {
591 $this->id = 0;
592
593 $this->id_sondage = 'a12d5g';
594 $this->description = 'Description of the specimen survey';
595 $this->mail_admin = 'email@email.com';
596 $this->nom_admin = 'surveyadmin';
597 $this->title = 'This is a specimen survey';
598 $this->date_fin = dol_now() + 3600 * 24 * 10;
599 $this->status = 1;
600 $this->format = 'classic';
601 $this->mailsonde = 0;
602 }
603
609 public function getComments()
610 {
611 $comments = array();
612
613 $sql = 'SELECT id_comment, usercomment, comment';
614 $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
615 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
616 $sql .= " ORDER BY id_comment";
617 $resql = $this->db->query($sql);
618
619 if ($resql) {
620 $num_rows = $this->db->num_rows($resql);
621
622 if ($num_rows > 0) {
623 while ($obj = $this->db->fetch_object($resql)) {
624 $comments[] = $obj;
625 }
626 }
627 }
628
629 return $comments;
630 }
631
640 public function addComment($comment, $comment_user, $user_ip = '')
641 {
642 $now = dol_now();
643 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
644 $sql .= " VALUES ('".$this->db->escape($this->id_sondage)."','".$this->db->escape($comment)."','".$this->db->escape($comment_user)."','".$this->db->idate($now)."'".($user_ip ? ",'".$this->db->escape($user_ip)."'" : '').")";
645 $resql = $this->db->query($sql);
646
647 if (!$resql) {
648 return false;
649 }
650
651 return true;
652 }
653
660 public function deleteComment($id_comment)
661 {
662 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.((int) $id_comment).' AND id_sondage = "'.$this->db->escape($this->id_sondage).'"';
663 $resql = $this->db->query($sql);
664
665 if (!$resql) {
666 return false;
667 }
668
669 return true;
670 }
671
677 private function cleanParameters()
678 {
679 $this->id_sondage = trim($this->id_sondage);
680 $this->description = trim($this->description);
681 $this->mail_admin = trim($this->mail_admin);
682 $this->nom_admin = trim($this->nom_admin);
683 $this->title = trim($this->title);
684 $this->status = (int) $this->status;
685 $this->format = trim($this->format);
686 $this->mailsonde = ($this->mailsonde ? 1 : 0);
687 $this->allow_comments = ($this->allow_comments ? 1 : 0);
688 $this->allow_spy = ($this->allow_spy ? 1 : 0);
689 $this->sujet = trim($this->sujet);
690 }
691
692
699 public function getLibStatut($mode)
700 {
701 return $this->LibStatut($this->status, $mode);
702 }
703
704 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
712 public function LibStatut($status, $mode)
713 {
714 // phpcs:enable
715 global $langs, $conf;
716
717 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
718 global $langs;
719 //$langs->load("mymodule");
720 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
721 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
722 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
723 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
724 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
725 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
726 }
727
728 $statusType = 'status'.$status;
729 if ($status == self::STATUS_VALIDATED) {
730 if (0) {
731 $statusType = 'status1';
732 } else {
733 $statusType = 'status4';
734 }
735 }
736 if ($status == self::STATUS_CLOSED) {
737 $statusType = 'status6';
738 }
739
740 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
741 }
742
743
749 public function countVotes()
750 {
751 $result = 0;
752
753 $sql = " SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
754 $sql .= " WHERE id_sondage = '".$this->db->escape($this->ref)."'";
755
756 $resql = $this->db->query($sql);
757 if ($resql) {
758 $obj = $this->db->fetch_object($resql);
759 if ($obj) {
760 $result = $obj->nb;
761 }
762 } else {
763 $this->error = $this->db->lasterror();
764 $this->errors[] = $this->error;
765 }
766
767 return $result;
768 }
769
781 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND')
782 {
783 dol_syslog(__METHOD__, LOG_DEBUG);
784
785 $records = array();
786
787 $sql = 'SELECT ';
788 $sql .= $this->getFieldList();
789 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
790 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
791 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
792 } else {
793 $sql .= ' WHERE 1 = 1';
794 }
795 // Manage filter
796 $sqlwhere = array();
797 if (count($filter) > 0) {
798 foreach ($filter as $key => $value) {
799 if ($key == 't.rowid') {
800 $sqlwhere[] = $key." = ".((int) $value);
801 } elseif (array_key_exists($key, $this->fields) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
802 $sqlwhere[] = $key." = '".$this->db->idate($value)."'";
803 } elseif ($key == 'customsql') {
804 $sqlwhere[] = $value;
805 } elseif (strpos($value, '%') === false) {
806 $sqlwhere[] = $key." IN (".$this->db->sanitize($this->db->escape($value)).")";
807 } else {
808 $sqlwhere[] = $key." LIKE '%".$this->db->escape($value)."%'";
809 }
810 }
811 }
812 if (count($sqlwhere) > 0) {
813 $sql .= ' AND ('.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere).')';
814 }
815
816 if (!empty($sortfield)) {
817 $sql .= $this->db->order($sortfield, $sortorder);
818 }
819 if (!empty($limit)) {
820 $sql .= $this->db->plimit($limit, $offset);
821 }
822
823 $resql = $this->db->query($sql);
824 if ($resql) {
825 $num = $this->db->num_rows($resql);
826 $i = 0;
827 while ($i < ($limit ? min($limit, $num) : $num)) {
828 $obj = $this->db->fetch_object($resql);
829
830 $record = new self($this->db);
831 $record->setVarsFromFetchObj($obj);
832
833 $records[$record->id_sondage] = $record;
834
835 $i++;
836 }
837 $this->db->free($resql);
838
839 return $records;
840 } else {
841 $this->errors[] = 'Error '.$this->db->lasterror();
842 dol_syslog(__METHOD__.' '.join(',', $this->errors), LOG_ERR);
843
844 return -1;
845 }
846 }
847}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Definition security.php:604
$object ref
Definition info.php:79
Parent class of all other business classes (invoices, contracts, proposals, orders,...
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Put here description of your class.
cleanParameters()
Cleans all the class variables before doing an update or an insert.
getLibStatut($mode)
Return status label of Order.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
deleteComment($id_comment)
Deletes a comment of the poll.
create(User $user, $notrigger=0)
Create object into database.
fetch($id, $numsurvey='')
Load object in memory from the database.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
const STATUS_VALIDATED
Validated/Opened status.
update(User $user, $notrigger=0)
Update object into database.
getTooltipContentArray($params)
getTooltipContentArray
getComments()
Returns all comments for the current opensurvey poll.
fetch_lines()
Return array of lines.
const STATUS_DRAFT
Draft status (not used)
getNomUrl($withpicto=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return a link to the object card (with optionaly the picto)
countVotes()
Return number of votes done for this survey.
LibStatut($status, $mode)
Return label of status.
addComment($comment, $comment_user, $user_ip='')
Adds a comment to the poll.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.