dolibarr 25.0.0-alpha
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-2026 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
28// Put here all includes required by your class file
29require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
30
31
36{
40 public $element = 'opensurvey_sondage';
41
45 public $table_element = 'opensurvey_sondage';
46
50 public $table_rowid = 'id_sondage';
51
55 public $picto = 'poll';
56
60 public $description;
61
65 public $date_m;
66
67
73 public $lines; // @phpstan-ignore-line
74
114 // BEGIN MODULEBUILDER PROPERTIES
118 public $fields = array(
119 'id_sondage' => array('type' => 'varchar(16)', 'label' => 'Idsondage', 'enabled' => '1', 'position' => 10, 'notnull' => 1, 'visible' => -1,),
120 'commentaires' => array('type' => 'mediumtext', 'label' => 'Comments', 'enabled' => '1', 'position' => 15, 'notnull' => 0, 'visible' => -1,),
121 'mail_admin' => array('type' => 'varchar(128)', 'label' => 'Mailadmin', 'enabled' => '1', 'position' => 20, 'notnull' => 0, 'visible' => -1,),
122 'nom_admin' => array('type' => 'varchar(64)', 'label' => 'Nomadmin', 'enabled' => '1', 'position' => 25, 'notnull' => 0, 'visible' => -1,),
123 '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',),
124 'titre' => array('type' => 'mediumtext', 'label' => 'Title', 'enabled' => '1', 'position' => 35, 'notnull' => 1, 'visible' => -1,),
125 'date_fin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => '1', 'position' => 40, 'notnull' => 1, 'visible' => -1,),
126 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => '1', 'position' => 500, 'notnull' => 0, 'visible' => -1,),
127 'format' => array('type' => 'varchar(2)', 'label' => 'Format', 'enabled' => '1', 'position' => 50, 'notnull' => 1, 'visible' => -1,),
128 'mailsonde' => array('type' => 'integer', 'label' => 'Mailsonde', 'enabled' => '1', 'position' => 55, 'notnull' => 1, 'visible' => -1,),
129 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 60, 'notnull' => 1, 'visible' => -1,),
130 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 65, 'notnull' => 1, 'visible' => -2, 'default' => '1', 'index' => 1,),
131 'allow_comments' => array('type' => 'integer', 'label' => 'Allowcomments', 'enabled' => '1', 'position' => 70, 'notnull' => 1, 'visible' => -1,),
132 'allow_spy' => array('type' => 'integer', 'label' => 'Allowspy', 'enabled' => '1', 'position' => 75, 'notnull' => 1, 'visible' => -1,),
133 'sujet' => array('type' => 'mediumtext', 'label' => 'Sujet', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => -1,),
134 //'id_sondage_admin' => array('type' => 'char(24)', 'label' => 'Idsondageadmin', 'enabled' => '1', 'position' => 85, 'notnull' => 0, 'visible' => -1,),
135 );
136
140 public $id_sondage;
141
146 public $commentaires;
147
151 public $mail_admin;
152
156 public $nom_admin;
157
161 public $fk_user_creat;
162
167 public $titre;
168
172 public $title;
173
177 public $date_fin = '';
178
182 public $status;
183
187 public $format;
188
192 public $mailsonde;
193
197 public $allow_comments;
198
202 public $allow_spy;
203
207 public $sujet;
208
212 public $id_sondage_admin;
213 // END MODULEBUILDER PROPERTIES
214
218 const STATUS_DRAFT = 0;
226 const STATUS_CLOSED = 2;
227
228
234 public function __construct($db)
235 {
236 $this->db = $db;
237 }
238
239
247 public function create(User $user, $notrigger = 0)
248 {
249 global $conf;
250
251 $error = 0;
252
253 // Clean parameters
254 $this->cleanParameters();
255
256 // Check parameters
257 if (!$this->date_fin > 0) {
258 $this->error = 'BadValueForEndDate';
259 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
260 return -1;
261 }
262
263 // Insert request
264 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_sondage(";
265 $sql .= "id_sondage,";
266 $sql .= "commentaires,";
267 $sql .= "fk_user_creat,";
268 $sql .= "titre,";
269 $sql .= "date_fin,";
270 $sql .= "status,";
271 $sql .= "format,";
272 $sql .= "mailsonde,";
273 $sql .= "allow_comments,";
274 $sql .= "allow_spy,";
275 $sql .= "sujet,";
276 $sql .= "entity";
277 $sql .= ") VALUES (";
278 $sql .= "'".$this->db->escape($this->id_sondage)."',";
279 $sql .= " ".(empty($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").",";
280 $sql .= " ".(int) $user->id.",";
281 $sql .= " '".$this->db->escape((string) $this->title)."',";
282 $sql .= " '".$this->db->idate($this->date_fin)."',";
283 $sql .= " ".(int) $this->status.",";
284 $sql .= " '".$this->db->escape((string) $this->format)."',";
285 $sql .= " ".((int) $this->mailsonde).",";
286 $sql .= " ".((int) $this->allow_comments).",";
287 $sql .= " ".((int) $this->allow_spy).",";
288 $sql .= " '".$this->db->escape($this->sujet)."',";
289 $sql .= " ".((int) $conf->entity);
290 $sql .= ")";
291
292 $this->db->begin();
293
294 dol_syslog(get_class($this)."::create", LOG_DEBUG);
295 $resql = $this->db->query($sql);
296 if (!$resql) {
297 $error++;
298 $this->errors[] = "Error ".$this->db->lasterror();
299 }
300
301 if (!$error && !$notrigger) {
302 // Call trigger
303 $result = $this->call_trigger('OPENSURVEY_CREATE', $user);
304 if ($result < 0) {
305 $error++;
306 }
307 // End call triggers
308 }
309
310 // Commit or rollback
311 if ($error) {
312 foreach ($this->errors as $errmsg) {
313 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
314 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
315 }
316 $this->db->rollback();
317 return -1 * $error;
318 } else {
319 $this->db->commit();
320 return $this->id;
321 }
322 }
323
324
332 public function fetch($id, $numsurvey = '')
333 {
334 $sql = "SELECT";
335 $sql .= " t.id_sondage,";
336 $sql .= " t.titre as title,";
337 $sql .= " t.commentaires as description,";
338 $sql .= " t.mail_admin,";
339 $sql .= " t.nom_admin,";
340 $sql .= " t.fk_user_creat,";
341 $sql .= " t.date_fin,";
342 $sql .= " t.status,";
343 $sql .= " t.format,";
344 $sql .= " t.mailsonde,";
345 $sql .= " t.allow_comments,";
346 $sql .= " t.allow_spy,";
347 $sql .= " t.sujet,";
348 $sql .= " t.tms";
349 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as t";
350 $sql .= " WHERE t.id_sondage = '".$this->db->escape($id ? ((int) $id) : $numsurvey)."'";
351
352 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
353 $resql = $this->db->query($sql);
354 if ($resql) {
355 if ($this->db->num_rows($resql)) {
356 $obj = $this->db->fetch_object($resql);
357
358 $this->id_sondage = $obj->id_sondage;
359 $this->ref = $this->id_sondage; //For compatibility
360
361 $this->description = $obj->description;
362 $this->mail_admin = $obj->mail_admin;
363 $this->nom_admin = $obj->nom_admin;
364 $this->title = $obj->title;
365 $this->date_fin = $this->db->jdate($obj->date_fin);
366 $this->status = $obj->status;
367 $this->format = $obj->format;
368 $this->mailsonde = $obj->mailsonde;
369 $this->allow_comments = $obj->allow_comments;
370 $this->allow_spy = $obj->allow_spy;
371 $this->sujet = $obj->sujet;
372 $this->fk_user_creat = $obj->fk_user_creat;
373
374 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms : "");
375 $ret = 1;
376 } else {
377 $sondage = ($id ? 'id='.$id : 'sondageid='.$numsurvey);
378 $this->error = 'Fetch no poll found for '.$sondage;
379 dol_syslog($this->error, LOG_ERR);
380 $ret = 0;
381 }
382
383 $this->db->free($resql);
384 } else {
385 $this->error = "Error ".$this->db->lasterror();
386 $ret = -1;
387 }
388
389 return $ret;
390 }
391
392
400 public function update(User $user, $notrigger = 0)
401 {
402 $error = 0;
403
404 // Clean parameters
405 $this->cleanParameters();
406
407 // Check parameters
408 // Put here code to add a control on parameters values
409
410 // Update request
411 $sql = "UPDATE ".MAIN_DB_PREFIX."opensurvey_sondage SET";
412 $sql .= " id_sondage=".(isset($this->id_sondage) ? "'".$this->db->escape($this->id_sondage)."'" : "null").",";
413 $sql .= " commentaires=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").",";
414 $sql .= " mail_admin=".(isset($this->mail_admin) ? "'".$this->db->escape($this->mail_admin)."'" : "null").",";
415 $sql .= " nom_admin=".(isset($this->nom_admin) ? "'".$this->db->escape($this->nom_admin)."'" : "null").",";
416 $sql .= " titre=".(isset($this->title) ? "'".$this->db->escape($this->title)."'" : "null").",";
417 $sql .= " date_fin=".(dol_strlen($this->date_fin) != 0 ? "'".$this->db->idate($this->date_fin)."'" : 'null').",";
418 $sql .= " status=".(!empty($this->status) ? (int) $this->status : "null").",";
419 $sql .= " format=".(isset($this->format) ? "'".$this->db->escape($this->format)."'" : "null").",";
420 $sql .= " mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) : "null").",";
421 $sql .= " allow_comments=".((int) $this->allow_comments).",";
422 $sql .= " allow_spy=".((int) $this->allow_spy);
423 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
424
425 $this->db->begin();
426
427 dol_syslog(get_class($this)."::update", LOG_DEBUG);
428 $resql = $this->db->query($sql);
429 if (!$resql) {
430 $error++;
431 $this->errors[] = "Error ".$this->db->lasterror();
432 }
433
434 if (!$error && !$notrigger) {
435 // Call trigger
436 $result = $this->call_trigger('OPENSURVEY_MODIFY', $user);
437 if ($result < 0) {
438 $error++;
439 }
440 // End call triggers
441 }
442
443 // Commit or rollback
444 if ($error) {
445 foreach ($this->errors as $errmsg) {
446 dol_syslog(get_class($this)."::update ".$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
465 public function delete(User $user, $notrigger = 0, $numsondage = '')
466 {
467 global $conf, $langs;
468 $error = 0;
469
470 if (empty($numsondage)) {
471 $numsondage = $this->id_sondage;
472 }
473
474 $this->db->begin();
475
476 if (!$error && !$notrigger) {
477 // Call trigger
478 $result = $this->call_trigger('OPENSURVEY_DELETE', $user);
479 if ($result < 0) {
480 $error++;
481 }
482 // End call triggers
483 }
484
485 if (!$error) {
486 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage)."'";
487 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
488 $resql = $this->db->query($sql);
489 // Answers and questions of a survey of format 'F' (form), the answers must be deleted before the respondents they refer to
490 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_user_formanswers WHERE fk_user_survey IN";
491 $sql .= " (SELECT id_users FROM ".MAIN_DB_PREFIX."opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage)."')";
492 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
493 $resql = $this->db->query($sql);
494 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_formquestions WHERE id_sondage = '".$this->db->escape($numsondage)."'";
495 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
496 $resql = $this->db->query($sql);
497 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage)."'";
498 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
499 $resql = $this->db->query($sql);
500
501 $sql = "DELETE FROM ".MAIN_DB_PREFIX."opensurvey_sondage";
502 $sql .= " WHERE id_sondage = '".$this->db->escape($numsondage)."'";
503
504 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
505 $resql = $this->db->query($sql);
506 if (!$resql) {
507 $error++;
508 $this->errors[] = "Error ".$this->db->lasterror();
509 }
510 }
511
512 // Commit or rollback
513 if ($error) {
514 foreach ($this->errors as $errmsg) {
515 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
516 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
517 }
518 $this->db->rollback();
519 return -1 * $error;
520 } else {
521 $this->db->commit();
522 return 1;
523 }
524 }
525
532 public function getTooltipContentArray($params)
533 {
534 global $conf, $langs;
535
536 $langs->load('opensurvey');
537
538 $datas = [];
539 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("ShowSurvey").'</u>';
540 if (isset($this->status)) {
541 $datas['picto'] .= ' '.$this->getLibStatut(5);
542 }
543 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
544 if (!empty($this->date_fin)) {
545 $datas['expire_date'] = '<br><b>'.$langs->trans('ExpireDate').':</b> '.dol_print_date($this->date_fin, 'day');
546 if ($this->date_fin && $this->date_fin < dol_now() && $this->status == Opensurveysondage::STATUS_VALIDATED) {
547 $datas['expire_date'] .= img_warning($langs->trans("Expired"));
548 }
549 }
550 $datas['title'] = '<br><b>'.$langs->trans('Title').':</b> '.$this->title;
551 if (!empty($this->description)) {
552 $datas['description'] = '<br><b>'.$langs->trans('Description').':</b> '.$this->description;
553 }
554
555 return $datas;
556 }
557
567 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
568 {
569 global $conf, $hookmanager, $langs;
570
571 if (!empty($conf->dol_no_mouse_hover)) {
572 $notooltip = 1; // Force disable tooltips
573 }
574
575 $result = '';
576 $params = [
577 'id' => $this->id,
578 'objecttype' => $this->element,
579 ];
580 $classfortooltip = 'classfortooltip';
581 $dataparams = '';
582 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
583 $classfortooltip = 'classforajaxtooltip';
584 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
585 $label = '';
586 } else {
587 $label = implode($this->getTooltipContentArray($params));
588 }
589
590 $url = DOL_URL_ROOT.'/opensurvey/card.php?id='.$this->id;
591
592 // Add param to save lastsearch_values or not
593 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
594 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
595 $add_save_lastsearch_values = 1;
596 }
597 if ($add_save_lastsearch_values) {
598 $url .= '&save_lastsearch_values=1';
599 }
600
601 $linkclose = '';
602 if (empty($notooltip)) {
603 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
604 $label = $langs->trans("ShowMyObject");
605 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
606 }
607 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
608 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
609 } else {
610 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
611 }
612
613 $linkstart = '<a href="'.$url.'"';
614 $linkstart .= $linkclose.'>';
615 $linkend = '</a>';
616
617 $result .= $linkstart;
618 if ($withpicto) {
619 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
620 }
621 if ($withpicto != 2) {
622 $result .= $this->ref;
623 }
624 $result .= $linkend;
625
626 global $action;
627 $hookmanager->initHooks(array($this->element . 'dao'));
628 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
629 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
630 if ($reshook > 0) {
631 $result = $hookmanager->resPrint;
632 } else {
633 $result .= $hookmanager->resPrint;
634 }
635
636 return $result;
637 }
638
639 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
645 public function fetch_lines()
646 {
647 // phpcs:enable
648 $this->lines = array();
649
650 $sql = "SELECT id_users, nom as name, reponses";
651 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
652 $sql .= " WHERE id_sondage = '".$this->db->escape($this->id_sondage)."'";
653
654 $resql = $this->db->query($sql);
655
656 if ($resql) {
657 $num = $this->db->num_rows($resql);
658 $i = 0;
659 while ($i < $num) {
660 $obj = $this->db->fetch_object($resql);
661 $tmp = array('id_users' => $obj->id_users, 'nom' => $obj->name, 'reponses' => $obj->reponses);
662
663 $this->lines[] = $tmp;
664 $i++;
665 }
666 } else {
667 dol_print_error($this->db);
668 }
669
670 return count($this->lines);
671 }
672
679 public function initAsSpecimen()
680 {
681 $this->id = 0;
682
683 $this->id_sondage = 'a12d5g';
684 $this->description = 'Description of the specimen survey';
685 $this->mail_admin = 'email@email.com';
686 $this->nom_admin = 'surveyadmin';
687 $this->title = 'This is a specimen survey';
688 $this->date_fin = dol_now() + 3600 * 24 * 10;
689 $this->status = 1;
690 $this->format = 'classic';
691 $this->mailsonde = 0;
692
693 return 1;
694 }
695
701 public function getComments()
702 {
703 $comments = array();
704
705 $sql = 'SELECT id_comment, usercomment, comment';
706 $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
707 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
708 $sql .= " ORDER BY id_comment";
709 $resql = $this->db->query($sql);
710
711 if ($resql) {
712 $num_rows = $this->db->num_rows($resql);
713
714 if ($num_rows > 0) {
715 while ($obj = $this->db->fetch_object($resql)) {
716 $comments[] = $obj;
717 }
718 }
719 }
720
721 return $comments;
722 }
723
732 public function addComment($comment, $comment_user, $user_ip = '')
733 {
734 $now = dol_now();
735 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
736 $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)."'" : '').")";
737 $resql = $this->db->query($sql);
738
739 if (!$resql) {
740 return false;
741 }
742
743 return true;
744 }
745
752 public function deleteComment($id_comment)
753 {
754 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.((int) $id_comment).' AND id_sondage = "'.$this->db->escape($this->id_sondage).'"';
755 $resql = $this->db->query($sql);
756
757 if (!$resql) {
758 return false;
759 }
760
761 return true;
762 }
763
769 private function cleanParameters()
770 {
771 $this->id_sondage = trim($this->id_sondage);
772 $this->description = trim($this->description);
773 $this->mail_admin = trim($this->mail_admin);
774 $this->nom_admin = trim($this->nom_admin);
775 $this->title = trim($this->title);
776 $this->status = (int) $this->status;
777 $this->format = trim($this->format);
778 $this->mailsonde = ($this->mailsonde ? 1 : 0);
779 $this->allow_comments = ($this->allow_comments ? 1 : 0);
780 $this->allow_spy = ($this->allow_spy ? 1 : 0);
781 $this->sujet = trim($this->sujet);
782 }
783
784
791 public function getLibStatut($mode)
792 {
793 return $this->LibStatut($this->status, $mode);
794 }
795
796 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
804 public function LibStatut($status, $mode)
805 {
806 // phpcs:enable
807 global $langs, $conf;
808
809 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
810 global $langs;
811 //$langs->load("mymodule");
812 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
813 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
814 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
815 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
816 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
817 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
818 }
819
820 $statusType = 'status'.$status;
821 if ($status == self::STATUS_VALIDATED) {
822 $statusType = 'status4';
823 }
824 if ($status == self::STATUS_CLOSED) {
825 $statusType = 'status6';
826 }
827
828 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
829 }
830
831
837 public function countVotes()
838 {
839 $result = 0;
840
841 $sql = " SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
842 $sql .= " WHERE id_sondage = '".$this->db->escape($this->ref)."'";
843
844 $resql = $this->db->query($sql);
845 if ($resql) {
846 $obj = $this->db->fetch_object($resql);
847 if ($obj) {
848 $result = $obj->nb;
849 }
850 } else {
851 $this->error = $this->db->lasterror();
852 $this->errors[] = $this->error;
853 }
854
855 return $result;
856 }
857
870 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
871 {
872 dol_syslog(__METHOD__, LOG_DEBUG);
873
874 $records = array();
875
876 $sql = 'SELECT ';
877 $sql .= $this->getFieldList();
878 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
879 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
880 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
881 } else {
882 $sql .= ' WHERE 1 = 1';
883 }
884
885 // Manage filter
886 $errormessage = '';
887 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
888 if ($errormessage) {
889 $this->errors[] = $errormessage;
890 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
891 return -1;
892 }
893
894 if (!empty($sortfield)) {
895 $sql .= $this->db->order($sortfield, $sortorder);
896 }
897 if (!empty($limit)) {
898 $sql .= $this->db->plimit($limit, $offset);
899 }
900
901 $resql = $this->db->query($sql);
902 if ($resql) {
903 $num = $this->db->num_rows($resql);
904 $i = 0;
905 while ($i < ($limit ? min($limit, $num) : $num)) {
906 $obj = $this->db->fetch_object($resql);
907
908 $record = new self($this->db);
909 $record->setVarsFromFetchObj($obj);
910
911 $records[$record->id_sondage] = $record;
912
913 $i++;
914 }
915 $this->db->free($resql);
916
917 return $records;
918 } else {
919 $this->errors[] = 'Error '.$this->db->lasterror();
920 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
921
922 return -1;
923 }
924 }
925}
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
$object ref
Definition info.php:90
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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.
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
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load list of objects in memory from the database.
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 optionally 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 $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:169
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_now($mode='gmt')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0, $forbiddenfields=array())
forgeSQLFromUniversalSearchCriteria
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.