Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing barcode in core #17898

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"symfony/property-access": "^7.1",
"symfony/routing": "^6.4",
"symfony/serializer": "^7.1",
"tecnickcom/tc-lib-barcode": "^2.3",
"tecnickcom/tcpdf": "^6.7",
"thenetworg/oauth2-azure": "^2.2",
"twig/markdown-extra": "^3.13",
Expand Down
171 changes: 170 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions src/Barcode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
MyvTsv marked this conversation as resolved.
Show resolved Hide resolved

/**
* ---------------------------------------------------------------------
*
* GLPI - Gestionnaire Libre de Parc Informatique
*
* http://glpi-project.org
*
* @copyright 2015-2024 Teclib' and contributors.
* @copyright 2003-2014 by the INDEPNET Development Team.
* @licence https://www.gnu.org/licenses/gpl-3.0.html
*
* ---------------------------------------------------------------------
*
* LICENSE
*
* This file is part of GLPI.
*
* 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
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* ---------------------------------------------------------------------
*/

class Barcode extends CommonDropdown
{
public static function generateQRCode(CommonDBTM $item)
{
global $CFG_GLPI;
if ( $item->getId() === -1) {
return false;
}
$barcode = new \Com\Tecnick\Barcode\Barcode();
$qrcode = $barcode->getBarcodeObj(
'QRCODE,H',
$CFG_GLPI["url_base"] . $item->getLinkURL(),
-2,
-2,
'black',
array(-2, -2, -2, -2)
)->setBackgroundColor('white');
return $qrcode;
}

public static function renderQRCode(CommonDBTM $item)
{
global $CFG_GLPI;
if (in_array($item::class, $CFG_GLPI["asset_types"])) {
$qrcode = self::generateQRCode($item);
if ($qrcode) {
return $qrcode->getHtmlDiv();
}
}
return false;
}
}
1 change: 1 addition & 0 deletions src/CommonDBTM.php
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,7 @@ public function showForm($ID, array $options = [])
'params' => $options,
'no_header' => !$new_item && !$in_modal,
'cluster' => $cluster,
'barcode' => Barcode::renderQRCode($this)
]);
return true;
}
Expand Down
11 changes: 11 additions & 0 deletions templates/generic_show_form.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,17 @@
{{ fields.htmlField('last_boot', item.fields['last_boot']|formatted_datetime(true), __('Last boot date')) }}
{% endif %}

{% if barcode %}
{{ fields.htmlField(
'qrcode',
barcode,
__('Asset URL'),
{
'helper': __('Scan this QRCode to be redirected to the asset page from your mobile device')
})
}}
{% endif %}

{% block more_fields %}
{% endblock %}
{% endblock %}
Expand Down
Loading