dolibarr 22.0.5
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-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024-2025 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 $picto = 'poll';
51
55 public $description;
56
60 public $date_m;
61
62
68 public $lines;
69
109 // BEGIN MODULEBUILDER PROPERTIES
113 public $fields = array(
114 'id_sondage' => array('type' => 'varchar(16)', 'label' => 'Idsondage', 'enabled' => '1', 'position' => 10, 'notnull' => 1, 'visible' => -1,),
115 'commentaires' => array('type' => 'mediumtext', 'label' => 'Comments', 'enabled' => '1', 'position' => 15, 'notnull' => 0, 'visible' => -1,),
116 'mail_admin' => array('type' => 'varchar(128)', 'label' => 'Mailadmin', 'enabled' => '1', 'position' => 20, 'notnull' => 0, 'visible' => -1,),
117 'nom_admin' => array('type' => 'varchar(64)', 'label' => 'Nomadmin', 'enabled' => '1', 'position' => 25, 'notnull' => 0, 'visible' => -1,),
118 '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',),
119 'titre' => array('type' => 'mediumtext', 'label' => 'Title', 'enabled' => '1', 'position' => 35, 'notnull' => 1, 'visible' => -1,),
120 'date_fin' => array('type' => 'datetime', 'label' => 'DateEnd', 'enabled' => '1', 'position' => 40, 'notnull' => 1, 'visible' => -1,),
121 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => '1', 'position' => 500, 'notnull' => 0, 'visible' => -1,),
122 'format' => array('type' => 'varchar(2)', 'label' => 'Format', 'enabled' => '1', 'position' => 50, 'notnull' => 1, 'visible' => -1,),
123 'mailsonde' => array('type' => 'integer', 'label' => 'Mailsonde', 'enabled' => '1', 'position' => 55, 'notnull' => 1, 'visible' => -1,),
124 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => '1', 'position' => 60, 'notnull' => 1, 'visible' => -1,),
125 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => '1', 'position' => 65, 'notnull' => 1, 'visible' => -2, 'default' => '1', 'index' => 1,),
126 'allow_comments' => array('type' => 'integer', 'label' => 'Allowcomments', 'enabled' => '1', 'position' => 70, 'notnull' => 1, 'visible' => -1,),
127 'allow_spy' => array('type' => 'integer', 'label' => 'Allowspy', 'enabled' => '1', 'position' => 75, 'notnull' => 1, 'visible' => -1,),
128 'sujet' => array('type' => 'mediumtext', 'label' => 'Sujet', 'enabled' => '1', 'position' => 80, 'notnull' => 0, 'visible' => -1,),
129 //'id_sondage_admin' => array('type' => 'char(24)', 'label' => 'Idsondageadmin', 'enabled' => '1', 'position' => 85, 'notnull' => 0, 'visible' => -1,),
130 );
131
135 public $id_sondage;
136
141 public $commentaires;
142
146 public $mail_admin;
147
151 public $nom_admin;
152
156 public $fk_user_creat;
157
162 public $titre;
163
167 public $title;
168
172 public $date_fin = '';
176 public $status;
177
181 public $format;
182
186 public $mailsonde;
187
191 public $allow_comments;
192
196 public $allow_spy;
197
201 public $sujet;
202
206 public $id_sondage_admin;
207 // END MODULEBUILDER PROPERTIES
208
212 const STATUS_DRAFT = 0;
220 const STATUS_CLOSED = 2;
221
222
228 public function __construct($db)
229 {
230 $this->db = $db;
231 }
232
233
241 public function create(User $user, $notrigger = 0)
242 {
243 global $conf;
244
245 $error = 0;
246
247 // Clean parameters
248 $this->cleanParameters();
249
250 // Check parameters
251 if (!$this->date_fin > 0) {
252 $this->error = 'BadValueForEndDate';
253 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
254 return -1;
255 }
256
257 // Insert request
258 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_sondage(";
259 $sql .= "id_sondage,";
260 $sql .= "commentaires,";
261 $sql .= "fk_user_creat,";
262 $sql .= "titre,";
263 $sql .= "date_fin,";
264 $sql .= "status,";
265 $sql .= "format,";
266 $sql .= "mailsonde,";
267 $sql .= "allow_comments,";
268 $sql .= "allow_spy,";
269 $sql .= "sujet,";
270 $sql .= "entity";
271 $sql .= ") VALUES (";
272 $sql .= "'".$this->db->escape($this->id_sondage)."',";
273 $sql .= " ".(empty($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").",";
274 $sql .= " ".(int) $user->id.",";
275 $sql .= " '".$this->db->escape($this->title)."',";
276 $sql .= " '".$this->db->idate($this->date_fin)."',";
277 $sql .= " ".(int) $this->status.",";
278 $sql .= " '".$this->db->escape($this->format)."',";
279 $sql .= " ".((int) $this->mailsonde).",";
280 $sql .= " ".((int) $this->allow_comments).",";
281 $sql .= " ".((int) $this->allow_spy).",";
282 $sql .= " '".$this->db->escape($this->sujet)."',";
283 $sql .= " ".((int) $conf->entity);
284 $sql .= ")";
285
286 $this->db->begin();
287
288 dol_syslog(get_class($this)."::create", LOG_DEBUG);
289 $resql = $this->db->query($sql);
290 if (!$resql) {
291 $error++;
292 $this->errors[] = "Error ".$this->db->lasterror();
293 }
294
295 if (!$error && !$notrigger) {
296 // Call trigger
297 $result = $this->call_trigger('OPENSURVEY_CREATE', $user);
298 if ($result < 0) {
299 $error++;
300 }
301 // End call triggers
302 }
303
304 // Commit or rollback
305 if ($error) {
306 foreach ($this->errors as $errmsg) {
307 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
308 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
309 }
310 $this->db->rollback();
311 return -1 * $error;
312 } else {
313 $this->db->commit();
314 return $this->id;
315 }
316 }
317
318
326 public function fetch($id, $numsurvey = '')
327 {
328 $sql = "SELECT";
329 $sql .= " t.id_sondage,";
330 $sql .= " t.titre as title,";
331 $sql .= " t.commentaires as description,";
332 $sql .= " t.mail_admin,";
333 $sql .= " t.nom_admin,";
334 $sql .= " t.fk_user_creat,";
335 $sql .= " t.date_fin,";
336 $sql .= " t.status,";
337 $sql .= " t.format,";
338 $sql .= " t.mailsonde,";
339 $sql .= " t.allow_comments,";
340 $sql .= " t.allow_spy,";
341 $sql .= " t.sujet,";
342 $sql .= " t.tms";
343 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as t";
344 $sql .= " WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey)."'";
345
346 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
347 $resql = $this->db->query($sql);
348 if ($resql) {
349 if ($this->db->num_rows($resql)) {
350 $obj = $this->db->fetch_object($resql);
351
352 $this->id_sondage = $obj->id_sondage;
353 $this->ref = $this->id_sondage; //For compatibility
354
355 $this->description = $obj->description;
356 $this->mail_admin = $obj->mail_admin;
357 $this->nom_admin = $obj->nom_admin;
358 $this->title = $obj->title;
359 $this->date_fin = $this->db->jdate($obj->date_fin);
360 $this->status = $obj->status;
361 $this->format = $obj->format;
362 $this->mailsonde = $obj->mailsonde;
363 $this->allow_comments = $obj->allow_comments;
364 $this->allow_spy = $obj->allow_spy;
365 $this->sujet = $obj->sujet;
366 $this->fk_user_creat = $obj->fk_user_creat;
367
368 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms : "");
369 $ret = 1;
370 } else {
371 $sondage = ($id ? 'id='.$id : 'sondageid='.$numsurvey);
372 $this->error = 'Fetch no poll found for '.$sondage;
373 dol_syslog($this->error, LOG_ERR);
374 $ret = 0;
375 }
376
377 $this->db->free($resql);
378 } else {
379 $this->error = "Error ".$this->db->lasterror();
380 $ret = -1;
381 }
382
383 return $ret;
384 }
385
386
394 public function update(User $user, $notrigger = 0)
395 {
396 $error = 0;
397
398 // Clean parameters
399 $this->cleanParameters();
400
401 // Check parameters
402 // Put here code to add a control on parameters values
403
404 // Update request
405 $sql = "UPDATE ".MAIN_DB_PREFIX."opensurvey_sondage SET";
406 $sql .= " id_sondage=".(isset($this->id_sondage) ? "'".$this->db->escape($this->id_sondage)."'" : "null").",";
407 $sql .= " commentaires=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").",";
408 $sql .= " mail_admin=".(isset($this->mail_admin) ? "'".$this->db->escape($this->mail_admin)."'" : "null").",";
409 $sql .= " nom_admin=".(isset($this->nom_admin) ? "'".$this->db->escape($this->nom_admin)."'" : "null").",";
410 $sql .= " titre=".(isset($this->title) ? "'".$this->db->escape($this->title)."'" : "null").",";
411 $sql .= " date_fin=".(dol_strlen($this->date_fin) != 0 ? "'".$this->db->idate($this->date_fin)."'" : 'null').",";
412 $sql .= " status=".(!empty($this->status) ? (int) $this->status : "null").",";
413 $sql .= " format=".(isset($this->format) ? "'".$this->db->escape($this->format)."'" : "null").",";
414 $sql .= " mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) : "null").",";
415 $sql .= " allow_comments=".((int) $this->allow_comments).",";
416 $sql .= " allow_spy=".((int) $this->allow_spy);
417 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
418
419 $this->db->begin();
420
421 dol_syslog(get_class($this)."::update", LOG_DEBUG);
422 $resql = $this->db->query($sql);
423 if (!$resql) {
424 $error++;
425 $this->errors[] = "Error ".$this->db->lasterror();
426 }
427
428 if (!$error && !$notrigger) {
429 // Call trigger
430 $result = $this->call_trigger('OPENSURVEY_MODIFY', $user);
431 if ($result < 0) {
432 $error++;
433 }
434 // End call triggers
435 }
436
437 // Commit or rollback
438 if ($error) {
439 foreach ($this->errors as $errmsg) {
440 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
441 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
442 }
443 $this->db->rollback();
444 return -1 * $error;
445 } else {
446 $this->db->commit();
447 return 1;
448 }
449 }
450
459 public function delete(User $user, $notrigger = 0, $numsondage = '')
460 {
461 global $conf, $langs;
462 $error = 0;
463
464 if (empty($numsondage)) {
465 $numsondage = $this->id_sondage;
466 }
467
468 $this->db->begin();
469
470 if (!$error && !$notrigger) {
471 // Call trigger
472 $result = $this->call_trigger('OPENSURVEY_DELETE', $user);
473 if ($result < 0) {
474 $error++;
475 }
476 // End call triggers
477 }
478
479 if (!$error) {
480 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage)."'";
481 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
482 $resql = $this->db->query($sql);
483 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage)."'";
484 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
485 $resql = $this->db->query($sql);
486
487 $sql = "DELETE FROM ".MAIN_DB_PREFIX."opensurvey_sondage";
488 $sql .= " WHERE id_sondage = '".$this->db->escape($numsondage)."'";
489
490 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
491 $resql = $this->db->query($sql);
492 if (!$resql) {
493 $error++;
494 $this->errors[] = "Error ".$this->db->lasterror();
495 }
496 }
497
498 // Commit or rollback
499 if ($error) {
500 foreach ($this->errors as $errmsg) {
501 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
502 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
503 }
504 $this->db->rollback();
505 return -1 * $error;
506 } else {
507 $this->db->commit();
508 return 1;
509 }
510 }
511
518 public function getTooltipContentArray($params)
519 {
520 global $conf, $langs;
521
522 $langs->load('opensurvey');
523
524 $datas = [];
525 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("ShowSurvey").'</u>';
526 if (isset($this->status)) {
527 $datas['picto'] .= ' '.$this->getLibStatut(5);
528 }
529 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
530 if (!empty($this->date_fin)) {
531 $datas['expire_date'] = '<br><b>'.$langs->trans('ExpireDate').':</b> '.dol_print_date($this->date_fin, 'day');
532 if ($this->date_fin && $this->date_fin < dol_now() && $this->status == Opensurveysondage::STATUS_VALIDATED) {
533 $datas['expire_date'] .= img_warning($langs->trans("Expired"));
534 }
535 }
536 $datas['title'] = '<br><b>'.$langs->trans('Title').':</b> '.$this->title;
537 if (!empty($this->description)) {
538 $datas['description'] = '<br><b>'.$langs->trans('Description').':</b> '.$this->description;
539 }
540
541 return $datas;
542 }
543
553 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
554 {
555 global $conf, $hookmanager, $langs;
556
557 if (!empty($conf->dol_no_mouse_hover)) {
558 $notooltip = 1; // Force disable tooltips
559 }
560
561 $result = '';
562 $params = [
563 'id' => $this->id,
564 'objecttype' => $this->element,
565 ];
566 $classfortooltip = 'classfortooltip';
567 $dataparams = '';
568 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
569 $classfortooltip = 'classforajaxtooltip';
570 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
571 $label = '';
572 } else {
573 $label = implode($this->getTooltipContentArray($params));
574 }
575
576 $url = DOL_URL_ROOT.'/opensurvey/card.php?id='.$this->id;
577
578 // Add param to save lastsearch_values or not
579 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
580 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
581 $add_save_lastsearch_values = 1;
582 }
583 if ($add_save_lastsearch_values) {
584 $url .= '&save_lastsearch_values=1';
585 }
586
587 $linkclose = '';
588 if (empty($notooltip)) {
589 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
590 $label = $langs->trans("ShowMyObject");
591 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
592 }
593 $linkclose .= ($label ? ' title="'.dolPrintHTMLForAttribute($label).'"' : ' title="tocomplete"');
594 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
595 } else {
596 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
597 }
598
599 $linkstart = '<a href="'.$url.'"';
600 $linkstart .= $linkclose.'>';
601 $linkend = '</a>';
602
603 $result .= $linkstart;
604 if ($withpicto) {
605 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
606 }
607 if ($withpicto != 2) {
608 $result .= $this->ref;
609 }
610 $result .= $linkend;
611
612 global $action;
613 $hookmanager->initHooks(array($this->element . 'dao'));
614 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
615 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
616 if ($reshook > 0) {
617 $result = $hookmanager->resPrint;
618 } else {
619 $result .= $hookmanager->resPrint;
620 }
621
622 return $result;
623 }
624
625 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
631 public function fetch_lines()
632 {
633 // phpcs:enable
634 $this->lines = array();
635
636 $sql = "SELECT id_users, nom as name, reponses";
637 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
638 $sql .= " WHERE id_sondage = '".$this->db->escape($this->id_sondage)."'";
639
640 $resql = $this->db->query($sql);
641
642 if ($resql) {
643 $num = $this->db->num_rows($resql);
644 $i = 0;
645 while ($i < $num) {
646 $obj = $this->db->fetch_object($resql);
647 $tmp = array('id_users' => $obj->id_users, 'nom' => $obj->name, 'reponses' => $obj->reponses);
648
649 $this->lines[] = $tmp;
650 $i++;
651 }
652 } else {
653 dol_print_error($this->db);
654 }
655
656 return count($this->lines);
657 }
658
665 public function initAsSpecimen()
666 {
667 $this->id = 0;
668
669 $this->id_sondage = 'a12d5g';
670 $this->description = 'Description of the specimen survey';
671 $this->mail_admin = 'email@email.com';
672 $this->nom_admin = 'surveyadmin';
673 $this->title = 'This is a specimen survey';
674 $this->date_fin = dol_now() + 3600 * 24 * 10;
675 $this->status = 1;
676 $this->format = 'classic';
677 $this->mailsonde = 0;
678
679 return 1;
680 }
681
687 public function getComments()
688 {
689 $comments = array();
690
691 $sql = 'SELECT id_comment, usercomment, comment';
692 $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
693 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
694 $sql .= " ORDER BY id_comment";
695 $resql = $this->db->query($sql);
696
697 if ($resql) {
698 $num_rows = $this->db->num_rows($resql);
699
700 if ($num_rows > 0) {
701 while ($obj = $this->db->fetch_object($resql)) {
702 $comments[] = $obj;
703 }
704 }
705 }
706
707 return $comments;
708 }
709
718 public function addComment($comment, $comment_user, $user_ip = '')
719 {
720 $now = dol_now();
721 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
722 $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)."'" : '').")";
723 $resql = $this->db->query($sql);
724
725 if (!$resql) {
726 return false;
727 }
728
729 return true;
730 }
731
738 public function deleteComment($id_comment)
739 {
740 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.((int) $id_comment).' AND id_sondage = "'.$this->db->escape($this->id_sondage).'"';
741 $resql = $this->db->query($sql);
742
743 if (!$resql) {
744 return false;
745 }
746
747 return true;
748 }
749
755 private function cleanParameters()
756 {
757 $this->id_sondage = trim($this->id_sondage);
758 $this->description = trim($this->description);
759 $this->mail_admin = trim($this->mail_admin);
760 $this->nom_admin = trim($this->nom_admin);
761 $this->title = trim($this->title);
762 $this->status = (int) $this->status;
763 $this->format = trim($this->format);
764 $this->mailsonde = ($this->mailsonde ? 1 : 0);
765 $this->allow_comments = ($this->allow_comments ? 1 : 0);
766 $this->allow_spy = ($this->allow_spy ? 1 : 0);
767 $this->sujet = trim($this->sujet);
768 }
769
770
777 public function getLibStatut($mode)
778 {
779 return $this->LibStatut($this->status, $mode);
780 }
781
782 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
790 public function LibStatut($status, $mode)
791 {
792 // phpcs:enable
793 global $langs, $conf;
794
795 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
796 global $langs;
797 //$langs->load("mymodule");
798 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
799 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
800 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
801 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
802 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
803 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
804 }
805
806 $statusType = 'status'.$status;
807 if ($status == self::STATUS_VALIDATED) {
808 if (0) {
809 $statusType = 'status1';
810 } else {
811 $statusType = 'status4';
812 }
813 }
814 if ($status == self::STATUS_CLOSED) {
815 $statusType = 'status6';
816 }
817
818 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
819 }
820
821
827 public function countVotes()
828 {
829 $result = 0;
830
831 $sql = " SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
832 $sql .= " WHERE id_sondage = '".$this->db->escape($this->ref)."'";
833
834 $resql = $this->db->query($sql);
835 if ($resql) {
836 $obj = $this->db->fetch_object($resql);
837 if ($obj) {
838 $result = $obj->nb;
839 }
840 } else {
841 $this->error = $this->db->lasterror();
842 $this->errors[] = $this->error;
843 }
844
845 return $result;
846 }
847
860 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
861 {
862 dol_syslog(__METHOD__, LOG_DEBUG);
863
864 $records = array();
865
866 $sql = 'SELECT ';
867 $sql .= $this->getFieldList();
868 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
869 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
870 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
871 } else {
872 $sql .= ' WHERE 1 = 1';
873 }
874
875 // Manage filter
876 $errormessage = '';
877 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
878 if ($errormessage) {
879 $this->errors[] = $errormessage;
880 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
881 return -1;
882 }
883
884 if (!empty($sortfield)) {
885 $sql .= $this->db->order($sortfield, $sortorder);
886 }
887 if (!empty($limit)) {
888 $sql .= $this->db->plimit($limit, $offset);
889 }
890
891 $resql = $this->db->query($sql);
892 if ($resql) {
893 $num = $this->db->num_rows($resql);
894 $i = 0;
895 while ($i < ($limit ? min($limit, $num) : $num)) {
896 $obj = $this->db->fetch_object($resql);
897
898 $record = new self($this->db);
899 $record->setVarsFromFetchObj($obj);
900
901 $records[$record->id_sondage] = $record;
902
903 $i++;
904 }
905 $this->db->free($resql);
906
907 return $records;
908 } else {
909 $this->errors[] = 'Error '.$this->db->lasterror();
910 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
911
912 return -1;
913 }
914 }
915}
$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.
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.
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:171
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.
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)
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79