Skip to content

Commit

Permalink
feat: Add config for add task description
Browse files Browse the repository at this point in the history
Feature/task description cost
  • Loading branch information
xacobofg committed May 19, 2020
2 parents 0fa7e22 + ed27518 commit 4cf19f2
Show file tree
Hide file tree
Showing 11 changed files with 388 additions and 2 deletions.
19 changes: 19 additions & 0 deletions front/config.form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
include ( "../../../inc/includes.php");

$config = new PluginCostsConfig();
if (isset($_POST["update"])) {
$config->check($_POST['id'], UPDATE);

// save
$config->update($_POST);


Html::back();

} else if (isset($_POST["refresh"])) {
$config->refresh($_POST); // used to refresh process list, task category list
Html::back();
}

Html::redirect($CFG_GLPI["root_doc"]."/front/config.form.php?forcetab=".urlencode('PluginCostsConfig$1'));
138 changes: 138 additions & 0 deletions inc/config.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
<?php

if(!defined('GLPI_ROOT')){
die("Sorry. You can't access directly to this file");
}

class PluginCostsConfig extends CommonDBTM {
static private $_instance = null;

public function __construct() {
global $DB;
if ($DB->tableExists(self::getTable())) {
$this->getFromDB(1);
}
}
/**
* Summary of canCreate
* @return boolean
*/
static function canCreate() {
return Session::haveRight('config', UPDATE);
}

/**
* Summary of canView
* @return boolean
*/
static function canView() {
return Session::haveRight('config', READ);
}

/**
* Summary of canUpdate
* @return boolean
*/
static function canUpdate() {
return Session::haveRight('config', UPDATE);
}

/**
* Summary of getTypeName
* @param mixed $nb plural
* @return mixed
*/
static function getTypeName($nb = 0) {
return __("Costs", "costs");
}

/**
* Summary of getInstance
* @return PluginProcessmakerConfig
*/
static function getInstance() {

if (!isset(self::$_instance)) {
self::$_instance = new self();
if (!self::$_instance->getFromDB(1)) {
self::$_instance->getEmpty();
}
}
return self::$_instance;
}

public static function getConfig($update = false) {
static $config = null;
if (is_null($config)) {
$config = new self();
}
if ($update) {
$config->getFromDB(1);
}
return $config;
}

/**
* Summary of showConfigForm
* @param mixed $item is the config
* @return boolean
*/
static function showConfigForm() {
global $CFG_GLPI;

$config = new self();
$config->getFromDB(1);

$config->showFormHeader(['colspan' => 4]);

echo "<tr class='tab_bg_1'>";
echo "<td >".__("Add task description on cost", "cost")."</td><td >";
Dropdown::showYesNo("taskdescription", $config->fields["taskdescription"]);
echo "</td></tr>\n";

$config->showFormButtons(['candel'=>false]);

return false;
}

function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
global $LANG;

if ($item->getType()=='Config') {
return __("Costs", "costs");
}
return '';
}

static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {

if ($item->getType()=='Config') {
self::showConfigForm($item);
}
return true;
}

public static function install(Migration $migration) {
global $DB;

$table = self::getTable();
$config = new self();

if (!$DB->tableExists($table)) {
$migration->displayMessage("Installing $table");
//Install

$query = "CREATE TABLE `$table` (
`id` int(11) NOT NULL auto_increment,
`taskdescription` tinyint(1) NOT NULL default '0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";

$DB->query($query) or die ($DB->error());
$config->add([
'id' => 1,
'taskdescription' => 0,
]);
}
}
}
9 changes: 8 additions & 1 deletion inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ static function generateCosts($item) {
'begin',
'end',
'actiontime',
'content',
],
'FROM'=>'glpi_tickettasks',
'WHERE'=>[
Expand All @@ -110,6 +111,7 @@ static function generateCosts($item) {
'begin',
'end',
'actiontime',
'content',
],
'FROM'=>'glpi_tickettasks',
'WHERE'=>[
Expand All @@ -119,11 +121,16 @@ static function generateCosts($item) {
}

foreach ($DB->request($query) as $id => $row) {
$config=PluginCostsConfig::getConfig();
$comment=__('Automatically generated by GLPI').' -> Costs Plugin';
if ($config->fields['taskdescription']) {
$comment=$row['content']." \n".__('Automatically generated by GLPI').' -> Costs Plugin';
}
$DB->insert(
'glpi_ticketcosts', [
'tickets_id'=>$ticket_id,
'name'=>$row['id']."_".$row['users_id_tech'],
'comment'=>__('Automatically generated by GLPI').' -> Costs Plugin',
'comment'=>$comment,
'begin_date'=>$row['begin'],
'end_date'=>$row['end'],
'actiontime'=>$row['actiontime'],
Expand Down
27 changes: 27 additions & 0 deletions locales/costs.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Cost Glpi Plugin.
# Copyright (C) 2020 TICgal
# This file is distributed under the same license as the PACKAGE package.
# TICgal, 2020
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-05-08 14:32+0200\n"
"PO-Revision-Date: 2020-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: inc/config.class.php:46 inc/config.class.php:102 inc/entity.class.php:46
#: inc/ticket.class.php:41
msgid "Costs"
msgstr ""

#: inc/config.class.php:89
msgid "Add task description on cost"
msgstr ""
Binary file added locales/en_GB.mo
Binary file not shown.
28 changes: 28 additions & 0 deletions locales/en_GB.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Cost Glpi Plugin.
# Copyright (C) 2020 TICgal
# This file is distributed under the same license as the PACKAGE package.
# TICgal, 2020
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-05-08 14:32+0200\n"
"PO-Revision-Date: 2020-05-08 14:33+0200\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.6\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: en_GB\n"

#: inc/config.class.php:46 inc/config.class.php:102 inc/entity.class.php:46
#: inc/ticket.class.php:41
msgid "Costs"
msgstr "Costs"

#: inc/config.class.php:89
msgid "Add task description on cost"
msgstr "Add task description on cost"
Binary file added locales/es_ES.mo
Binary file not shown.
28 changes: 28 additions & 0 deletions locales/es_ES.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Cost Glpi Plugin.
# Copyright (C) 2020 TICgal
# This file is distributed under the same license as the PACKAGE package.
# TICgal, 2020
#
msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-05-08 14:32+0200\n"
"PO-Revision-Date: 2020-05-08 14:34+0200\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"X-Generator: Poedit 2.0.6\n"
"Last-Translator: \n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
"Language: es_ES\n"

#: inc/config.class.php:46 inc/config.class.php:102 inc/entity.class.php:46
#: inc/ticket.class.php:41
msgid "Costs"
msgstr "Costes"

#: inc/config.class.php:89
msgid "Add task description on cost"
msgstr "Añadir la descripción de la tarea en el coste"
6 changes: 5 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@link https://tic.gal
@since 2018
---------------------------------------------------------------------- */
define ('PLUGIN_COSTS_VERSION', '1.1.0');
define ('PLUGIN_COSTS_VERSION', '1.2.0');
// Minimal GLPI version, inclusive
define("PLUGIN_COSTS_MIN_GLPI", "9.3.0");
// Maximum GLPI version, exclusive
Expand Down Expand Up @@ -94,6 +94,10 @@ function plugin_init_costs() {
if (Session::haveRight('entity', UPDATE)) {
Plugin::registerClass('PluginCostsEntity', ['addtabon' => 'Entity']);
}
if (Session::haveRightsOr("config", [READ, UPDATE])) {
Plugin::registerClass('PluginCostsConfig', ['addtabon' => 'Config']);
$PLUGIN_HOOKS['config_page']['costs'] = 'front/config.form.php';
}

$PLUGIN_HOOKS['csrf_compliant']['costs'] = true;
$PLUGIN_HOOKS['pre_item_update']['costs'] = ['Ticket' => ['PluginCostsTicket','generateCosts']];
Expand Down
19 changes: 19 additions & 0 deletions tools/generate_locales.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

CUR_PATH="`dirname \"$0\"`"

cd "$CUR_PATH/.."

xgettext *.php */*.php -o locales/costs.pot -L PHP --add-comments=TRANS --from-code=UTF-8 --force-po -k --keyword=__:1,2t --keyword=_x:1,2,3t --keyword=__s:1,2t --keyword=_sx:1,2,3t --keyword=_n:1,2,3,4t --keyword=_sn:1,2t --keyword=_nx:1,2,3t --copyright-holder "TICgal"

cd locales

sed -i "s/SOME DESCRIPTIVE TITLE/Cost Glpi Plugin/" costs.pot
sed -i "s/FIRST AUTHOR <EMAIL@ADDRESS>, YEAR./TICgal, $(date +%Y)/" costs.pot
sed -i "s/YEAR/$(date +%Y)/" costs.pot

for a in $(ls *.po); do
msgmerge -U $a costs.pot
msgfmt $a -o "${a%.*}.mo"
done
rm -f *.po~
Loading

0 comments on commit 4cf19f2

Please sign in to comment.