commonnumrefgenerator.class.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /* Copyright (C) 2023 Laurent Destailleur <eldy@users.sourceforge.net>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. * or see https://www.gnu.org/
  17. */
  18. /**
  19. * \file htdocs/core/class/commonnumrefgenerator.class.php
  20. * \ingroup core
  21. * \brief File of parent class for num ref generators
  22. */
  23. /**
  24. * Parent class for number ref generators
  25. */
  26. abstract class CommonNumRefGenerator
  27. {
  28. /**
  29. * @var string Model name
  30. */
  31. public $name = '';
  32. /**
  33. * @var string Version
  34. */
  35. public $version = '';
  36. /**
  37. * @var string Error code (or message)
  38. */
  39. public $error = '';
  40. /**
  41. * @var string[] Array of error strings
  42. */
  43. public $errors = array();
  44. /**
  45. * @var DoliDB Database handler.
  46. */
  47. protected $db;
  48. /** Return model name
  49. * TODO Replace with getName()
  50. *
  51. * @param Translate $langs Object langs
  52. * @return string Model name
  53. */
  54. public function getNom($langs)
  55. {
  56. return empty($this->name) ? get_class($this) : $this->name;
  57. }
  58. /** Return model name
  59. *
  60. * @param Translate $langs Object langs
  61. * @return string Model name
  62. */
  63. public function getName($langs)
  64. {
  65. return empty($this->name) ? get_class($this) : $this->name;
  66. }
  67. /**
  68. * Return if a module can be used or not
  69. *
  70. * @return boolean true if module can be used
  71. */
  72. public function isEnabled()
  73. {
  74. return true;
  75. }
  76. /**
  77. * Returns the default description of the numbering template
  78. *
  79. * @param Translate $langs Language
  80. * @return string Descriptive text
  81. */
  82. public function info($langs)
  83. {
  84. return $langs->trans("NoDescription");
  85. }
  86. /**
  87. * Checks if the numbers already in the database do not
  88. * cause conflicts that would prevent this numbering working.
  89. *
  90. * @param Object $object Object we need next value for
  91. * @return boolean false if conflict, true if ok
  92. */
  93. public function canBeActivated($object)
  94. {
  95. return true;
  96. }
  97. /**
  98. * Returns version of numbering module
  99. *
  100. * @return string Valeur
  101. */
  102. public function getVersion()
  103. {
  104. global $langs;
  105. $langs->load("admin");
  106. if ($this->version == 'development') {
  107. return $langs->trans("VersionDevelopment");
  108. }
  109. if ($this->version == 'experimental') {
  110. return $langs->trans("VersionExperimental");
  111. }
  112. if ($this->version == 'dolibarr') {
  113. return DOL_VERSION;
  114. }
  115. if ($this->version) {
  116. return $this->version;
  117. }
  118. return $langs->trans("NotAvailable");
  119. }
  120. }