dolibarr  17.0.4
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-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 
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  //$this->enabled = getDolGlobalInt(FEATURES_LEVEL) > 0; // Condition when module is enabled or not
105  //$this->hidden = ! ($user->hasRight('mymodule,'myobject','read'); // Condition when module is visible by user (test on permission)
106  }
107 
114  public function loadBox($max = 5)
115  {
116  global $langs;
117 
118  // Use configuration value for max lines count
119  $this->max = $max;
120 
121  //dol_include_once("/mymodule/class/mymodule.class.php");
122 
123  // Populate the head at runtime
124  $text = $langs->trans("MyModuleBoxDescription", $max);
125  $this->info_box_head = array(
126  // Title text
127  'text' => $text,
128  // Add a link
129  'sublink' => 'http://example.com',
130  // Sublink icon placed after the text
131  'subpicto' => 'object_mymodule@mymodule',
132  // Sublink icon HTML alt text
133  'subtext' => '',
134  // Sublink HTML target
135  'target' => '',
136  // HTML class attached to the picto and link
137  'subclass' => 'center',
138  // Limit and truncate with "…" the displayed text lenght, 0 = disabled
139  'limit' => 0,
140  // Adds translated " (Graph)" to a hidden form value's input (?)
141  'graph' => false
142  );
143 
144  // Populate the contents at runtime
145  $this->info_box_contents = array(
146  0 => array( // First line
147  0 => array( // First Column
148  // HTML properties of the TR element. Only available on the first column.
149  'tr' => 'class="left"',
150  // HTML properties of the TD element
151  'td' => '',
152 
153  // Main text for content of cell
154  'text' => 'First cell of first line',
155  // Link on 'text' and 'logo' elements
156  'url' => 'http://example.com',
157  // Link's target HTML property
158  'target' => '_blank',
159  // Fist line logo (deprecated. Include instead logo html code into text or text2, and set asis property to true to avoid HTML cleaning)
160  //'logo' => 'monmodule@monmodule',
161  // Unformatted text, added after text. Usefull to add/load javascript code
162  'textnoformat' => '',
163 
164  // Main text for content of cell (other method)
165  //'text2' => '<p><strong>Another text</strong></p>',
166 
167  // Truncates 'text' element to the specified character length, 0 = disabled
168  'maxlength' => 0,
169  // Prevents HTML cleaning (and truncation)
170  'asis' => false,
171  // Same for 'text2'
172  'asis2' => true
173  ),
174  1 => array( // Another column
175  // No TR for n≠0
176  'td' => '',
177  'text' => 'Second cell',
178  )
179  ),
180  1 => array( // Another line
181  0 => array( // TR
182  'tr' => 'class="left"',
183  'text' => 'Another line'
184  ),
185  1 => array( // TR
186  'tr' => 'class="left"',
187  'text' => ''
188  )
189  ),
190  2 => array( // Another line
191  0 => array( // TR
192  'tr' => 'class="left"',
193  'text' => ''
194  ),
195  1 => array( // TR
196  'tr' => 'class="left"',
197  'text' => ''
198  )
199  ),
200  );
201  }
202 
211  public function showBox($head = null, $contents = null, $nooutput = 0)
212  {
213  // You may make your own code here…
214  // … or use the parent's class function using the provided head and contents templates
215  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
216  }
217 }
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.