dolibarr 24.0.0-beta
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;
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 ? $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 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage)."'";
490 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
491 $resql = $this->db->query($sql);
492
493 $sql = "DELETE FROM ".MAIN_DB_PREFIX."opensurvey_sondage";
494 $sql .= " WHERE id_sondage = '".$this->db->escape($numsondage)."'";
495
496 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
497 $resql = $this->db->query($sql);
498 if (!$resql) {
499 $error++;
500 $this->errors[] = "Error ".$this->db->lasterror();
501 }
502 }
503
504 // Commit or rollback
505 if ($error) {
506 foreach ($this->errors as $errmsg) {
507 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
508 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
509 }
510 $this->db->rollback();
511 return -1 * $error;
512 } else {
513 $this->db->commit();
514 return 1;
515 }
516 }
517
524 public function getTooltipContentArray($params)
525 {
526 global $conf, $langs;
527
528 $langs->load('opensurvey');
529
530 $datas = [];
531 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("ShowSurvey").'</u>';
532 if (isset($this->status)) {
533 $datas['picto'] .= ' '.$this->getLibStatut(5);
534 }
535 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
536 if (!empty($this->date_fin)) {
537 $datas['expire_date'] = '<br><b>'.$langs->trans('ExpireDate').':</b> '.dol_print_date($this->date_fin, 'day');
538 if ($this->date_fin && $this->date_fin < dol_now() && $this->status == Opensurveysondage::STATUS_VALIDATED) {
539 $datas['expire_date'] .= img_warning($langs->trans("Expired"));
540 }
541 }
542 $datas['title'] = '<br><b>'.$langs->trans('Title').':</b> '.$this->title;
543 if (!empty($this->description)) {
544 $datas['description'] = '<br><b>'.$langs->trans('Description').':</b> '.$this->description;
545 }
546
547 return $datas;
548 }
549
559 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
560 {
561 global $conf, $hookmanager, $langs;
562
563 if (!empty($conf->dol_no_mouse_hover)) {
564 $notooltip = 1; // Force disable tooltips
565 }
566
567 $result = '';
568 $params = [
569 'id' => $this->id,
570 'objecttype' => $this->element,
571 ];
572 $classfortooltip = 'classfortooltip';
573 $dataparams = '';
574 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
575 $classfortooltip = 'classforajaxtooltip';
576 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
577 $label = '';
578 } else {
579 $label = implode($this->getTooltipContentArray($params));
580 }
581
582 $url = DOL_URL_ROOT.'/opensurvey/card.php?id='.$this->id;
583
584 // Add param to save lastsearch_values or not
585 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
586 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
587 $add_save_lastsearch_values = 1;
588 }
589 if ($add_save_lastsearch_values) {
590 $url .= '&save_lastsearch_values=1';
591 }
592
593 $linkclose = '';
594 if (empty($notooltip)) {
595 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
596 $label = $langs->trans("ShowMyObject");
597 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
598 }
599 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
600 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
601 } else {
602 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
603 }
604
605 $linkstart = '<a href="'.$url.'"';
606 $linkstart .= $linkclose.'>';
607 $linkend = '</a>';
608
609 $result .= $linkstart;
610 if ($withpicto) {
611 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
612 }
613 if ($withpicto != 2) {
614 $result .= $this->ref;
615 }
616 $result .= $linkend;
617
618 global $action;
619 $hookmanager->initHooks(array($this->element . 'dao'));
620 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
621 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
622 if ($reshook > 0) {
623 $result = $hookmanager->resPrint;
624 } else {
625 $result .= $hookmanager->resPrint;
626 }
627
628 return $result;
629 }
630
631 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
637 public function fetch_lines()
638 {
639 // phpcs:enable
640 $this->lines = array();
641
642 $sql = "SELECT id_users, nom as name, reponses";
643 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
644 $sql .= " WHERE id_sondage = '".$this->db->escape($this->id_sondage)."'";
645
646 $resql = $this->db->query($sql);
647
648 if ($resql) {
649 $num = $this->db->num_rows($resql);
650 $i = 0;
651 while ($i < $num) {
652 $obj = $this->db->fetch_object($resql);
653 $tmp = array('id_users' => $obj->id_users, 'nom' => $obj->name, 'reponses' => $obj->reponses);
654
655 $this->lines[] = $tmp;
656 $i++;
657 }
658 } else {
659 dol_print_error($this->db);
660 }
661
662 return count($this->lines);
663 }
664
671 public function initAsSpecimen()
672 {
673 $this->id = 0;
674
675 $this->id_sondage = 'a12d5g';
676 $this->description = 'Description of the specimen survey';
677 $this->mail_admin = 'email@email.com';
678 $this->nom_admin = 'surveyadmin';
679 $this->title = 'This is a specimen survey';
680 $this->date_fin = dol_now() + 3600 * 24 * 10;
681 $this->status = 1;
682 $this->format = 'classic';
683 $this->mailsonde = 0;
684
685 return 1;
686 }
687
693 public function getComments()
694 {
695 $comments = array();
696
697 $sql = 'SELECT id_comment, usercomment, comment';
698 $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
699 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
700 $sql .= " ORDER BY id_comment";
701 $resql = $this->db->query($sql);
702
703 if ($resql) {
704 $num_rows = $this->db->num_rows($resql);
705
706 if ($num_rows > 0) {
707 while ($obj = $this->db->fetch_object($resql)) {
708 $comments[] = $obj;
709 }
710 }
711 }
712
713 return $comments;
714 }
715
724 public function addComment($comment, $comment_user, $user_ip = '')
725 {
726 $now = dol_now();
727 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
728 $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)."'" : '').")";
729 $resql = $this->db->query($sql);
730
731 if (!$resql) {
732 return false;
733 }
734
735 return true;
736 }
737
744 public function deleteComment($id_comment)
745 {
746 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.((int) $id_comment).' AND id_sondage = "'.$this->db->escape($this->id_sondage).'"';
747 $resql = $this->db->query($sql);
748
749 if (!$resql) {
750 return false;
751 }
752
753 return true;
754 }
755
761 private function cleanParameters()
762 {
763 $this->id_sondage = trim($this->id_sondage);
764 $this->description = trim($this->description);
765 $this->mail_admin = trim($this->mail_admin);
766 $this->nom_admin = trim($this->nom_admin);
767 $this->title = trim($this->title);
768 $this->status = (int) $this->status;
769 $this->format = trim($this->format);
770 $this->mailsonde = ($this->mailsonde ? 1 : 0);
771 $this->allow_comments = ($this->allow_comments ? 1 : 0);
772 $this->allow_spy = ($this->allow_spy ? 1 : 0);
773 $this->sujet = trim($this->sujet);
774 }
775
776
783 public function getLibStatut($mode)
784 {
785 return $this->LibStatut($this->status, $mode);
786 }
787
788 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
796 public function LibStatut($status, $mode)
797 {
798 // phpcs:enable
799 global $langs, $conf;
800
801 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
802 global $langs;
803 //$langs->load("mymodule");
804 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
805 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
806 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
807 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
808 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
809 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
810 }
811
812 $statusType = 'status'.$status;
813 if ($status == self::STATUS_VALIDATED) {
814 $statusType = 'status4';
815 }
816 if ($status == self::STATUS_CLOSED) {
817 $statusType = 'status6';
818 }
819
820 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
821 }
822
823
829 public function countVotes()
830 {
831 $result = 0;
832
833 $sql = " SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
834 $sql .= " WHERE id_sondage = '".$this->db->escape($this->ref)."'";
835
836 $resql = $this->db->query($sql);
837 if ($resql) {
838 $obj = $this->db->fetch_object($resql);
839 if ($obj) {
840 $result = $obj->nb;
841 }
842 } else {
843 $this->error = $this->db->lasterror();
844 $this->errors[] = $this->error;
845 }
846
847 return $result;
848 }
849
862 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
863 {
864 dol_syslog(__METHOD__, LOG_DEBUG);
865
866 $records = array();
867
868 $sql = 'SELECT ';
869 $sql .= $this->getFieldList();
870 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
871 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
872 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
873 } else {
874 $sql .= ' WHERE 1 = 1';
875 }
876
877 // Manage filter
878 $errormessage = '';
879 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
880 if ($errormessage) {
881 $this->errors[] = $errormessage;
882 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
883 return -1;
884 }
885
886 if (!empty($sortfield)) {
887 $sql .= $this->db->order($sortfield, $sortorder);
888 }
889 if (!empty($limit)) {
890 $sql .= $this->db->plimit($limit, $offset);
891 }
892
893 $resql = $this->db->query($sql);
894 if ($resql) {
895 $num = $this->db->num_rows($resql);
896 $i = 0;
897 while ($i < ($limit ? min($limit, $num) : $num)) {
898 $obj = $this->db->fetch_object($resql);
899
900 $record = new self($this->db);
901 $record->setVarsFromFetchObj($obj);
902
903 $records[$record->id_sondage] = $record;
904
905 $i++;
906 }
907 $this->db->free($resql);
908
909 return $records;
910 } else {
911 $this->errors[] = 'Error '.$this->db->lasterror();
912 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
913
914 return -1;
915 }
916 }
917}
$object ref
Definition info.php:90
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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:168
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.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.