dolibarr/htdocs/modulebuilder/template/core/boxes/mymodulewidget1.php

220 lines
6.1 KiB
PHP
Raw Normal View History

2017-05-08 19:00:23 +00:00
<?php
2018-11-09 14:29:49 +00:00
/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
2023-04-18 18:40:07 +00:00
* Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
2017-07-08 13:43:36 +00:00
* Copyright (C) ---Put here your own copyright and developer email---
2017-05-08 19:00:23 +00:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 19:55:30 +00:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2017-05-08 19:00:23 +00:00
*/
/**
2019-03-10 18:33:28 +00:00
* \file htdocs/modulebuilder/template/core/boxes/mymodulewidget1.php
2017-05-08 19:00:23 +00:00
* \ingroup mymodule
2017-07-16 10:07:59 +00:00
* \brief Widget provided by MyModule
2017-05-08 19:00:23 +00:00
*
* Put detailed description here.
*/
include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php";
2017-05-08 19:00:23 +00:00
2020-12-11 01:12:39 +00:00
2017-05-08 19:00:23 +00:00
/**
* Class to manage the box
*
* Warning: for the box to be detected correctly by dolibarr,
* the filename should be the lowercase classname
*/
2017-07-16 10:07:59 +00:00
class mymodulewidget1 extends ModeleBoxes
2017-05-08 19:00:23 +00:00
{
/**
* @var string Alphanumeric ID. Populated by the constructor.
*/
2017-07-16 10:07:59 +00:00
public $boxcode = "mymodulebox";
2017-05-08 19:00:23 +00:00
/**
* @var string Box icon (in configuration page)
* Automatically calls the icon named with the corresponding "object_" prefix
*/
public $boximg = "mymodule@mymodule";
/**
* @var string Box label (in configuration page)
*/
public $boxlabel;
/**
* @var string[] Module dependencies
*/
public $depends = array('mymodule');
/**
* @var DoliDb Database handler
*/
public $db;
/**
* @var mixed More parameters
*/
public $param;
/**
* @var array Header informations. Usually created at runtime by loadBox().
*/
public $info_box_head = array();
/**
* @var array Contents informations. Usually created at runtime by loadBox().
*/
public $info_box_contents = array();
2021-03-10 16:02:39 +00:00
/**
* @var string Widget type ('graph' means the widget is a graph widget)
*/
public $widgettype = 'graph';
2017-05-08 19:00:23 +00:00
/**
* Constructor
*
* @param DoliDB $db Database handler
* @param string $param More parameters
*/
public function __construct(DoliDB $db, $param = '')
{
2017-06-12 12:12:40 +00:00
global $user, $conf, $langs;
2021-12-04 14:19:45 +00:00
// Translations
$langs->loadLangs(array("boxes", "mymodule@mymodule"));
2017-05-08 19:00:23 +00:00
parent::__construct($db, $param);
2017-07-16 10:07:59 +00:00
$this->boxlabel = $langs->transnoentitiesnoconv("MyWidget");
2017-05-08 19:00:23 +00:00
$this->param = $param;
2017-06-12 12:12:40 +00:00
2023-04-18 18:40:07 +00:00
// Condition when module is enabled or not
// $this->enabled = getDolGlobalInt('MAIN_FEATURES_LEVEL') > 0;
// Condition when module is visible by user (test on permission)
// $this->hidden = !$user->hasRight('mymodule', 'myobject', 'read');
2017-05-08 19:00:23 +00:00
}
/**
* Load data into info_box_contents array to show array later. Called by Dolibarr before displaying the box.
*
* @param int $max Maximum number of records to load
* @return void
*/
public function loadBox($max = 5)
{
global $langs;
// Use configuration value for max lines count
$this->max = $max;
2020-04-19 20:05:47 +00:00
//dol_include_once("/mymodule/class/mymodule.class.php");
2017-05-08 19:00:23 +00:00
// Populate the head at runtime
2017-07-16 10:07:59 +00:00
$text = $langs->trans("MyModuleBoxDescription", $max);
2017-05-08 19:00:23 +00:00
$this->info_box_head = array(
// Title text
'text' => $text,
// Add a link
'sublink' => 'http://example.com',
// Sublink icon placed after the text
'subpicto' => 'object_mymodule@mymodule',
// Sublink icon HTML alt text
'subtext' => '',
// Sublink HTML target
'target' => '',
// HTML class attached to the picto and link
'subclass' => 'center',
// Limit and truncate with "…" the displayed text lenght, 0 = disabled
'limit' => 0,
// Adds translated " (Graph)" to a hidden form value's input (?)
'graph' => false
);
// Populate the contents at runtime
$this->info_box_contents = array(
0 => array( // First line
0 => array( // First Column
// HTML properties of the TR element. Only available on the first column.
2019-02-09 14:24:21 +00:00
'tr' => 'class="left"',
2017-05-08 19:00:23 +00:00
// HTML properties of the TD element
2019-02-09 14:24:21 +00:00
'td' => '',
2017-07-16 10:07:59 +00:00
// Main text for content of cell
2019-02-09 14:24:21 +00:00
'text' => 'First cell of first line',
2017-05-08 19:00:23 +00:00
// Link on 'text' and 'logo' elements
2019-02-09 14:24:21 +00:00
'url' => 'http://example.com',
2017-05-08 19:00:23 +00:00
// Link's target HTML property
2019-02-09 14:24:21 +00:00
'target' => '_blank',
2017-07-16 10:07:59 +00:00
// Fist line logo (deprecated. Include instead logo html code into text or text2, and set asis property to true to avoid HTML cleaning)
2019-02-09 14:24:21 +00:00
//'logo' => 'monmodule@monmodule',
2017-07-16 10:07:59 +00:00
// Unformatted text, added after text. Usefull to add/load javascript code
'textnoformat' => '',
// Main text for content of cell (other method)
2019-02-09 14:24:21 +00:00
//'text2' => '<p><strong>Another text</strong></p>',
2017-07-16 10:07:59 +00:00
2017-05-08 19:00:23 +00:00
// Truncates 'text' element to the specified character length, 0 = disabled
2019-02-09 14:24:21 +00:00
'maxlength' => 0,
2017-05-08 19:00:23 +00:00
// Prevents HTML cleaning (and truncation)
2019-02-09 14:24:21 +00:00
'asis' => false,
2017-05-08 19:00:23 +00:00
// Same for 'text2'
2019-02-09 14:24:21 +00:00
'asis2' => true
2017-05-08 19:00:23 +00:00
),
1 => array( // Another column
// No TR for n≠0
2019-02-09 14:24:21 +00:00
'td' => '',
2017-07-16 10:07:59 +00:00
'text' => 'Second cell',
2017-05-08 19:00:23 +00:00
)
),
1 => array( // Another line
0 => array( // TR
2019-02-09 14:24:21 +00:00
'tr' => 'class="left"',
2017-05-08 19:00:23 +00:00
'text' => 'Another line'
2017-07-16 10:07:59 +00:00
),
1 => array( // TR
2019-02-09 14:24:21 +00:00
'tr' => 'class="left"',
2017-07-16 10:07:59 +00:00
'text' => ''
2017-05-08 19:00:23 +00:00
)
),
2 => array( // Another line
0 => array( // TR
2019-02-09 14:24:21 +00:00
'tr' => 'class="left"',
2017-07-16 10:07:59 +00:00
'text' => ''
),
2019-03-04 22:25:23 +00:00
1 => array( // TR
2019-02-09 14:24:21 +00:00
'tr' => 'class="left"',
2017-07-16 10:07:59 +00:00
'text' => ''
2017-05-08 19:00:23 +00:00
)
),
);
}
2020-05-01 06:40:55 +00:00
/**
* Method to show box. Called by Dolibarr eatch time it wants to display the box.
*
* @param array $head Array with properties of box title
* @param array $contents Array with properties of box lines
* @param int $nooutput No print, only return string
2021-03-16 18:07:07 +00:00
* @return string
2020-05-01 06:40:55 +00:00
*/
public function showBox($head = null, $contents = null, $nooutput = 0)
{
// You may make your own code here…
// … or use the parent's class function using the provided head and contents templates
2021-03-10 10:56:44 +00:00
return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
2020-05-01 06:40:55 +00:00
}
2017-05-08 19:00:23 +00:00
}