dolibarr  13.0.2
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-2020 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 
86  public function __construct(DoliDB $db, $param = '')
87  {
88  global $user, $conf, $langs;
89  $langs->load("boxes");
90  $langs->load('mymodule@mymodule');
91 
92  parent::__construct($db, $param);
93 
94  $this->boxlabel = $langs->transnoentitiesnoconv("MyWidget");
95 
96  $this->param = $param;
97 
98  //$this->enabled = $conf->global->FEATURES_LEVEL > 0; // Condition when module is enabled or not
99  //$this->hidden = ! ($user->rights->mymodule->myobject->read); // Condition when module is visible by user (test on permission)
100  }
101 
108  public function loadBox($max = 5)
109  {
110  global $langs;
111 
112  // Use configuration value for max lines count
113  $this->max = $max;
114 
115  //dol_include_once("/mymodule/class/mymodule.class.php");
116 
117  // Populate the head at runtime
118  $text = $langs->trans("MyModuleBoxDescription", $max);
119  $this->info_box_head = array(
120  // Title text
121  'text' => $text,
122  // Add a link
123  'sublink' => 'http://example.com',
124  // Sublink icon placed after the text
125  'subpicto' => 'object_mymodule@mymodule',
126  // Sublink icon HTML alt text
127  'subtext' => '',
128  // Sublink HTML target
129  'target' => '',
130  // HTML class attached to the picto and link
131  'subclass' => 'center',
132  // Limit and truncate with "…" the displayed text lenght, 0 = disabled
133  'limit' => 0,
134  // Adds translated " (Graph)" to a hidden form value's input (?)
135  'graph' => false
136  );
137 
138  // Populate the contents at runtime
139  $this->info_box_contents = array(
140  0 => array( // First line
141  0 => array( // First Column
142  // HTML properties of the TR element. Only available on the first column.
143  'tr' => 'class="left"',
144  // HTML properties of the TD element
145  'td' => '',
146 
147  // Main text for content of cell
148  'text' => 'First cell of first line',
149  // Link on 'text' and 'logo' elements
150  'url' => 'http://example.com',
151  // Link's target HTML property
152  'target' => '_blank',
153  // Fist line logo (deprecated. Include instead logo html code into text or text2, and set asis property to true to avoid HTML cleaning)
154  //'logo' => 'monmodule@monmodule',
155  // Unformatted text, added after text. Usefull to add/load javascript code
156  'textnoformat' => '',
157 
158  // Main text for content of cell (other method)
159  //'text2' => '<p><strong>Another text</strong></p>',
160 
161  // Truncates 'text' element to the specified character length, 0 = disabled
162  'maxlength' => 0,
163  // Prevents HTML cleaning (and truncation)
164  'asis' => false,
165  // Same for 'text2'
166  'asis2' => true
167  ),
168  1 => array( // Another column
169  // No TR for n≠0
170  'td' => '',
171  'text' => 'Second cell',
172  )
173  ),
174  1 => array( // Another line
175  0 => array( // TR
176  'tr' => 'class="left"',
177  'text' => 'Another line'
178  ),
179  1 => array( // TR
180  'tr' => 'class="left"',
181  'text' => ''
182  )
183  ),
184  2 => array( // Another line
185  0 => array( // TR
186  'tr' => 'class="left"',
187  'text' => ''
188  ),
189  1 => array( // TR
190  'tr' => 'class="left"',
191  'text' => ''
192  )
193  ),
194  );
195  }
196 
205  public function showBox($head = null, $contents = null, $nooutput = 0)
206  {
207  // You may make your own code here…
208  // … or use the parent's class function using the provided head and contents templates
209  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
210  }
211 }
__construct(DoliDB $db, $param= '')
Constructor.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Class to manage Dolibarr database access.
Class ModeleBoxes.
Class to manage the box.
loadBox($max=5)
Load data into info_box_contents array to show array later.