mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-10-15 05:04:32 +02:00
Feature GLP11 (#88)
* Feature GLP11 * phpstan * enable CI and fix phstanneon * Update .github/workflows/continuous-integration.yml Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> * Update phpstan.neon Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> * Pass all paramters to parent call * move query -> doQuery * fix direct query * release GLPI 11.0 * Clean composer.json * psalm + rector * fix --------- Co-authored-by: Romain B. <8530352+Rom1-B@users.noreply.github.com> Co-authored-by: Johan Cwiklinski <johan@x-tnd.be> Co-authored-by: Rom1-B <rom1.biot@gmail.com>
This commit is contained in:
@@ -59,25 +59,25 @@ class Child extends CommonDBChild
|
||||
// - CommonDBConnexity::HAVE_SAME_RIGHT_ON_ITEM we must have at least update right
|
||||
// on the item
|
||||
// * $mustBeAttached: some CommonDBChild can be free, without any parent.
|
||||
public static function canCreate()
|
||||
public static function canCreate(): bool
|
||||
{
|
||||
return (Session::haveRight('internet', UPDATE)
|
||||
&& parent::canCreate());
|
||||
}
|
||||
|
||||
public static function canView()
|
||||
public static function canView(): bool
|
||||
{
|
||||
return (Session::haveRight('internet', READ)
|
||||
&& parent::canView());
|
||||
}
|
||||
|
||||
public static function canUpdate()
|
||||
public static function canUpdate(): bool
|
||||
{
|
||||
return (Session::haveRight('internet', UPDATE)
|
||||
&& parent::canUpdate());
|
||||
}
|
||||
|
||||
public static function canDelete()
|
||||
public static function canDelete(): bool
|
||||
{
|
||||
return (Session::haveRight('internet', DELETE)
|
||||
&& parent::canDelete());
|
||||
|
@@ -37,23 +37,17 @@ namespace GlpiPlugin\Example;
|
||||
|
||||
use CommonDBTM;
|
||||
|
||||
// Class of the defined type
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die("Sorry. You can't access directly to this file");
|
||||
}
|
||||
|
||||
class Computer extends CommonDBTM
|
||||
{
|
||||
public static function showInfo()
|
||||
{
|
||||
echo '<table class="tab_glpi" width="100%">';
|
||||
echo '<tr>';
|
||||
echo '<th>' . __('More information') . '</th>';
|
||||
echo '<th>' . __s('More information') . '</th>';
|
||||
echo '</tr>';
|
||||
echo '<tr class="tab_bg_1">';
|
||||
echo '<td>';
|
||||
echo __('Test successful');
|
||||
echo __s('Test successful');
|
||||
echo '</td>';
|
||||
echo '</tr>';
|
||||
echo '</table>';
|
||||
@@ -71,7 +65,7 @@ class Computer extends CommonDBTM
|
||||
|
||||
public static function add_default_where($in)
|
||||
{
|
||||
list($itemtype, $condition) = $in;
|
||||
[$itemtype, $condition] = $in;
|
||||
if ($itemtype == 'Computer') {
|
||||
$table = getTableForItemType($itemtype);
|
||||
$condition .= ' (' . $table . '.groups_id NOT IN (' . implode(',', $_SESSION['glpigroups']) . '))';
|
||||
|
@@ -44,10 +44,8 @@ class Config extends CommonDBTM
|
||||
|
||||
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
||||
{
|
||||
if (!$withtemplate) {
|
||||
if ($item->getType() == 'Config') {
|
||||
return __('Example plugin');
|
||||
}
|
||||
if (!$withtemplate && $item->getType() == 'Config') {
|
||||
return __s('Example plugin');
|
||||
}
|
||||
|
||||
return '';
|
||||
@@ -73,10 +71,10 @@ class Config extends CommonDBTM
|
||||
echo "<form name='form' action=\"" . Toolbox::getItemTypeFormURL('Config') . "\" method='post'>";
|
||||
echo "<div class='center' id='tabsbody'>";
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr><th colspan='4'>" . __('Example setup') . '</th></tr>';
|
||||
echo '<td >' . __('My boolean choice :') . '</td>';
|
||||
echo "<tr><th colspan='4'>" . __s('Example setup') . '</th></tr>';
|
||||
echo '<td >' . __s('My boolean choice :') . '</td>';
|
||||
echo "<td colspan='3'>";
|
||||
echo "<input type='hidden' name='config_class' value='" . __CLASS__ . "'>";
|
||||
echo "<input type='hidden' name='config_class' value='" . self::class . "'>";
|
||||
echo "<input type='hidden' name='config_context' value='plugin:Example'>";
|
||||
Dropdown::showYesNo('configuration', $my_config['configuration']);
|
||||
echo '</td></tr>';
|
||||
@@ -96,5 +94,6 @@ class Config extends CommonDBTM
|
||||
$config = new self();
|
||||
$config->showFormExample();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@@ -37,17 +37,11 @@ namespace GlpiPlugin\Example;
|
||||
|
||||
use CommonDevice;
|
||||
|
||||
// Class of the defined type
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die("Sorry. You can't access directly to this file");
|
||||
}
|
||||
|
||||
/// Class DeviceCamera
|
||||
class DeviceCamera extends CommonDevice
|
||||
{
|
||||
public static function getTypeName($nb = 0)
|
||||
{
|
||||
return _n('Camera', 'Cameras', $nb);
|
||||
return _sn('Camera', 'Cameras', $nb);
|
||||
}
|
||||
}
|
||||
|
@@ -1,30 +1,31 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
-------------------------------------------------------------------------
|
||||
GLPI - Gestionnaire Libre de Parc Informatique
|
||||
Copyright (C) 2003-2011 by the INDEPNET Development Team.
|
||||
|
||||
http://indepnet.net/ http://glpi-project.org
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
LICENSE
|
||||
|
||||
This file is part of GLPI.
|
||||
|
||||
GLPI 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 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GLPI 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
|
||||
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
|
||||
--------------------------------------------------------------------------
|
||||
/**
|
||||
* -------------------------------------------------------------------------
|
||||
* Example plugin for GLPI
|
||||
* -------------------------------------------------------------------------
|
||||
*
|
||||
* LICENSE
|
||||
*
|
||||
* This file is part of Example.
|
||||
*
|
||||
* Example 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 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Example 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
|
||||
* along with Example. If not, see <http://www.gnu.org/licenses/>.
|
||||
* -------------------------------------------------------------------------
|
||||
* @copyright Copyright (C) 2006-2022 by Example plugin team.
|
||||
* @license GPLv2 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
* @link https://github.com/pluginsGLPI/example
|
||||
* -------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -58,10 +59,6 @@ namespace GlpiPlugin\Example;
|
||||
|
||||
use Document as GlpiDocument;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die("Sorry. You can't access this file directly");
|
||||
}
|
||||
|
||||
class Document extends GlpiDocument
|
||||
{
|
||||
/**
|
||||
@@ -74,9 +71,9 @@ class Document extends GlpiDocument
|
||||
public static function getTable($classname = null)
|
||||
{
|
||||
if ($classname === null) {
|
||||
$classname = get_called_class();
|
||||
$classname = static::class;
|
||||
}
|
||||
if ($classname == get_called_class()) {
|
||||
if ($classname == static::class) {
|
||||
return parent::getTable(Document::class);
|
||||
}
|
||||
|
||||
@@ -128,11 +125,9 @@ class Document extends GlpiDocument
|
||||
public function post_getFromDB()
|
||||
{
|
||||
// Check the user can view this itemtype and can view this item
|
||||
if ($this->canView() && $this->canViewItem()) {
|
||||
if (isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/octet-stream'
|
||||
|| isset($_GET['alt']) && $_GET['alt'] == 'media') {
|
||||
$this->sendFile(); // and terminate script
|
||||
}
|
||||
if ($this->canView() && $this->canViewItem() && (isset($_SERVER['HTTP_ACCEPT']) && $_SERVER['HTTP_ACCEPT'] == 'application/octet-stream' || isset($_GET['alt']) && $_GET['alt'] == 'media')) {
|
||||
$this->sendFile();
|
||||
// and terminate script
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,14 +162,12 @@ class Document extends GlpiDocument
|
||||
}
|
||||
|
||||
// set range if specified by the client
|
||||
if (isset($_SERVER['HTTP_RANGE'])) {
|
||||
if (preg_match('/bytes=\h*(\d+)?-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
|
||||
if (!empty($matches[1])) {
|
||||
$begin = intval($matches[1]);
|
||||
}
|
||||
if (!empty($matches[2])) {
|
||||
$end = min(intval($matches[2]), $end);
|
||||
}
|
||||
if (isset($_SERVER['HTTP_RANGE']) && preg_match('/bytes=\h*(\d+)?-(\d*)[\D.*]?/i', $_SERVER['HTTP_RANGE'], $matches)) {
|
||||
if (!empty($matches[1])) {
|
||||
$begin = intval($matches[1]);
|
||||
}
|
||||
if (!empty($matches[2])) {
|
||||
$end = min(intval($matches[2]), $end);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -43,9 +43,9 @@ class Dropdown extends CommonDropdown
|
||||
public static function getTypeName($nb = 0)
|
||||
{
|
||||
if ($nb > 0) {
|
||||
return __('Plugin Example Dropdowns', 'example');
|
||||
return __s('Plugin Example Dropdowns', 'example');
|
||||
}
|
||||
|
||||
return __('Plugin Example Dropdowns', 'example');
|
||||
return __s('Plugin Example Dropdowns', 'example');
|
||||
}
|
||||
}
|
||||
|
188
src/Example.php
188
src/Example.php
@@ -35,13 +35,19 @@
|
||||
|
||||
namespace GlpiPlugin\Example;
|
||||
|
||||
use Central;
|
||||
use CommonDBTM;
|
||||
use CommonGLPI;
|
||||
use Computer;
|
||||
use Html;
|
||||
use Item_Disk;
|
||||
use Log;
|
||||
use MassiveAction;
|
||||
use Notification;
|
||||
use Phone;
|
||||
use Preference;
|
||||
use Session;
|
||||
use Supplier;
|
||||
|
||||
// Class of the defined type
|
||||
class Example extends CommonDBTM
|
||||
@@ -57,7 +63,7 @@ class Example extends CommonDBTM
|
||||
|
||||
public static function getMenuName()
|
||||
{
|
||||
return __('Example plugin');
|
||||
return __s('Example plugin');
|
||||
}
|
||||
|
||||
public static function getAdditionalMenuLinks()
|
||||
@@ -90,7 +96,7 @@ class Example extends CommonDBTM
|
||||
|
||||
echo "<tr class='tab_bg_1'>";
|
||||
|
||||
echo '<td>' . __('ID') . '</td>';
|
||||
echo '<td>' . __s('ID') . '</td>';
|
||||
echo '<td>';
|
||||
echo $ID;
|
||||
echo '</td>';
|
||||
@@ -106,28 +112,28 @@ class Example extends CommonDBTM
|
||||
|
||||
$tab[] = [
|
||||
'id' => 'common',
|
||||
'name' => __('Header Needed'),
|
||||
'name' => __s('Header Needed'),
|
||||
];
|
||||
|
||||
$tab[] = [
|
||||
'id' => '1',
|
||||
'table' => 'glpi_plugin_example_examples',
|
||||
'field' => 'name',
|
||||
'name' => __('Name'),
|
||||
'name' => __s('Name'),
|
||||
];
|
||||
|
||||
$tab[] = [
|
||||
'id' => '2',
|
||||
'table' => 'glpi_plugin_example_dropdowns',
|
||||
'field' => 'name',
|
||||
'name' => __('Dropdown'),
|
||||
'name' => __s('Dropdown'),
|
||||
];
|
||||
|
||||
$tab[] = [
|
||||
'id' => '3',
|
||||
'table' => 'glpi_plugin_example_examples',
|
||||
'field' => 'serial',
|
||||
'name' => __('Serial number'),
|
||||
'name' => __s('Serial number'),
|
||||
'usehaving' => true,
|
||||
'searchtype' => 'equals',
|
||||
];
|
||||
@@ -136,7 +142,7 @@ class Example extends CommonDBTM
|
||||
'id' => '30',
|
||||
'table' => 'glpi_plugin_example_examples',
|
||||
'field' => 'id',
|
||||
'name' => __('ID'),
|
||||
'name' => __s('ID'),
|
||||
'usehaving' => true,
|
||||
'searchtype' => 'equals',
|
||||
];
|
||||
@@ -155,8 +161,8 @@ class Example extends CommonDBTM
|
||||
{
|
||||
switch ($name) {
|
||||
case 'Sample':
|
||||
return ['description' => __('Cron description for example', 'example'),
|
||||
'parameter' => __('Cron parameter for example', 'example')];
|
||||
return ['description' => __s('Cron description for example', 'example'),
|
||||
'parameter' => __s('Cron parameter for example', 'example')];
|
||||
}
|
||||
|
||||
return [];
|
||||
@@ -167,7 +173,7 @@ class Example extends CommonDBTM
|
||||
*
|
||||
* @param $task Object of CronTask class for log / stat
|
||||
*
|
||||
* @return interger
|
||||
* @return int
|
||||
* >0 : done
|
||||
* <0 : to be run again (not finished)
|
||||
* 0 : nothing to do
|
||||
@@ -211,33 +217,34 @@ class Example extends CommonDBTM
|
||||
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
||||
{
|
||||
if (!$withtemplate) {
|
||||
switch ($item->getType()) {
|
||||
case 'Profile':
|
||||
if ($item->getField('central')) {
|
||||
return __('Example', 'example');
|
||||
}
|
||||
break;
|
||||
if ($item instanceof Profile) {
|
||||
if ($item->getField('central')) {
|
||||
return __s('Example', 'example');
|
||||
}
|
||||
|
||||
case 'Phone':
|
||||
if ($_SESSION['glpishow_count_on_tabs']) {
|
||||
return self::createTabEntry(
|
||||
__('Example', 'example'),
|
||||
countElementsInTable($this->getTable()),
|
||||
);
|
||||
}
|
||||
} elseif ($item instanceof Phone) {
|
||||
if ($_SESSION['glpishow_count_on_tabs']) {
|
||||
return self::createTabEntry(
|
||||
__s('Example', 'example'),
|
||||
countElementsInTable($this->getTable()),
|
||||
);
|
||||
}
|
||||
|
||||
return __('Example', 'example');
|
||||
return __s('Example', 'example');
|
||||
|
||||
case 'ComputerDisk':
|
||||
case 'Supplier':
|
||||
return [1 => __('Test Plugin', 'example'),
|
||||
2 => __('Test Plugin 2', 'example')];
|
||||
} elseif ($item instanceof Item_Disk || $item instanceof Supplier) {
|
||||
return [
|
||||
1 => __s('Test Plugin', 'example'),
|
||||
2 => __s('Test Plugin 2', 'example'),
|
||||
];
|
||||
|
||||
case 'Computer':
|
||||
case 'Central':
|
||||
case 'Preference':
|
||||
case 'Notification':
|
||||
return [1 => __('Test Plugin', 'example')];
|
||||
} elseif ($item instanceof Computer
|
||||
|| $item instanceof Central
|
||||
|| $item instanceof Preference
|
||||
|| $item instanceof Notification) {
|
||||
return [
|
||||
1 => __s('Test Plugin', 'example'),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,53 +253,46 @@ class Example extends CommonDBTM
|
||||
|
||||
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
||||
{
|
||||
switch ($item->getType()) {
|
||||
case 'Phone':
|
||||
echo __('Plugin Example on Phone', 'example');
|
||||
break;
|
||||
if ($item instanceof Phone) {
|
||||
echo __s('Plugin Example on Phone', 'example');
|
||||
|
||||
case 'Central':
|
||||
echo __('Plugin central action', 'example');
|
||||
break;
|
||||
} elseif ($item instanceof Central) {
|
||||
echo __s('Plugin central action', 'example');
|
||||
|
||||
case 'Preference':
|
||||
// Complete form display
|
||||
$data = plugin_version_example();
|
||||
} elseif ($item instanceof Preference) {
|
||||
// Complete form display
|
||||
$data = plugin_version_example();
|
||||
|
||||
echo "<form action='Where to post form'>";
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr><th colspan='3'>" . $data['name'] . ' - ' . $data['version'];
|
||||
echo '</th></tr>';
|
||||
echo "<form action='Where to post form'>";
|
||||
echo "<table class='tab_cadre_fixe'>";
|
||||
echo "<tr><th colspan='3'>" . $data['name'] . ' - ' . $data['version'];
|
||||
echo '</th></tr>';
|
||||
|
||||
echo "<tr class='tab_bg_1'><td>Name of the pref</td>";
|
||||
echo '<td>Input to set the pref</td>';
|
||||
echo "<tr class='tab_bg_1'><td>Name of the pref</td>";
|
||||
echo '<td>Input to set the pref</td>';
|
||||
|
||||
echo "<td><input class='submit' type='submit' name='submit' value='submit'></td>";
|
||||
echo '</tr>';
|
||||
echo "<td><input class='submit' type='submit' name='submit' value='submit'></td>";
|
||||
echo '</tr>';
|
||||
|
||||
echo '</table>';
|
||||
echo '</form>';
|
||||
break;
|
||||
echo '</table>';
|
||||
echo '</form>';
|
||||
|
||||
case 'Notification':
|
||||
echo __('Plugin mailing action', 'example');
|
||||
break;
|
||||
} elseif ($item instanceof Notification) {
|
||||
echo __s('Plugin mailing action', 'example');
|
||||
|
||||
case 'ComputerDisk':
|
||||
case 'Supplier':
|
||||
if ($tabnum == 1) {
|
||||
echo __('First tab of Plugin example', 'example');
|
||||
} else {
|
||||
echo __('Second tab of Plugin example', 'example');
|
||||
}
|
||||
break;
|
||||
} elseif ($item instanceof Item_Disk || $item instanceof Supplier) {
|
||||
if ($tabnum == 1) {
|
||||
echo __s('First tab of Plugin example', 'example');
|
||||
} else {
|
||||
echo __s('Second tab of Plugin example', 'example');
|
||||
}
|
||||
|
||||
default:
|
||||
//TRANS: %1$s is a class name, %2$d is an item ID
|
||||
printf(__('Plugin example CLASS=%1$s id=%2$d', 'example'), $item->getType(), $item->getField('id'));
|
||||
break;
|
||||
} else {
|
||||
//TRANS: %1$s is a class name, %2$d is an item ID
|
||||
printf(__s('Plugin example CLASS=%1$s', 'example'), get_class($item));
|
||||
}
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ class Example extends CommonDBTM
|
||||
$key = $parm['begin'] . '$$$' . 'plugin_example1';
|
||||
$output[$key]['begin'] = date('Y-m-d 17:00:00');
|
||||
$output[$key]['end'] = date('Y-m-d 18:00:00');
|
||||
$output[$key]['name'] = __('test planning example 1', 'example');
|
||||
$output[$key]['name'] = __s('test planning example 1', 'example');
|
||||
// Specify the itemtype to be able to use specific display system
|
||||
$output[$key]['itemtype'] = Example::class;
|
||||
// Set the ID using the ID of the item in the database to have unique ID
|
||||
@@ -337,7 +337,7 @@ class Example extends CommonDBTM
|
||||
* @param $type position of the item in the time block (in, through, begin or end)
|
||||
* @param $complete complete display (more details)
|
||||
*
|
||||
* @return Nothing (display function)
|
||||
* @return void (display function)
|
||||
**/
|
||||
public static function displayPlanningItem(array $val, $who, $type = '', $complete = 0)
|
||||
{
|
||||
@@ -347,7 +347,7 @@ class Example extends CommonDBTM
|
||||
case 'in':
|
||||
//TRANS: %1$s is the start time of a planned item, %2$s is the end
|
||||
printf(
|
||||
__('From %1$s to %2$s :'),
|
||||
__s('From %1$s to %2$s :'),
|
||||
date('H:i', strtotime($val['begin'])),
|
||||
date('H:i', strtotime($val['end'])),
|
||||
);
|
||||
@@ -359,12 +359,12 @@ class Example extends CommonDBTM
|
||||
|
||||
case 'begin':
|
||||
//TRANS: %s is the start time of a planned item
|
||||
printf(__('Start at %s:'), date('H:i', strtotime($val['begin'])));
|
||||
printf(__s('Start at %s:'), date('H:i', strtotime($val['begin'])));
|
||||
break;
|
||||
|
||||
case 'end':
|
||||
//TRANS: %s is the end time of a planned item
|
||||
printf(__('End at %s:'), date('H:i', strtotime($val['end'])));
|
||||
printf(__s('End at %s:'), date('H:i', strtotime($val['end'])));
|
||||
break;
|
||||
}
|
||||
echo '<br>';
|
||||
@@ -384,7 +384,7 @@ class Example extends CommonDBTM
|
||||
{
|
||||
switch ($data['linked_action'] - Log::HISTORY_PLUGIN) {
|
||||
case 0:
|
||||
return __('History from plugin example', 'example');
|
||||
return __s('History from plugin example', 'example');
|
||||
}
|
||||
|
||||
return '';
|
||||
@@ -397,7 +397,7 @@ class Example extends CommonDBTM
|
||||
$actions = parent::getSpecificMassiveActions($checkitem);
|
||||
|
||||
$actions['Document_Item' . MassiveAction::CLASS_ACTION_SEPARATOR . 'add'] = _x('button', 'Add a document'); // GLPI core one
|
||||
$actions[__CLASS__ . MassiveAction::CLASS_ACTION_SEPARATOR . 'do_nothing'] = __('Do Nothing - just for fun', 'example'); // Specific one
|
||||
$actions[self::class . MassiveAction::CLASS_ACTION_SEPARATOR . 'do_nothing'] = __s('Do Nothing - just for fun', 'example'); // Specific one
|
||||
|
||||
return $actions;
|
||||
}
|
||||
@@ -408,12 +408,12 @@ class Example extends CommonDBTM
|
||||
case 'DoIt':
|
||||
echo " <input type='hidden' name='toto' value='1'>" .
|
||||
Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']) .
|
||||
' ' . __('Write in item history', 'example');
|
||||
' ' . __s('Write in item history', 'example');
|
||||
|
||||
return true;
|
||||
case 'do_nothing':
|
||||
echo ' ' . Html::submit(_x('button', 'Post'), ['name' => 'massiveaction']) .
|
||||
' ' . __('but do nothing :)', 'example');
|
||||
' ' . __s('but do nothing :)', 'example');
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -436,8 +436,8 @@ class Example extends CommonDBTM
|
||||
switch ($ma->getAction()) {
|
||||
case 'DoIt':
|
||||
if ($item->getType() == 'Computer') {
|
||||
Session::addMessageAfterRedirect(__('Right it is the type I want...', 'example'));
|
||||
Session::addMessageAfterRedirect(__('Write in item history', 'example'));
|
||||
Session::addMessageAfterRedirect(__s('Right it is the type I want...', 'example'));
|
||||
Session::addMessageAfterRedirect(__s('Write in item history', 'example'));
|
||||
$changes = [0, 'old value', 'new value'];
|
||||
foreach ($ids as $id) {
|
||||
if ($item->getFromDB($id)) {
|
||||
@@ -464,8 +464,8 @@ class Example extends CommonDBTM
|
||||
|
||||
case 'do_nothing':
|
||||
if ($item->getType() == Example::class) {
|
||||
Session::addMessageAfterRedirect(__('Right it is the type I want...', 'example'));
|
||||
Session::addMessageAfterRedirect(__(
|
||||
Session::addMessageAfterRedirect(__s('Right it is the type I want...', 'example'));
|
||||
Session::addMessageAfterRedirect(__s(
|
||||
'But... I say I will do nothing for:',
|
||||
'example',
|
||||
));
|
||||
@@ -487,27 +487,27 @@ class Example extends CommonDBTM
|
||||
parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
|
||||
}
|
||||
|
||||
public static function generateLinkContents($link, CommonDBTM $item)
|
||||
public static function generateLinkContents($link, CommonDBTM $item, bool $safe_url = true)
|
||||
{
|
||||
if (strstr($link, '[EXAMPLE_ID]')) {
|
||||
$link = str_replace('[EXAMPLE_ID]', $item->getID(), $link);
|
||||
$link = str_replace('[EXAMPLE_ID]', (string) $item->getID(), $link);
|
||||
|
||||
return [$link];
|
||||
}
|
||||
|
||||
return parent::generateLinkContents($link, $item);
|
||||
return parent::generateLinkContents($link, $item, $safe_url);
|
||||
}
|
||||
|
||||
public static function dashboardTypes()
|
||||
{
|
||||
return [
|
||||
'example' => [
|
||||
'label' => __('Plugin Example', 'example'),
|
||||
'label' => __s('Plugin Example', 'example'),
|
||||
'function' => Example::class . '::cardWidget',
|
||||
'image' => 'https://via.placeholder.com/100x86?text=example',
|
||||
],
|
||||
'example_static' => [
|
||||
'label' => __('Plugin Example (static)', 'example'),
|
||||
'label' => __s('Plugin Example (static)', 'example'),
|
||||
'function' => Example::class . '::cardWidgetWithoutProvider',
|
||||
'image' => 'https://via.placeholder.com/100x86?text=example+static',
|
||||
],
|
||||
@@ -522,16 +522,16 @@ class Example extends CommonDBTM
|
||||
$new_cards = [
|
||||
'plugin_example_card' => [
|
||||
'widgettype' => ['example'],
|
||||
'label' => __('Plugin Example card'),
|
||||
'label' => __s('Plugin Example card'),
|
||||
'provider' => Example::class . '::cardDataProvider',
|
||||
],
|
||||
'plugin_example_card_without_provider' => [
|
||||
'widgettype' => ['example_static'],
|
||||
'label' => __('Plugin Example card without provider'),
|
||||
'label' => __s('Plugin Example card without provider'),
|
||||
],
|
||||
'plugin_example_card_with_core_widget' => [
|
||||
'widgettype' => ['bigNumber'],
|
||||
'label' => __('Plugin Example card with core provider'),
|
||||
'label' => __s('Plugin Example card with core provider'),
|
||||
'provider' => Example::class . '::cardBigNumberProvider',
|
||||
],
|
||||
];
|
||||
@@ -605,14 +605,8 @@ class Example extends CommonDBTM
|
||||
|
||||
public static function cardBigNumberProvider(array $params = [])
|
||||
{
|
||||
$default_params = [
|
||||
'label' => null,
|
||||
'icon' => null,
|
||||
];
|
||||
$params = array_merge($default_params, $params);
|
||||
|
||||
return [
|
||||
'number' => rand(),
|
||||
'number' => random_int(0, mt_getrandmax()),
|
||||
'url' => 'https://www.linux.org/',
|
||||
'label' => 'plugin example - some text',
|
||||
'icon' => 'fab fa-linux', // font awesome icon
|
||||
|
@@ -38,7 +38,7 @@ class ComputerModelFilter extends AbstractFilter
|
||||
{
|
||||
public static function getName(): string
|
||||
{
|
||||
return __('Computer model');
|
||||
return __s('Computer model');
|
||||
}
|
||||
|
||||
public static function getId(): string
|
||||
@@ -48,6 +48,7 @@ class ComputerModelFilter extends AbstractFilter
|
||||
|
||||
public static function canBeApplied(string $table): bool
|
||||
{
|
||||
/** @var DBmysql $DB */
|
||||
global $DB;
|
||||
|
||||
return $DB->fieldExists($table, ComputerModel::getForeignKeyField());
|
||||
|
@@ -50,9 +50,6 @@ class ItemForm
|
||||
*/
|
||||
public static function preSection($params)
|
||||
{
|
||||
$item = $params['item'];
|
||||
$options = $params['options'];
|
||||
|
||||
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
|
||||
<section class="accordion-item" aria-label="a label">
|
||||
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
|
||||
@@ -81,9 +78,6 @@ TWIG, []);
|
||||
*/
|
||||
public static function postSection($params)
|
||||
{
|
||||
$item = $params['item'];
|
||||
$options = $params['options'];
|
||||
|
||||
echo TemplateRenderer::getInstance()->renderFromStringTemplate(<<<TWIG
|
||||
<section class="accordion-item" aria-label="a label">
|
||||
<h2 class="accordion-header" id="example-heading" title="example-heading-id" data-bs-toggle="tooltip">
|
||||
@@ -119,25 +113,25 @@ TWIG, []);
|
||||
|
||||
$out = '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
||||
$out .= sprintf(
|
||||
__('Start %1$s hook call for %2$s type'),
|
||||
__s('Start %1$s hook call for %2$s type'),
|
||||
'pre_item_form',
|
||||
$item::getType(),
|
||||
);
|
||||
$out .= '</th></tr>';
|
||||
|
||||
$out .= "<tr><$firstelt>";
|
||||
$out .= '<label for="example_pre_form_hook">' . __('First pre form hook') . '</label>';
|
||||
$out .= '<label for="example_pre_form_hook">' . __s('First pre form hook') . '</label>';
|
||||
$out .= "</$firstelt><td>";
|
||||
$out .= '<input type="text" name="example_pre_form_hook" id="example_pre_form_hook"/>';
|
||||
$out .= "</td><$firstelt>";
|
||||
$out .= '<label for="example_pre_form_hook2">' . __('Second pre form hook') . '</label>';
|
||||
$out .= '<label for="example_pre_form_hook2">' . __s('Second pre form hook') . '</label>';
|
||||
$out .= "</$firstelt><td>";
|
||||
$out .= '<input type="text" name="example_pre_form_hook2" id="example_pre_form_hook2"/>';
|
||||
$out .= '</td></tr>';
|
||||
|
||||
$out .= '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
||||
$out .= sprintf(
|
||||
__('End %1$s hook call for %2$s type'),
|
||||
__s('End %1$s hook call for %2$s type'),
|
||||
'pre_item_form',
|
||||
$item::getType(),
|
||||
);
|
||||
@@ -162,25 +156,25 @@ TWIG, []);
|
||||
|
||||
$out = '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
||||
$out .= sprintf(
|
||||
__('Start %1$s hook call for %2$s type'),
|
||||
__s('Start %1$s hook call for %2$s type'),
|
||||
'post_item_form',
|
||||
$item::getType(),
|
||||
);
|
||||
$out .= '</th></tr>';
|
||||
|
||||
$out .= "<tr><$firstelt>";
|
||||
$out .= '<label for="example_post_form_hook">' . __('First post form hook') . '</label>';
|
||||
$out .= '<label for="example_post_form_hook">' . __s('First post form hook') . '</label>';
|
||||
$out .= "</$firstelt><td>";
|
||||
$out .= '<input type="text" name="example_post_form_hook" id="example_post_form_hook"/>';
|
||||
$out .= "</td><$firstelt>";
|
||||
$out .= '<label for="example_post_form_hook2">' . __('Second post form hook') . '</label>';
|
||||
$out .= '<label for="example_post_form_hook2">' . __s('Second post form hook') . '</label>';
|
||||
$out .= "</$firstelt><td>";
|
||||
$out .= '<input type="text" name="example_post_form_hook2" id="example_post_form_hook2"/>';
|
||||
$out .= '</td></tr>';
|
||||
|
||||
$out .= '<tr><th colspan="' . (isset($options['colspan']) ? $options['colspan'] * 2 : '4') . '">';
|
||||
$out .= sprintf(
|
||||
__('End %1$s hook call for %2$s type'),
|
||||
__s('End %1$s hook call for %2$s type'),
|
||||
'post_item_form',
|
||||
$item::getType(),
|
||||
);
|
||||
@@ -209,7 +203,7 @@ JAVASCRIPT;
|
||||
|
||||
echo "<li class='followup' id='email_transfer_$rand'>
|
||||
<i class='far fa-envelope'></i>" .
|
||||
__('Send a notification') .
|
||||
__s('Send a notification') .
|
||||
Html::scriptBlock($JS) . '
|
||||
</li>';
|
||||
}
|
||||
|
@@ -40,10 +40,6 @@ namespace GlpiPlugin\Example;
|
||||
use GlpiPlugin\Example\DeviceCamera;
|
||||
use Item_Devices;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die("Sorry. You can't access directly to this file");
|
||||
}
|
||||
|
||||
/**
|
||||
* Relation between item and devices
|
||||
**/
|
||||
|
@@ -32,10 +32,6 @@ namespace GlpiPlugin\Example;
|
||||
|
||||
use NotificationTarget;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die("Sorry. You can't access directly to this file");
|
||||
}
|
||||
|
||||
// Class NotificationTarget
|
||||
class NotificationTargetExample extends NotificationTarget
|
||||
{
|
||||
@@ -46,8 +42,6 @@ class NotificationTargetExample extends NotificationTarget
|
||||
|
||||
public function addDataForTemplate($event, $options = [])
|
||||
{
|
||||
global $DB, $CFG_GLPI;
|
||||
|
||||
$this->data['##example.name##'] = __('Example', 'example');
|
||||
$this->data['##example.name##'] = __s('Example', 'example');
|
||||
}
|
||||
}
|
||||
|
@@ -34,17 +34,27 @@ use CommonGLPI;
|
||||
use Html;
|
||||
use Session;
|
||||
|
||||
final class Profile extends \Profile
|
||||
class Profile extends \Profile
|
||||
{
|
||||
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
|
||||
{
|
||||
return __('Example plugin');
|
||||
if (
|
||||
$item instanceof \Profile
|
||||
&& $item->getField('id')
|
||||
) {
|
||||
return self::createTabEntry(__s('Example plugin'));
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
|
||||
{
|
||||
$profile = new self();
|
||||
$profile->showFormExample($item->getID());
|
||||
if ($item instanceof self) {
|
||||
$profile = new self();
|
||||
$profile->showFormExample($item->getID());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function showFormExample(int $profiles_id): void
|
||||
|
@@ -37,11 +37,6 @@ namespace GlpiPlugin\Example;
|
||||
|
||||
use Rule;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die("Sorry. You can't access directly to this file");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rule class store all informations about a GLPI rule :
|
||||
* - description
|
||||
@@ -69,7 +64,7 @@ class RuleTest extends Rule
|
||||
{
|
||||
$criterias = [];
|
||||
$criterias['name']['field'] = 'name';
|
||||
$criterias['name']['name'] = __('Software');
|
||||
$criterias['name']['name'] = __s('Software');
|
||||
$criterias['name']['table'] = 'glpi_softwares';
|
||||
|
||||
return $criterias;
|
||||
@@ -78,7 +73,7 @@ class RuleTest extends Rule
|
||||
public function getActions()
|
||||
{
|
||||
$actions = [];
|
||||
$actions['softwarecategories_id']['name'] = __('Category (class)', 'example');
|
||||
$actions['softwarecategories_id']['name'] = __s('Category (class)', 'example');
|
||||
$actions['softwarecategories_id']['type'] = 'dropdown';
|
||||
$actions['softwarecategories_id']['table'] = 'glpi_softwarecategories';
|
||||
|
||||
|
@@ -37,11 +37,6 @@ namespace GlpiPlugin\Example;
|
||||
|
||||
use RuleCollection;
|
||||
|
||||
if (!defined('GLPI_ROOT')) {
|
||||
die("Sorry. You can't access directly to this file");
|
||||
}
|
||||
|
||||
|
||||
class RuleTestCollection extends RuleCollection
|
||||
{
|
||||
// From RuleCollection
|
||||
|
@@ -68,14 +68,15 @@ class Showtabitem
|
||||
{
|
||||
switch ($params['item']->getType()) {
|
||||
case 'Ticket':
|
||||
if ($params['options']['itemtype'] == 'TicketValidation' && $params['options']['tabnum'] == 2) {
|
||||
// if tasks are not all done
|
||||
// then prevent solution div to show
|
||||
// this is an example to prevent solving of ticket
|
||||
if (true) { // here you should test if some tasks are in todo status.
|
||||
$params['options']['prevent_solution'] = true; // this will be passed to the post_show hook
|
||||
echo "<div id='toHideSolution' style='display: none;'>"; // in order to hide the default solution div
|
||||
}
|
||||
// if tasks are not all done
|
||||
// then prevent solution div to show
|
||||
// this is an example to prevent solving of ticket
|
||||
if ($params['options']['itemtype'] == 'TicketValidation' && $params['options']['tabnum'] == 2 && true) {
|
||||
// here you should test if some tasks are in todo status.
|
||||
$params['options']['prevent_solution'] = true;
|
||||
// this will be passed to the post_show hook
|
||||
echo "<div id='toHideSolution' style='display: none;'>";
|
||||
// in order to hide the default solution div
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user