dolibarr 21.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-2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 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
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' => 'Comments', '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 'titre' => array('type' => 'mediumtext', 'label' => 'Title', 'enabled' => '1', 'position' => 35, 'notnull' => 1, 'visible' => -1,),
113 'date_fin' => array('type' => 'datetime', 'label' => 'DateEnd', '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
128 public $id_sondage;
129
134 public $commentaires;
135
139 public $mail_admin;
140
144 public $nom_admin;
145
149 public $fk_user_creat;
150
154 public $title;
155
159 public $date_fin = '';
160 public $status;
161
165 public $format;
166
170 public $mailsonde;
171
175 public $allow_comments;
176
180 public $allow_spy;
181
185 public $sujet;
186
190 public $id_sondage_admin;
191 // END MODULEBUILDER PROPERTIES
192
196 const STATUS_DRAFT = 0;
204 const STATUS_CLOSED = 2;
205
206
212 public function __construct($db)
213 {
214 $this->db = $db;
215 }
216
217
225 public function create(User $user, $notrigger = 0)
226 {
227 global $conf;
228
229 $error = 0;
230
231 // Clean parameters
232 $this->cleanParameters();
233
234 // Check parameters
235 if (!$this->date_fin > 0) {
236 $this->error = 'BadValueForEndDate';
237 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
238 return -1;
239 }
240
241 // Insert request
242 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_sondage(";
243 $sql .= "id_sondage,";
244 $sql .= "commentaires,";
245 $sql .= "fk_user_creat,";
246 $sql .= "titre,";
247 $sql .= "date_fin,";
248 $sql .= "status,";
249 $sql .= "format,";
250 $sql .= "mailsonde,";
251 $sql .= "allow_comments,";
252 $sql .= "allow_spy,";
253 $sql .= "sujet,";
254 $sql .= "entity";
255 $sql .= ") VALUES (";
256 $sql .= "'".$this->db->escape($this->id_sondage)."',";
257 $sql .= " ".(empty($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").",";
258 $sql .= " ".(int) $user->id.",";
259 $sql .= " '".$this->db->escape($this->title)."',";
260 $sql .= " '".$this->db->idate($this->date_fin)."',";
261 $sql .= " ".(int) $this->status.",";
262 $sql .= " '".$this->db->escape($this->format)."',";
263 $sql .= " ".((int) $this->mailsonde).",";
264 $sql .= " ".((int) $this->allow_comments).",";
265 $sql .= " ".((int) $this->allow_spy).",";
266 $sql .= " '".$this->db->escape($this->sujet)."',";
267 $sql .= " ".((int) $conf->entity);
268 $sql .= ")";
269
270 $this->db->begin();
271
272 dol_syslog(get_class($this)."::create", LOG_DEBUG);
273 $resql = $this->db->query($sql);
274 if (!$resql) {
275 $error++;
276 $this->errors[] = "Error ".$this->db->lasterror();
277 }
278
279 if (!$error && !$notrigger) {
280 // Call trigger
281 $result = $this->call_trigger('OPENSURVEY_CREATE', $user);
282 if ($result < 0) {
283 $error++;
284 }
285 // End call triggers
286 }
287
288 // Commit or rollback
289 if ($error) {
290 foreach ($this->errors as $errmsg) {
291 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
292 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
293 }
294 $this->db->rollback();
295 return -1 * $error;
296 } else {
297 $this->db->commit();
298 return $this->id;
299 }
300 }
301
302
310 public function fetch($id, $numsurvey = '')
311 {
312 $sql = "SELECT";
313 $sql .= " t.id_sondage,";
314 $sql .= " t.titre as title,";
315 $sql .= " t.commentaires as description,";
316 $sql .= " t.mail_admin,";
317 $sql .= " t.nom_admin,";
318 $sql .= " t.fk_user_creat,";
319 $sql .= " t.date_fin,";
320 $sql .= " t.status,";
321 $sql .= " t.format,";
322 $sql .= " t.mailsonde,";
323 $sql .= " t.allow_comments,";
324 $sql .= " t.allow_spy,";
325 $sql .= " t.sujet,";
326 $sql .= " t.tms";
327 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as t";
328 $sql .= " WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey)."'";
329
330 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
331 $resql = $this->db->query($sql);
332 if ($resql) {
333 if ($this->db->num_rows($resql)) {
334 $obj = $this->db->fetch_object($resql);
335
336 $this->id_sondage = $obj->id_sondage;
337 $this->ref = $this->id_sondage; //For compatibility
338
339 $this->description = $obj->description;
340 $this->mail_admin = $obj->mail_admin;
341 $this->nom_admin = $obj->nom_admin;
342 $this->title = $obj->title;
343 $this->date_fin = $this->db->jdate($obj->date_fin);
344 $this->status = $obj->status;
345 $this->format = $obj->format;
346 $this->mailsonde = $obj->mailsonde;
347 $this->allow_comments = $obj->allow_comments;
348 $this->allow_spy = $obj->allow_spy;
349 $this->sujet = $obj->sujet;
350 $this->fk_user_creat = $obj->fk_user_creat;
351
352 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms : "");
353 $ret = 1;
354 } else {
355 $sondage = ($id ? 'id='.$id : 'sondageid='.$numsurvey);
356 $this->error = 'Fetch no poll found for '.$sondage;
357 dol_syslog($this->error, LOG_ERR);
358 $ret = 0;
359 }
360
361 $this->db->free($resql);
362 } else {
363 $this->error = "Error ".$this->db->lasterror();
364 $ret = -1;
365 }
366
367 return $ret;
368 }
369
370
378 public function update(User $user, $notrigger = 0)
379 {
380 $error = 0;
381
382 // Clean parameters
383 $this->cleanParameters();
384
385 // Check parameters
386 // Put here code to add a control on parameters values
387
388 // Update request
389 $sql = "UPDATE ".MAIN_DB_PREFIX."opensurvey_sondage SET";
390 $sql .= " id_sondage=".(isset($this->id_sondage) ? "'".$this->db->escape($this->id_sondage)."'" : "null").",";
391 $sql .= " commentaires=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").",";
392 $sql .= " mail_admin=".(isset($this->mail_admin) ? "'".$this->db->escape($this->mail_admin)."'" : "null").",";
393 $sql .= " nom_admin=".(isset($this->nom_admin) ? "'".$this->db->escape($this->nom_admin)."'" : "null").",";
394 $sql .= " titre=".(isset($this->title) ? "'".$this->db->escape($this->title)."'" : "null").",";
395 $sql .= " date_fin=".(dol_strlen($this->date_fin) != 0 ? "'".$this->db->idate($this->date_fin)."'" : 'null').",";
396 $sql .= " status=".(isset($this->status) ? "'".$this->db->escape($this->status)."'" : "null").",";
397 $sql .= " format=".(isset($this->format) ? "'".$this->db->escape($this->format)."'" : "null").",";
398 $sql .= " mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) : "null").",";
399 $sql .= " allow_comments=".((int) $this->allow_comments).",";
400 $sql .= " allow_spy=".((int) $this->allow_spy);
401 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
402
403 $this->db->begin();
404
405 dol_syslog(get_class($this)."::update", LOG_DEBUG);
406 $resql = $this->db->query($sql);
407 if (!$resql) {
408 $error++;
409 $this->errors[] = "Error ".$this->db->lasterror();
410 }
411
412 if (!$error && !$notrigger) {
413 // Call trigger
414 $result = $this->call_trigger('OPENSURVEY_MODIFY', $user);
415 if ($result < 0) {
416 $error++;
417 }
418 // End call triggers
419 }
420
421 // Commit or rollback
422 if ($error) {
423 foreach ($this->errors as $errmsg) {
424 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
425 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
426 }
427 $this->db->rollback();
428 return -1 * $error;
429 } else {
430 $this->db->commit();
431 return 1;
432 }
433 }
434
443 public function delete(User $user, $notrigger = 0, $numsondage = '')
444 {
445 global $conf, $langs;
446 $error = 0;
447
448 if (empty($numsondage)) {
449 $numsondage = $this->id_sondage;
450 }
451
452 $this->db->begin();
453
454 if (!$error && !$notrigger) {
455 // Call trigger
456 $result = $this->call_trigger('OPENSURVEY_DELETE', $user);
457 if ($result < 0) {
458 $error++;
459 }
460 // End call triggers
461 }
462
463 if (!$error) {
464 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage)."'";
465 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
466 $resql = $this->db->query($sql);
467 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage)."'";
468 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
469 $resql = $this->db->query($sql);
470
471 $sql = "DELETE FROM ".MAIN_DB_PREFIX."opensurvey_sondage";
472 $sql .= " WHERE id_sondage = '".$this->db->escape($numsondage)."'";
473
474 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
475 $resql = $this->db->query($sql);
476 if (!$resql) {
477 $error++;
478 $this->errors[] = "Error ".$this->db->lasterror();
479 }
480 }
481
482 // Commit or rollback
483 if ($error) {
484 foreach ($this->errors as $errmsg) {
485 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
486 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
487 }
488 $this->db->rollback();
489 return -1 * $error;
490 } else {
491 $this->db->commit();
492 return 1;
493 }
494 }
495
502 public function getTooltipContentArray($params)
503 {
504 global $conf, $langs;
505
506 $langs->load('opensurvey');
507
508 $datas = [];
509 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("ShowSurvey").'</u>';
510 if (isset($this->status)) {
511 $datas['picto'] .= ' '.$this->getLibStatut(5);
512 }
513 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
514 if (!empty($this->date_fin)) {
515 $datas['expire_date'] = '<br><b>'.$langs->trans('ExpireDate').':</b> '.dol_print_date($this->date_fin, 'day');
516 if ($this->date_fin && $this->date_fin < dol_now() && $this->status == Opensurveysondage::STATUS_VALIDATED) {
517 $datas['expire_date'] .= img_warning($langs->trans("Expired"));
518 }
519 }
520 $datas['title'] = '<br><b>'.$langs->trans('Title').':</b> '.$this->title;
521 if (!empty($this->description)) {
522 $datas['description'] = '<br><b>'.$langs->trans('Description').':</b> '.$this->description;
523 }
524
525 return $datas;
526 }
527
537 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
538 {
539 global $conf, $hookmanager, $langs;
540
541 if (!empty($conf->dol_no_mouse_hover)) {
542 $notooltip = 1; // Force disable tooltips
543 }
544
545 $result = '';
546 $params = [
547 'id' => $this->id,
548 'objecttype' => $this->element,
549 ];
550 $classfortooltip = 'classfortooltip';
551 $dataparams = '';
552 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
553 $classfortooltip = 'classforajaxtooltip';
554 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
555 $label = '';
556 } else {
557 $label = implode($this->getTooltipContentArray($params));
558 }
559
560 $url = DOL_URL_ROOT.'/opensurvey/card.php?id='.$this->id;
561
562 // Add param to save lastsearch_values or not
563 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
564 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
565 $add_save_lastsearch_values = 1;
566 }
567 if ($add_save_lastsearch_values) {
568 $url .= '&save_lastsearch_values=1';
569 }
570
571 $linkclose = '';
572 if (empty($notooltip)) {
573 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
574 $label = $langs->trans("ShowMyObject");
575 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
576 }
577 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
578 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
579 } else {
580 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
581 }
582
583 $linkstart = '<a href="'.$url.'"';
584 $linkstart .= $linkclose.'>';
585 $linkend = '</a>';
586
587 $result .= $linkstart;
588 if ($withpicto) {
589 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
590 }
591 if ($withpicto != 2) {
592 $result .= $this->ref;
593 }
594 $result .= $linkend;
595
596 global $action;
597 $hookmanager->initHooks(array($this->element . 'dao'));
598 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
599 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
600 if ($reshook > 0) {
601 $result = $hookmanager->resPrint;
602 } else {
603 $result .= $hookmanager->resPrint;
604 }
605
606 return $result;
607 }
608
609 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
615 public function fetch_lines()
616 {
617 // phpcs:enable
618 $this->lines = array();
619
620 $sql = "SELECT id_users, nom as name, reponses";
621 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
622 $sql .= " WHERE id_sondage = '".$this->db->escape($this->id_sondage)."'";
623
624 $resql = $this->db->query($sql);
625
626 if ($resql) {
627 $num = $this->db->num_rows($resql);
628 $i = 0;
629 while ($i < $num) {
630 $obj = $this->db->fetch_object($resql);
631 $tmp = array('id_users' => $obj->id_users, 'nom' => $obj->name, 'reponses' => $obj->reponses);
632
633 $this->lines[] = $tmp;
634 $i++;
635 }
636 } else {
637 dol_print_error($this->db);
638 }
639
640 return count($this->lines);
641 }
642
649 public function initAsSpecimen()
650 {
651 $this->id = 0;
652
653 $this->id_sondage = 'a12d5g';
654 $this->description = 'Description of the specimen survey';
655 $this->mail_admin = 'email@email.com';
656 $this->nom_admin = 'surveyadmin';
657 $this->title = 'This is a specimen survey';
658 $this->date_fin = dol_now() + 3600 * 24 * 10;
659 $this->status = 1;
660 $this->format = 'classic';
661 $this->mailsonde = 0;
662
663 return 1;
664 }
665
671 public function getComments()
672 {
673 $comments = array();
674
675 $sql = 'SELECT id_comment, usercomment, comment';
676 $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
677 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
678 $sql .= " ORDER BY id_comment";
679 $resql = $this->db->query($sql);
680
681 if ($resql) {
682 $num_rows = $this->db->num_rows($resql);
683
684 if ($num_rows > 0) {
685 while ($obj = $this->db->fetch_object($resql)) {
686 $comments[] = $obj;
687 }
688 }
689 }
690
691 return $comments;
692 }
693
702 public function addComment($comment, $comment_user, $user_ip = '')
703 {
704 $now = dol_now();
705 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
706 $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)."'" : '').")";
707 $resql = $this->db->query($sql);
708
709 if (!$resql) {
710 return false;
711 }
712
713 return true;
714 }
715
722 public function deleteComment($id_comment)
723 {
724 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.((int) $id_comment).' AND id_sondage = "'.$this->db->escape($this->id_sondage).'"';
725 $resql = $this->db->query($sql);
726
727 if (!$resql) {
728 return false;
729 }
730
731 return true;
732 }
733
739 private function cleanParameters()
740 {
741 $this->id_sondage = trim($this->id_sondage);
742 $this->description = trim($this->description);
743 $this->mail_admin = trim($this->mail_admin);
744 $this->nom_admin = trim($this->nom_admin);
745 $this->title = trim($this->title);
746 $this->status = (int) $this->status;
747 $this->format = trim($this->format);
748 $this->mailsonde = ($this->mailsonde ? 1 : 0);
749 $this->allow_comments = ($this->allow_comments ? 1 : 0);
750 $this->allow_spy = ($this->allow_spy ? 1 : 0);
751 $this->sujet = trim($this->sujet);
752 }
753
754
761 public function getLibStatut($mode)
762 {
763 return $this->LibStatut($this->status, $mode);
764 }
765
766 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
774 public function LibStatut($status, $mode)
775 {
776 // phpcs:enable
777 global $langs, $conf;
778
779 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
780 global $langs;
781 //$langs->load("mymodule");
782 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
783 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
784 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
785 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
786 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
787 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
788 }
789
790 $statusType = 'status'.$status;
791 if ($status == self::STATUS_VALIDATED) {
792 if (0) {
793 $statusType = 'status1';
794 } else {
795 $statusType = 'status4';
796 }
797 }
798 if ($status == self::STATUS_CLOSED) {
799 $statusType = 'status6';
800 }
801
802 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
803 }
804
805
811 public function countVotes()
812 {
813 $result = 0;
814
815 $sql = " SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
816 $sql .= " WHERE id_sondage = '".$this->db->escape($this->ref)."'";
817
818 $resql = $this->db->query($sql);
819 if ($resql) {
820 $obj = $this->db->fetch_object($resql);
821 if ($obj) {
822 $result = $obj->nb;
823 }
824 } else {
825 $this->error = $this->db->lasterror();
826 $this->errors[] = $this->error;
827 }
828
829 return $result;
830 }
831
844 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
845 {
846 dol_syslog(__METHOD__, LOG_DEBUG);
847
848 $records = array();
849
850 $sql = 'SELECT ';
851 $sql .= $this->getFieldList();
852 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
853 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
854 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
855 } else {
856 $sql .= ' WHERE 1 = 1';
857 }
858
859 // Manage filter
860 $errormessage = '';
861 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
862 if ($errormessage) {
863 $this->errors[] = $errormessage;
864 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
865 return -1;
866 }
867
868 if (!empty($sortfield)) {
869 $sql .= $this->db->order($sortfield, $sortorder);
870 }
871 if (!empty($limit)) {
872 $sql .= $this->db->plimit($limit, $offset);
873 }
874
875 $resql = $this->db->query($sql);
876 if ($resql) {
877 $num = $this->db->num_rows($resql);
878 $i = 0;
879 while ($i < ($limit ? min($limit, $num) : $num)) {
880 $obj = $this->db->fetch_object($resql);
881
882 $record = new self($this->db);
883 $record->setVarsFromFetchObj($obj);
884
885 $records[$record->id_sondage] = $record;
886
887 $i++;
888 }
889 $this->db->free($resql);
890
891 return $records;
892 } else {
893 $this->errors[] = 'Error '.$this->db->lasterror();
894 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
895
896 return -1;
897 }
898 }
899}
$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.
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:162
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_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (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).
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.