Custom Plugin champs perso

MantisBT forum for users who prefer to ask and answer questions in French.

Moderators: Developer, Contributor

Post Reply
r3z3
Posts: 4
Joined: 23 Jun 2012, 13:36

Custom Plugin champs perso

Post by r3z3 »

Hello,
J'avais besoin d'adapter Mantis Bug Tracker pour gérer des risques.
Avec l'aide de l'IA, j'ai réussi à faire fonctionner ce plugin que j'ai ajouté à ma version 2.23.0

Si ça peut vous aider aussi, c'est avec plaisir !
PS : dans mon cas, ajout de 3 champs perso : Impact, Proba et Score. Le plugin multiplie l'Impact par la Proba et alimente le champ perso Score avec le résultat.

<?php
class CustomFieldMultiplierPlugin extends MantisPlugin {

private $field1_name = 'Impact';
private $field2_name = 'Proba';
private $result_field_name = 'Score';

function register() {
$this->name = 'Custom Fields Multiply';
$this->description = 'Multiplies two custom fields and stores the result in another custom field upon bug creation or update';
$this->version = '1.0';
$this->requires = array(
'MantisCore' => '2.23.0',
);
$this->author = 'Your Name';
$this->contact = 'your.email@example.com';
$this->url = 'http://example.com';
}

function hooks() {
return array(
'EVENT_REPORT_BUG' => 'update_custom_fields',
'EVENT_UPDATE_BUG' => 'update_custom_fields',
);
}

function update_custom_fields($p_event, $p_bug_data) {
$field1_id = custom_field_get_id_from_name($this->field1_name);
$field2_id = custom_field_get_id_from_name($this->field2_name);
$result_field_id = custom_field_get_id_from_name($this->result_field_name);

if ($field1_id && $field2_id && $result_field_id) {
$field1_value = custom_field_get_value($field1_id, $p_bug_data->id);
$field2_value = custom_field_get_value($field2_id, $p_bug_data->id);

if (is_numeric($field1_value) && is_numeric($field2_value)) {
$result_value = $field1_value * $field2_value;
custom_field_set_value($result_field_id, $p_bug_data->id, $result_value);
}
}
}
}


?>
EricBan
Posts: 1
Joined: 02 Aug 2024, 10:48

Re: Custom Plugin champs perso

Post by EricBan »

Bonjour Mr,

Svp vous pouvez me guider sur l'installation de mantis bu tracker en local.
Merci d'avance.
Email: ericmoffo@outlook.com
Cordialement
Post Reply