dolibarr  19.0.0-dev
mymodulewidget1.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3  * Copyright (C) 2018-2023 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 
28 include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
29 
30 
38 {
42  public $boxcode = "mymodulebox";
43 
48  public $boximg = "mymodule@mymodule";
49 
53  public $boxlabel;
54 
58  public $depends = array('mymodule');
59 
63  public $db;
64 
68  public $param;
69 
73  public $info_box_head = array();
74 
78  public $info_box_contents = array();
79 
83  public $widgettype = 'graph';
84 
85 
92  public function __construct(DoliDB $db, $param = '')
93  {
94  global $user, $conf, $langs;
95  // Translations
96  $langs->loadLangs(array("boxes", "mymodule@mymodule"));
97 
98  parent::__construct($db, $param);
99 
100  $this->boxlabel = $langs->transnoentitiesnoconv("MyWidget");
101 
102  $this->param = $param;
103 
104  // Condition when module is enabled or not
105  // $this->enabled = getDolGlobalInt('MAIN_FEATURES_LEVEL') > 0;
106  // Condition when module is visible by user (test on permission)
107  // $this->hidden = !$user->hasRight('mymodule', 'myobject', 'read');
108  }
109 
116  public function loadBox($max = 5)
117  {
118  global $langs;
119 
120  // Use configuration value for max lines count
121  $this->max = $max;
122 
123  //dol_include_once("/mymodule/class/mymodule.class.php");
124 
125  // Populate the head at runtime
126  $text = $langs->trans("MyModuleBoxDescription", $max);
127  $this->info_box_head = array(
128  // Title text
129  'text' => $text,
130  // Add a link
131  'sublink' => 'http://example.com',
132  // Sublink icon placed after the text
133  'subpicto' => 'object_mymodule@mymodule',
134  // Sublink icon HTML alt text
135  'subtext' => '',
136  // Sublink HTML target
137  'target' => '',
138  // HTML class attached to the picto and link
139  'subclass' => 'center',
140  // Limit and truncate with "…" the displayed text lenght, 0 = disabled
141  'limit' => 0,
142  // Adds translated " (Graph)" to a hidden form value's input (?)
143  'graph' => false
144  );
145 
146  // Populate the contents at runtime
147  $this->info_box_contents = array(
148  0 => array( // First line
149  0 => array( // First Column
150  // HTML properties of the TR element. Only available on the first column.
151  'tr' => 'class="left"',
152  // HTML properties of the TD element
153  'td' => '',
154 
155  // Main text for content of cell
156  'text' => 'First cell of first line',
157  // Link on 'text' and 'logo' elements
158  'url' => 'http://example.com',
159  // Link's target HTML property
160  'target' => '_blank',
161  // Fist line logo (deprecated. Include instead logo html code into text or text2, and set asis property to true to avoid HTML cleaning)
162  //'logo' => 'monmodule@monmodule',
163  // Unformatted text, added after text. Usefull to add/load javascript code
164  'textnoformat' => '',
165 
166  // Main text for content of cell (other method)
167  //'text2' => '<p><strong>Another text</strong></p>',
168 
169  // Truncates 'text' element to the specified character length, 0 = disabled
170  'maxlength' => 0,
171  // Prevents HTML cleaning (and truncation)
172  'asis' => false,
173  // Same for 'text2'
174  'asis2' => true
175  ),
176  1 => array( // Another column
177  // No TR for n≠0
178  'td' => '',
179  'text' => 'Second cell',
180  )
181  ),
182  1 => array( // Another line
183  0 => array( // TR
184  'tr' => 'class="left"',
185  'text' => 'Another line'
186  ),
187  1 => array( // TR
188  'tr' => 'class="left"',
189  'text' => ''
190  )
191  ),
192  2 => array( // Another line
193  0 => array( // TR
194  'tr' => 'class="left"',
195  'text' => ''
196  ),
197  1 => array( // TR
198  'tr' => 'class="left"',
199  'text' => ''
200  )
201  ),
202  );
203  }
204 
213  public function showBox($head = null, $contents = null, $nooutput = 0)
214  {
215  // You may make your own code here…
216  // … or use the parent's class function using the provided head and contents templates
217  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
218  }
219 }
Class to manage Dolibarr database access.
Class ModeleBoxes.
Class to manage the box.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct(DoliDB $db, $param='')
Constructor.
loadBox($max=5)
Load data into info_box_contents array to show array later.