mymodulewidget1.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php
  2. /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018-2021 Frédéric France <frederic.france@netlogic.fr>
  4. * Copyright (C) ---Put here your own copyright and developer email---
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/modulebuilder/template/core/boxes/mymodulewidget1.php
  21. * \ingroup mymodule
  22. * \brief Widget provided by MyModule
  23. *
  24. * Put detailed description here.
  25. */
  26. include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
  27. /**
  28. * Class to manage the box
  29. *
  30. * Warning: for the box to be detected correctly by dolibarr,
  31. * the filename should be the lowercase classname
  32. */
  33. class mymodulewidget1 extends ModeleBoxes
  34. {
  35. /**
  36. * @var string Alphanumeric ID. Populated by the constructor.
  37. */
  38. public $boxcode = "mymodulebox";
  39. /**
  40. * @var string Box icon (in configuration page)
  41. * Automatically calls the icon named with the corresponding "object_" prefix
  42. */
  43. public $boximg = "mymodule@mymodule";
  44. /**
  45. * @var string Box label (in configuration page)
  46. */
  47. public $boxlabel;
  48. /**
  49. * @var string[] Module dependencies
  50. */
  51. public $depends = array('mymodule');
  52. /**
  53. * @var DoliDb Database handler
  54. */
  55. public $db;
  56. /**
  57. * @var mixed More parameters
  58. */
  59. public $param;
  60. /**
  61. * @var array Header informations. Usually created at runtime by loadBox().
  62. */
  63. public $info_box_head = array();
  64. /**
  65. * @var array Contents informations. Usually created at runtime by loadBox().
  66. */
  67. public $info_box_contents = array();
  68. /**
  69. * @var string Widget type ('graph' means the widget is a graph widget)
  70. */
  71. public $widgettype = 'graph';
  72. /**
  73. * Constructor
  74. *
  75. * @param DoliDB $db Database handler
  76. * @param string $param More parameters
  77. */
  78. public function __construct(DoliDB $db, $param = '')
  79. {
  80. global $user, $conf, $langs;
  81. // Translations
  82. $langs->loadLangs(array("boxes", "mymodule@mymodule"));
  83. parent::__construct($db, $param);
  84. $this->boxlabel = $langs->transnoentitiesnoconv("MyWidget");
  85. $this->param = $param;
  86. //$this->enabled = $conf->global->FEATURES_LEVEL > 0; // Condition when module is enabled or not
  87. //$this->hidden = ! ($user->rights->mymodule->myobject->read); // Condition when module is visible by user (test on permission)
  88. }
  89. /**
  90. * Load data into info_box_contents array to show array later. Called by Dolibarr before displaying the box.
  91. *
  92. * @param int $max Maximum number of records to load
  93. * @return void
  94. */
  95. public function loadBox($max = 5)
  96. {
  97. global $langs;
  98. // Use configuration value for max lines count
  99. $this->max = $max;
  100. //dol_include_once("/mymodule/class/mymodule.class.php");
  101. // Populate the head at runtime
  102. $text = $langs->trans("MyModuleBoxDescription", $max);
  103. $this->info_box_head = array(
  104. // Title text
  105. 'text' => $text,
  106. // Add a link
  107. 'sublink' => 'http://example.com',
  108. // Sublink icon placed after the text
  109. 'subpicto' => 'object_mymodule@mymodule',
  110. // Sublink icon HTML alt text
  111. 'subtext' => '',
  112. // Sublink HTML target
  113. 'target' => '',
  114. // HTML class attached to the picto and link
  115. 'subclass' => 'center',
  116. // Limit and truncate with "…" the displayed text lenght, 0 = disabled
  117. 'limit' => 0,
  118. // Adds translated " (Graph)" to a hidden form value's input (?)
  119. 'graph' => false
  120. );
  121. // Populate the contents at runtime
  122. $this->info_box_contents = array(
  123. 0 => array( // First line
  124. 0 => array( // First Column
  125. // HTML properties of the TR element. Only available on the first column.
  126. 'tr' => 'class="left"',
  127. // HTML properties of the TD element
  128. 'td' => '',
  129. // Main text for content of cell
  130. 'text' => 'First cell of first line',
  131. // Link on 'text' and 'logo' elements
  132. 'url' => 'http://example.com',
  133. // Link's target HTML property
  134. 'target' => '_blank',
  135. // Fist line logo (deprecated. Include instead logo html code into text or text2, and set asis property to true to avoid HTML cleaning)
  136. //'logo' => 'monmodule@monmodule',
  137. // Unformatted text, added after text. Usefull to add/load javascript code
  138. 'textnoformat' => '',
  139. // Main text for content of cell (other method)
  140. //'text2' => '<p><strong>Another text</strong></p>',
  141. // Truncates 'text' element to the specified character length, 0 = disabled
  142. 'maxlength' => 0,
  143. // Prevents HTML cleaning (and truncation)
  144. 'asis' => false,
  145. // Same for 'text2'
  146. 'asis2' => true
  147. ),
  148. 1 => array( // Another column
  149. // No TR for n≠0
  150. 'td' => '',
  151. 'text' => 'Second cell',
  152. )
  153. ),
  154. 1 => array( // Another line
  155. 0 => array( // TR
  156. 'tr' => 'class="left"',
  157. 'text' => 'Another line'
  158. ),
  159. 1 => array( // TR
  160. 'tr' => 'class="left"',
  161. 'text' => ''
  162. )
  163. ),
  164. 2 => array( // Another line
  165. 0 => array( // TR
  166. 'tr' => 'class="left"',
  167. 'text' => ''
  168. ),
  169. 1 => array( // TR
  170. 'tr' => 'class="left"',
  171. 'text' => ''
  172. )
  173. ),
  174. );
  175. }
  176. /**
  177. * Method to show box. Called by Dolibarr eatch time it wants to display the box.
  178. *
  179. * @param array $head Array with properties of box title
  180. * @param array $contents Array with properties of box lines
  181. * @param int $nooutput No print, only return string
  182. * @return string
  183. */
  184. public function showBox($head = null, $contents = null, $nooutput = 0)
  185. {
  186. // You may make your own code here…
  187. // … or use the parent's class function using the provided head and contents templates
  188. return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
  189. }
  190. }