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;
133 public $commentaires;
134 public $mail_admin;
135 public $nom_admin;
136 public $fk_user_creat;
137 public $title;
138 public $date_fin = '';
139 public $status;
140 public $format;
141 public $mailsonde;
142 public $entity;
146 public $allow_comments;
147
151 public $allow_spy;
152
156 public $sujet;
157
161 public $id_sondage_admin;
162 // END MODULEBUILDER PROPERTIES
163
167 const STATUS_DRAFT = 0;
175 const STATUS_CLOSED = 2;
176
177
183 public function __construct($db)
184 {
185 $this->db = $db;
186 }
187
188
196 public function create(User $user, $notrigger = 0)
197 {
198 global $conf;
199
200 $error = 0;
201
202 // Clean parameters
203 $this->cleanParameters();
204
205 // Check parameters
206 if (!$this->date_fin > 0) {
207 $this->error = 'BadValueForEndDate';
208 dol_syslog(get_class($this)."::create ".$this->error, LOG_ERR);
209 return -1;
210 }
211
212 // Insert request
213 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_sondage(";
214 $sql .= "id_sondage,";
215 $sql .= "commentaires,";
216 $sql .= "fk_user_creat,";
217 $sql .= "titre,";
218 $sql .= "date_fin,";
219 $sql .= "status,";
220 $sql .= "format,";
221 $sql .= "mailsonde,";
222 $sql .= "allow_comments,";
223 $sql .= "allow_spy,";
224 $sql .= "sujet,";
225 $sql .= "entity";
226 $sql .= ") VALUES (";
227 $sql .= "'".$this->db->escape($this->id_sondage)."',";
228 $sql .= " ".(empty($this->description) ? 'NULL' : "'".$this->db->escape($this->description)."'").",";
229 $sql .= " ".(int) $user->id.",";
230 $sql .= " '".$this->db->escape($this->title)."',";
231 $sql .= " '".$this->db->idate($this->date_fin)."',";
232 $sql .= " ".(int) $this->status.",";
233 $sql .= " '".$this->db->escape($this->format)."',";
234 $sql .= " ".((int) $this->mailsonde).",";
235 $sql .= " ".((int) $this->allow_comments).",";
236 $sql .= " ".((int) $this->allow_spy).",";
237 $sql .= " '".$this->db->escape($this->sujet)."',";
238 $sql .= " ".((int) $conf->entity);
239 $sql .= ")";
240
241 $this->db->begin();
242
243 dol_syslog(get_class($this)."::create", LOG_DEBUG);
244 $resql = $this->db->query($sql);
245 if (!$resql) {
246 $error++;
247 $this->errors[] = "Error ".$this->db->lasterror();
248 }
249
250 if (!$error && !$notrigger) {
251 // Call trigger
252 $result = $this->call_trigger('OPENSURVEY_CREATE', $user);
253 if ($result < 0) {
254 $error++;
255 }
256 // End call triggers
257 }
258
259 // Commit or rollback
260 if ($error) {
261 foreach ($this->errors as $errmsg) {
262 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
263 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
264 }
265 $this->db->rollback();
266 return -1 * $error;
267 } else {
268 $this->db->commit();
269 return $this->id;
270 }
271 }
272
273
281 public function fetch($id, $numsurvey = '')
282 {
283 $sql = "SELECT";
284 $sql .= " t.id_sondage,";
285 $sql .= " t.titre as title,";
286 $sql .= " t.commentaires as description,";
287 $sql .= " t.mail_admin,";
288 $sql .= " t.nom_admin,";
289 $sql .= " t.fk_user_creat,";
290 $sql .= " t.date_fin,";
291 $sql .= " t.status,";
292 $sql .= " t.format,";
293 $sql .= " t.mailsonde,";
294 $sql .= " t.allow_comments,";
295 $sql .= " t.allow_spy,";
296 $sql .= " t.sujet,";
297 $sql .= " t.tms";
298 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as t";
299 $sql .= " WHERE t.id_sondage = '".$this->db->escape($id ? $id : $numsurvey)."'";
300
301 dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
302 $resql = $this->db->query($sql);
303 if ($resql) {
304 if ($this->db->num_rows($resql)) {
305 $obj = $this->db->fetch_object($resql);
306
307 $this->id_sondage = $obj->id_sondage;
308 $this->ref = $this->id_sondage; //For compatibility
309
310 $this->description = $obj->description;
311 $this->mail_admin = $obj->mail_admin;
312 $this->nom_admin = $obj->nom_admin;
313 $this->title = $obj->title;
314 $this->date_fin = $this->db->jdate($obj->date_fin);
315 $this->status = $obj->status;
316 $this->format = $obj->format;
317 $this->mailsonde = $obj->mailsonde;
318 $this->allow_comments = $obj->allow_comments;
319 $this->allow_spy = $obj->allow_spy;
320 $this->sujet = $obj->sujet;
321 $this->fk_user_creat = $obj->fk_user_creat;
322
323 $this->date_m = $this->db->jdate(!empty($obj->tms) ? $obj->tms : "");
324 $ret = 1;
325 } else {
326 $sondage = ($id ? 'id='.$id : 'sondageid='.$numsurvey);
327 $this->error = 'Fetch no poll found for '.$sondage;
328 dol_syslog($this->error, LOG_ERR);
329 $ret = 0;
330 }
331
332 $this->db->free($resql);
333 } else {
334 $this->error = "Error ".$this->db->lasterror();
335 $ret = -1;
336 }
337
338 return $ret;
339 }
340
341
349 public function update(User $user, $notrigger = 0)
350 {
351 $error = 0;
352
353 // Clean parameters
354 $this->cleanParameters();
355
356 // Check parameters
357 // Put here code to add a control on parameters values
358
359 // Update request
360 $sql = "UPDATE ".MAIN_DB_PREFIX."opensurvey_sondage SET";
361 $sql .= " id_sondage=".(isset($this->id_sondage) ? "'".$this->db->escape($this->id_sondage)."'" : "null").",";
362 $sql .= " commentaires=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").",";
363 $sql .= " mail_admin=".(isset($this->mail_admin) ? "'".$this->db->escape($this->mail_admin)."'" : "null").",";
364 $sql .= " nom_admin=".(isset($this->nom_admin) ? "'".$this->db->escape($this->nom_admin)."'" : "null").",";
365 $sql .= " titre=".(isset($this->title) ? "'".$this->db->escape($this->title)."'" : "null").",";
366 $sql .= " date_fin=".(dol_strlen($this->date_fin) != 0 ? "'".$this->db->idate($this->date_fin)."'" : 'null').",";
367 $sql .= " status=".(isset($this->status) ? "'".$this->db->escape($this->status)."'" : "null").",";
368 $sql .= " format=".(isset($this->format) ? "'".$this->db->escape($this->format)."'" : "null").",";
369 $sql .= " mailsonde=".(isset($this->mailsonde) ? ((int) $this->mailsonde) : "null").",";
370 $sql .= " allow_comments=".((int) $this->allow_comments).",";
371 $sql .= " allow_spy=".((int) $this->allow_spy);
372 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
373
374 $this->db->begin();
375
376 dol_syslog(get_class($this)."::update", LOG_DEBUG);
377 $resql = $this->db->query($sql);
378 if (!$resql) {
379 $error++;
380 $this->errors[] = "Error ".$this->db->lasterror();
381 }
382
383 if (!$error && !$notrigger) {
384 // Call trigger
385 $result = $this->call_trigger('OPENSURVEY_MODIFY', $user);
386 if ($result < 0) {
387 $error++;
388 }
389 // End call triggers
390 }
391
392 // Commit or rollback
393 if ($error) {
394 foreach ($this->errors as $errmsg) {
395 dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
396 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
397 }
398 $this->db->rollback();
399 return -1 * $error;
400 } else {
401 $this->db->commit();
402 return 1;
403 }
404 }
405
414 public function delete(User $user, $notrigger = 0, $numsondage = '')
415 {
416 global $conf, $langs;
417 $error = 0;
418
419 if (empty($numsondage)) {
420 $numsondage = $this->id_sondage;
421 }
422
423 $this->db->begin();
424
425 if (!$error && !$notrigger) {
426 // Call trigger
427 $result = $this->call_trigger('OPENSURVEY_DELETE', $user);
428 if ($result < 0) {
429 $error++;
430 }
431 // End call triggers
432 }
433
434 if (!$error) {
435 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_comments WHERE id_sondage = '".$this->db->escape($numsondage)."'";
436 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
437 $resql = $this->db->query($sql);
438 $sql = 'DELETE FROM '.MAIN_DB_PREFIX."opensurvey_user_studs WHERE id_sondage = '".$this->db->escape($numsondage)."'";
439 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
440 $resql = $this->db->query($sql);
441
442 $sql = "DELETE FROM ".MAIN_DB_PREFIX."opensurvey_sondage";
443 $sql .= " WHERE id_sondage = '".$this->db->escape($numsondage)."'";
444
445 dol_syslog(get_class($this)."::delete", LOG_DEBUG);
446 $resql = $this->db->query($sql);
447 if (!$resql) {
448 $error++;
449 $this->errors[] = "Error ".$this->db->lasterror();
450 }
451 }
452
453 // Commit or rollback
454 if ($error) {
455 foreach ($this->errors as $errmsg) {
456 dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
457 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
458 }
459 $this->db->rollback();
460 return -1 * $error;
461 } else {
462 $this->db->commit();
463 return 1;
464 }
465 }
466
474 public function getTooltipContentArray($params)
475 {
476 global $conf, $langs;
477
478 $langs->load('opensurvey');
479
480 $datas = [];
481 $datas['picto'] = img_picto('', $this->picto).' <u>'.$langs->trans("ShowSurvey").'</u>';
482 if (isset($this->status)) {
483 $datas['picto'] .= ' '.$this->getLibStatut(5);
484 }
485 $datas['ref'] = '<br><b>'.$langs->trans('Ref').':</b> '.$this->ref;
486 if (!empty($this->date_fin)) {
487 $datas['expire_date'] = '<br><b>'.$langs->trans('ExpireDate').':</b> '.dol_print_date($this->date_fin, 'day');
488 if ($this->date_fin && $this->date_fin < dol_now() && $this->status == Opensurveysondage::STATUS_VALIDATED) {
489 $datas['expire_date'] .= img_warning($langs->trans("Expired"));
490 }
491 }
492 $datas['title'] = '<br><b>'.$langs->trans('Title').':</b> '.$this->title;
493 if (!empty($this->description)) {
494 $datas['description'] = '<br><b>'.$langs->trans('Description').':</b> '.$this->description;
495 }
496
497 return $datas;
498 }
499
509 public function getNomUrl($withpicto = 0, $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
510 {
511 global $conf, $hookmanager, $langs;
512
513 if (!empty($conf->dol_no_mouse_hover)) {
514 $notooltip = 1; // Force disable tooltips
515 }
516
517 $result = '';
518 $params = [
519 'id' => $this->id,
520 'objecttype' => $this->element,
521 ];
522 $classfortooltip = 'classfortooltip';
523 $dataparams = '';
524 if (getDolGlobalInt('MAIN_ENABLE_AJAX_TOOLTIP')) {
525 $classfortooltip = 'classforajaxtooltip';
526 $dataparams = ' data-params="'.dol_escape_htmltag(json_encode($params)).'"';
527 $label = '';
528 } else {
529 $label = implode($this->getTooltipContentArray($params));
530 }
531
532 $url = DOL_URL_ROOT.'/opensurvey/card.php?id='.$this->id;
533
534 // Add param to save lastsearch_values or not
535 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
536 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
537 $add_save_lastsearch_values = 1;
538 }
539 if ($add_save_lastsearch_values) {
540 $url .= '&save_lastsearch_values=1';
541 }
542
543 $linkclose = '';
544 if (empty($notooltip)) {
545 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
546 $label = $langs->trans("ShowMyObject");
547 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
548 }
549 $linkclose .= ($label ? ' title="'.dol_escape_htmltag($label, 1).'"' : ' title="tocomplete"');
550 $linkclose .= $dataparams.' class="'.$classfortooltip.($morecss ? ' '.$morecss : '').'"';
551 } else {
552 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
553 }
554
555 $linkstart = '<a href="'.$url.'"';
556 $linkstart .= $linkclose.'>';
557 $linkend = '</a>';
558
559 $result .= $linkstart;
560 if ($withpicto) {
561 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), (($withpicto != 2) ? 'class="paddingright"' : ''), 0, 0, $notooltip ? 0 : 1);
562 }
563 if ($withpicto != 2) {
564 $result .= $this->ref;
565 }
566 $result .= $linkend;
567
568 global $action;
569 $hookmanager->initHooks(array($this->element . 'dao'));
570 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
571 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
572 if ($reshook > 0) {
573 $result = $hookmanager->resPrint;
574 } else {
575 $result .= $hookmanager->resPrint;
576 }
577
578 return $result;
579 }
580
581 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
587 public function fetch_lines()
588 {
589 // phpcs:enable
590 $this->lines = array();
591
592 $sql = "SELECT id_users, nom as name, reponses";
593 $sql .= " FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
594 $sql .= " WHERE id_sondage = '".$this->db->escape($this->id_sondage)."'";
595
596 $resql = $this->db->query($sql);
597
598 if ($resql) {
599 $num = $this->db->num_rows($resql);
600 $i = 0;
601 while ($i < $num) {
602 $obj = $this->db->fetch_object($resql);
603 $tmp = array('id_users' => $obj->id_users, 'nom' => $obj->name, 'reponses' => $obj->reponses);
604
605 $this->lines[] = $tmp;
606 $i++;
607 }
608 } else {
609 dol_print_error($this->db);
610 }
611
612 return count($this->lines);
613 }
614
621 public function initAsSpecimen()
622 {
623 $this->id = 0;
624
625 $this->id_sondage = 'a12d5g';
626 $this->description = 'Description of the specimen survey';
627 $this->mail_admin = 'email@email.com';
628 $this->nom_admin = 'surveyadmin';
629 $this->title = 'This is a specimen survey';
630 $this->date_fin = dol_now() + 3600 * 24 * 10;
631 $this->status = 1;
632 $this->format = 'classic';
633 $this->mailsonde = 0;
634
635 return 1;
636 }
637
643 public function getComments()
644 {
645 $comments = array();
646
647 $sql = 'SELECT id_comment, usercomment, comment';
648 $sql .= ' FROM '.MAIN_DB_PREFIX.'opensurvey_comments';
649 $sql .= " WHERE id_sondage='".$this->db->escape($this->id_sondage)."'";
650 $sql .= " ORDER BY id_comment";
651 $resql = $this->db->query($sql);
652
653 if ($resql) {
654 $num_rows = $this->db->num_rows($resql);
655
656 if ($num_rows > 0) {
657 while ($obj = $this->db->fetch_object($resql)) {
658 $comments[] = $obj;
659 }
660 }
661 }
662
663 return $comments;
664 }
665
674 public function addComment($comment, $comment_user, $user_ip = '')
675 {
676 $now = dol_now();
677 $sql = "INSERT INTO ".MAIN_DB_PREFIX."opensurvey_comments (id_sondage, comment, usercomment, date_creation, ip)";
678 $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)."'" : '').")";
679 $resql = $this->db->query($sql);
680
681 if (!$resql) {
682 return false;
683 }
684
685 return true;
686 }
687
694 public function deleteComment($id_comment)
695 {
696 $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'opensurvey_comments WHERE id_comment = '.((int) $id_comment).' AND id_sondage = "'.$this->db->escape($this->id_sondage).'"';
697 $resql = $this->db->query($sql);
698
699 if (!$resql) {
700 return false;
701 }
702
703 return true;
704 }
705
711 private function cleanParameters()
712 {
713 $this->id_sondage = trim($this->id_sondage);
714 $this->description = trim($this->description);
715 $this->mail_admin = trim($this->mail_admin);
716 $this->nom_admin = trim($this->nom_admin);
717 $this->title = trim($this->title);
718 $this->status = (int) $this->status;
719 $this->format = trim($this->format);
720 $this->mailsonde = ($this->mailsonde ? 1 : 0);
721 $this->allow_comments = ($this->allow_comments ? 1 : 0);
722 $this->allow_spy = ($this->allow_spy ? 1 : 0);
723 $this->sujet = trim($this->sujet);
724 }
725
726
733 public function getLibStatut($mode)
734 {
735 return $this->LibStatut($this->status, $mode);
736 }
737
738 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
746 public function LibStatut($status, $mode)
747 {
748 // phpcs:enable
749 global $langs, $conf;
750
751 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
752 global $langs;
753 //$langs->load("mymodule");
754 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
755 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
756 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
757 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv('Draft');
758 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv('Opened');
759 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv('Closed');
760 }
761
762 $statusType = 'status'.$status;
763 if ($status == self::STATUS_VALIDATED) {
764 if (0) {
765 $statusType = 'status1';
766 } else {
767 $statusType = 'status4';
768 }
769 }
770 if ($status == self::STATUS_CLOSED) {
771 $statusType = 'status6';
772 }
773
774 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
775 }
776
777
783 public function countVotes()
784 {
785 $result = 0;
786
787 $sql = " SELECT COUNT(id_users) as nb FROM ".MAIN_DB_PREFIX."opensurvey_user_studs";
788 $sql .= " WHERE id_sondage = '".$this->db->escape($this->ref)."'";
789
790 $resql = $this->db->query($sql);
791 if ($resql) {
792 $obj = $this->db->fetch_object($resql);
793 if ($obj) {
794 $result = $obj->nb;
795 }
796 } else {
797 $this->error = $this->db->lasterror();
798 $this->errors[] = $this->error;
799 }
800
801 return $result;
802 }
803
816 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
817 {
818 dol_syslog(__METHOD__, LOG_DEBUG);
819
820 $records = array();
821
822 $sql = 'SELECT ';
823 $sql .= $this->getFieldList();
824 $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
825 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
826 $sql .= ' WHERE t.entity IN ('.getEntity($this->element).')';
827 } else {
828 $sql .= ' WHERE 1 = 1';
829 }
830
831 // Manage filter
832 $errormessage = '';
833 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
834 if ($errormessage) {
835 $this->errors[] = $errormessage;
836 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
837 return -1;
838 }
839
840 if (!empty($sortfield)) {
841 $sql .= $this->db->order($sortfield, $sortorder);
842 }
843 if (!empty($limit)) {
844 $sql .= $this->db->plimit($limit, $offset);
845 }
846
847 $resql = $this->db->query($sql);
848 if ($resql) {
849 $num = $this->db->num_rows($resql);
850 $i = 0;
851 while ($i < ($limit ? min($limit, $num) : $num)) {
852 $obj = $this->db->fetch_object($resql);
853
854 $record = new self($this->db);
855 $record->setVarsFromFetchObj($obj);
856
857 $records[$record->id_sondage] = $record;
858
859 $i++;
860 }
861 $this->db->free($resql);
862
863 return $records;
864 } else {
865 $this->errors[] = 'Error '.$this->db->lasterror();
866 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
867
868 return -1;
869 }
870 }
871}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:626
$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 $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 dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.