Repository Access Links:

This URL has Read-Only access.
Statistics
| Branch: | Revision:

dolibarr-module-template / core / boxes / mybox.php @ ef37f43f

History | View | Annotate | Download (5.2 kB)

1
<?php
2
/* <one line to give the program's name and a brief idea of what it does.>
3
 * Copyright (C) <year>  <name of author>
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

    
19
/**
20
 * \file    core/boxes/mybox.php
21
 * \ingroup mymodule
22
 * \brief   Example box definition.
23
 *
24
 * Put detailed description here.
25
 */
26

    
27
/** Includes */
28
include_once DOL_DOCUMENT_ROOT . "/core/boxes/modules_boxes.php";
29

    
30
/**
31
 * Class to manage the box
32
 *
33
 * Warning: for the box to be detected correctly by dolibarr,
34
 * the filename should be the lowercase classname
35
 */
36
class MyBox extends ModeleBoxes
37
{
38
        /**
39
         * @var string Alphanumeric ID. Populated by the constructor.
40
         */
41
        public $boxcode = "mybox";
42

    
43
        /**
44
         * @var string Box icon (in configuration page)
45
         * Automatically calls the icon named with the corresponding "object_" prefix
46
         */
47
        public $boximg = "mymodule@mymodule";
48

    
49
        /**
50
         * @var string Box label (in configuration page)
51
         */
52
        public $boxlabel;
53

    
54
        /**
55
         * @var string[] Module dependencies
56
         */
57
        public $depends = array('mymodule');
58

    
59
        /**
60
         * @var DoliDb Database handler
61
         */
62
        public $db;
63

    
64
        /**
65
         * @var mixed More parameters
66
         */
67
        public $param;
68

    
69
        /**
70
         * @var array Header informations. Usually created at runtime by loadBox().
71
         */
72
        public $info_box_head = array();
73

    
74
        /**
75
         * @var array Contents informations. Usually created at runtime by loadBox().
76
         */
77
        public $info_box_contents = array();
78

    
79
        /**
80
         * Constructor
81
         *
82
         * @param DoliDB $db Database handler
83
         * @param string $param More parameters
84
         */
85
        public function __construct(DoliDB $db, $param = '')
86
        {
87
                global $langs;
88
                $langs->load("boxes");
89
                $langs->load('mymodule@mymodule');
90

    
91
                $this->boxlabel = $langs->transnoentitiesnoconv("MyBox");
92

    
93
                $this->db = $db;
94
                $this->param = $param;
95
        }
96

    
97
        /**
98
         * Load data into info_box_contents array to show array later. Called by Dolibarr before displaying the box.
99
         *
100
         * @param int $max Maximum number of records to load
101
         * @return void
102
         */
103
        public function loadBox($max = 5)
104
        {
105
                global $langs;
106

    
107
                // Use configuration value for max lines count
108
                $this->max = $max;
109

    
110
                //include_once DOL_DOCUMENT_ROOT . "/mymodule/class/mymodule.class.php";
111

    
112
                // Populate the head at runtime
113
                $text = $langs->trans("MyBoxDescription", $max);
114
                $this->info_box_head = array(
115
                        // Title text
116
                        'text' => $text,
117
                        // Add a link
118
                        'sublink' => 'http://example.com',
119
                        // Sublink icon placed after the text
120
                        'subpicto' => 'object_mymodule@mymodule',
121
                        // Sublink icon HTML alt text
122
                        'subtext' => '',
123
                        // Sublink HTML target
124
                        'target' => '',
125
                        // HTML class attached to the picto and link
126
                        'subclass' => 'center',
127
                        // Limit and truncate with "?" the displayed text lenght, 0 = disabled
128
                        'limit' => 0,
129
                        // Adds translated " (Graph)" to a hidden form value's input (?)
130
                        'graph' => false
131
                );
132

    
133
                // Populate the contents at runtime
134
                $this->info_box_contents = array(
135
                        0 => array( // First line
136
                                0 => array( // First Column
137
                                        //  HTML properties of the TR element. Only available on the first column.
138
                                        'tr'           => 'align="left"',
139
                                        // HTML properties of the TD element
140
                                        'td'           => '',
141
                                        // Fist line logo
142
                                        'logo'         => 'mymodule@mymodule',
143
                                        // Main text
144
                                        'text'         => 'My text',
145
                                        // Secondary text
146
                                        'text2'        => '<p><strong>Another text</strong></p>',
147
                                        // Unformatted text, usefull to load javascript elements
148
                                        'textnoformat' => '',
149
                                        // Link on 'text' and 'logo' elements
150
                                        'url'          => 'http://example.com',
151
                                        // Link's target HTML property
152
                                        'target'       => '_blank',
153
                                        // Truncates 'text' element to the specified character length, 0 = disabled
154
                                        'maxlength'    => 0,
155
                                        // Prevents HTML cleaning (and truncation)
156
                                        'asis'         => false,
157
                                        // Same for 'text2'
158
                                        'asis2'        => true
159
                                ),
160
                                1 => array( // Another column
161
                                        // No TR for n?0
162
                                        'td'   => '',
163
                                        'text' => 'Another cell',
164
                                )
165
                        ),
166
                        1 => array( // Another line
167
                                0 => array( // TR
168
                                        'tr'   => 'align="left"',
169
                                        'text' => 'Another line'
170
                                )
171
                        ),
172
                        2 => array( // Another line
173
                                0 => array( // TR
174
                                        'tr'   => 'align="left"',
175
                                        'text' => 'Yet another line'
176
                                )
177
                        ),
178
                );
179
        }
180

    
181
        /**
182
         * Method to show box. Called by Dolibarr eatch time it wants to display the box.
183
         *
184
         * @param array $head Array with properties of box title
185
         * @param array $contents Array with properties of box lines
186
         * @return void
187
         */
188
        public function showBox($head = null, $contents = null)
189
        {
190
                // You may make your own code here?
191
                // ? or use the parent's class function using the provided head and contents templates
192
                parent::showBox($this->info_box_head, $this->info_box_contents);
193
        }
194
}