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