Skip to content

Commit 4ae2a92

Browse files
committed
feat(targetproblem): target problem
1 parent 58a9b04 commit 4ae2a92

9 files changed

+115
-74
lines changed

inc/abstracttarget.class.php

+26
Original file line numberDiff line numberDiff line change
@@ -2473,4 +2473,30 @@ public function getDefaultData(PluginFormcreatorFormAnswer $formanswer): array {
24732473
$data = array_merge($data, $predefined_fields);
24742474
return $data;
24752475
}
2476+
2477+
/**
2478+
* get all target problems for a form
2479+
*
2480+
* @param int $formId
2481+
* @return array
2482+
*/
2483+
public function getTargetsForForm($formId) {
2484+
global $DB;
2485+
2486+
$targets = [];
2487+
$rows = $DB->request([
2488+
'SELECT' => ['id'],
2489+
'FROM' => static::getTable(),
2490+
'WHERE' => [
2491+
'plugin_formcreator_forms_id' => $formId
2492+
],
2493+
]);
2494+
foreach ($rows as $row) {
2495+
$target = new static();
2496+
$target->getFromDB($row['id']);
2497+
$targets[$row['id']] = $target;
2498+
}
2499+
2500+
return $targets;
2501+
}
24762502
}

inc/form.class.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -2238,7 +2238,8 @@ public function getFields() : array {
22382238
public static function getTargetTypes() : array {
22392239
return [
22402240
PluginFormcreatorTargetTicket::class,
2241-
PluginFormcreatorTargetChange::class
2241+
PluginFormcreatorTargetChange::class,
2242+
PluginFormcreatorTargetProblem::class,
22422243
];
22432244
}
22442245

inc/targetchange.class.php

-26
Original file line numberDiff line numberDiff line change
@@ -901,30 +901,4 @@ public function save(PluginFormcreatorFormAnswer $formanswer) {
901901

902902
return $change;
903903
}
904-
905-
/**
906-
* get all target changes for a form
907-
*
908-
* @param int $formId
909-
* @return array
910-
*/
911-
public function getTargetsForForm($formId) {
912-
global $DB;
913-
914-
$targets = [];
915-
$rows = $DB->request([
916-
'SELECT' => ['id'],
917-
'FROM' => self::getTable(),
918-
'WHERE' => [
919-
'plugin_formcreator_forms_id' => $formId
920-
],
921-
]);
922-
foreach ($rows as $row) {
923-
$target = new self();
924-
$target->getFromDB($row['id']);
925-
$targets[$row['id']] = $target;
926-
}
927-
928-
return $targets;
929-
}
930904
}

inc/targetticket.class.php

-26
Original file line numberDiff line numberDiff line change
@@ -1543,30 +1543,4 @@ private function saveAssociatedItems($input) {
15431543
unset($input['items_id']);
15441544
return $input;
15451545
}
1546-
1547-
/**
1548-
* get all target tickets for a form
1549-
*
1550-
* @param int $formId
1551-
* @return array
1552-
*/
1553-
public function getTargetsForForm($formId) {
1554-
global $DB;
1555-
1556-
$targets = [];
1557-
$rows = $DB->request([
1558-
'SELECT' => ['id'],
1559-
'FROM' => self::getTable(),
1560-
'WHERE' => [
1561-
'plugin_formcreator_forms_id' => $formId
1562-
],
1563-
]);
1564-
foreach ($rows as $row) {
1565-
$target = new self();
1566-
$target->getFromDB($row['id']);
1567-
$targets[$row['id']] = $target;
1568-
}
1569-
1570-
return $targets;
1571-
}
15721546
}

install/mysql/plugin_formcreator_empty.sql

+25
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,31 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targettickets` (
217217
INDEX `tickettemplates_id` (`tickettemplates_id`)
218218
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
219219

220+
CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targetproblems` (
221+
`id` int(11) NOT NULL AUTO_INCREMENT,
222+
`name` varchar(255) NOT NULL DEFAULT '',
223+
`plugin_formcreator_forms_id` int(11) NOT NULL DEFAULT '0',
224+
`target_name` varchar(255) NOT NULL DEFAULT '',
225+
`problemtemplates_id` int(11) NOT NULL DEFAULT '0',
226+
`content` longtext,
227+
`impactcontent` longtext,
228+
`causecontent` longtext,
229+
`symptomcontent` longtext,
230+
`urgency_rule` int(11) NOT NULL DEFAULT '1',
231+
`urgency_question` int(11) NOT NULL DEFAULT '0',
232+
`destination_entity` int(11) NOT NULL DEFAULT '1',
233+
`destination_entity_value` int(11) DEFAULT NULL,
234+
`tag_type` int(11) NOT NULL DEFAULT '1',
235+
`tag_questions` varchar(255) NOT NULL,
236+
`tag_specifics` varchar(255) NOT NULL,
237+
`category_rule` int(11) NOT NULL DEFAULT '1',
238+
`category_question` int(11) NOT NULL DEFAULT '0',
239+
`show_rule` int(11) NOT NULL DEFAULT '1',
240+
`uuid` varchar(255) DEFAULT NULL,
241+
PRIMARY KEY (`id`),
242+
INDEX `problemtemplates_id` (`problemtemplates_id`)
243+
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
244+
220245
CREATE TABLE IF NOT EXISTS `glpi_plugin_formcreator_targets_actors` (
221246
`id` int(11) NOT NULL AUTO_INCREMENT,
222247
`itemtype` varchar(255) DEFAULT NULL,

tests/2-integration/PluginFormcreatorIssue.php

+29-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,24 @@
3333

3434
class PluginFormcreatorIssue extends CommonTestCase {
3535

36+
public function beforeTestMethod($method) {
37+
switch ($method) {
38+
case 'testAddTicket':
39+
case 'testUpdateTicket':
40+
$this->login('post-only', 'postonly');
41+
break;
42+
43+
case 'testDeleteTicket':
44+
$this->login('glpi', 'glpi');
45+
break;
46+
}
47+
}
48+
3649
public function testAddTicket() {
37-
$this->login('post-only', 'postonly');
50+
global $CFG_GLPI;
51+
52+
$CFG_GLPI['use_notifications'] = '0';
53+
3854
// Create a form with a target ticket
3955
$form = $this->getForm();
4056
$this->getTargetTicket([
@@ -43,7 +59,10 @@ public function testAddTicket() {
4359

4460
// answer the form
4561
$formAnswer = new \PluginFormcreatorFormAnswer();
46-
$formAnswer->add([\PluginFormcreatorForm::getForeignKeyField() => $form->getID()]);
62+
$formAnswer->add([
63+
\PluginFormcreatorForm::getForeignKeyField() => $form->getID()
64+
]);
65+
4766
// Get the generated ticket
4867
$ticket = array_pop($formAnswer->targetList);
4968
$this->object($ticket);
@@ -63,7 +82,10 @@ public function testAddTicket() {
6382
}
6483

6584
public function testUpdateTicket() {
66-
$this->login('post-only', 'postonly');
85+
global $CFG_GLPI;
86+
87+
$CFG_GLPI['use_notifications'] = '0';
88+
6789
// Create a form with a target ticket
6890
$form = $this->getForm();
6991
$this->getTargetTicket([
@@ -104,7 +126,10 @@ public function testUpdateTicket() {
104126
}
105127

106128
public function testDeleteTicket() {
107-
$this->login('glpi', 'glpi');
129+
global $CFG_GLPI;
130+
131+
$CFG_GLPI['use_notifications'] = '0';
132+
108133
$form = $this->getForm();
109134
$this->getTargetTicket([
110135
\PluginFormcreatorForm::getForeignKeyField() => $form->getID(),

tests/2-integration/PluginFormcreatorTargetChange.php

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,30 +44,30 @@ public function testTargetChangeActors() {
4444
// Create a form with a target change
4545
$form = $this->getForm();
4646

47-
$targetChange = new \PluginFormcreatorTargetChange();
48-
$targetChange->add([
47+
$instance = new \PluginFormcreatorTargetChange();
48+
$instance->add([
4949
'name' => 'a target',
5050
'plugin_formcreator_forms_id' => $form->getID()
5151
]);
52-
$this->boolean($targetChange->isNewItem())->isFalse();
52+
$this->boolean($instance->isNewItem())->isFalse();
5353

5454
$requesterActor = new \PluginFormcreatorTarget_Actor();
5555
$observerActor = new \PluginFormcreatorTarget_Actor();
56-
$targetChangeId = $targetChange->getID();
56+
$instanceId = $instance->getID();
5757

5858
// find the actors created by default
5959
$requesterActor->getFromDBByCrit([
6060
'AND' => [
61-
'itemtype' => $targetChange->getType(),
62-
'items_id' => $targetChangeId,
61+
'itemtype' => $instance->getType(),
62+
'items_id' => $instanceId,
6363
'actor_role' => \PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER,
6464
'actor_type' => \PluginFormcreatorTarget_Actor::ACTOR_TYPE_AUTHOR,
6565
]
6666
]);
6767
$observerActor->getFromDBByCrit([
6868
'AND' => [
69-
'itemtype' => $targetChange->getType(),
70-
'items_id' => $targetChangeId,
69+
'itemtype' => $instance->getType(),
70+
'items_id' => $instanceId,
7171
'actor_role' => \PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER,
7272
'actor_type' => \PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR
7373
]

tests/2-integration/PluginFormcreatorTargetTicket.php

+9-9
Original file line numberDiff line numberDiff line change
@@ -46,31 +46,31 @@ public function testTargetTicketActors() {
4646
// Create a form with a target ticket
4747
$form = $this->getForm();
4848

49-
$targetTicket = new \PluginFormcreatorTargetTicket();
50-
$targetTicket->add([
49+
$instance = new \PluginFormcreatorTargetTicket();
50+
$instance->add([
5151
'name' => 'a target',
5252
'plugin_formcreator_forms_id' => $form->getID()
5353
]);
54-
$targetTicket->getFromDB($targetTicket->getID());
55-
$this->boolean($targetTicket->isNewItem())->isFalse();
54+
$instance->getFromDB($instance->getID());
55+
$this->boolean($instance->isNewItem())->isFalse();
5656

5757
// find the actors created by default
5858
$requesterActor = new \PluginFormcreatorTarget_Actor();
5959
$observerActor = new \PluginFormcreatorTarget_Actor();
60-
$targetTicketId = $targetTicket->getID();
60+
$instanceId = $instance->getID();
6161

6262
$requesterActor->getFromDBByCrit([
6363
'AND' => [
64-
'itemtype' => $targetTicket->getType(),
65-
'items_id' => $targetTicketId,
64+
'itemtype' => $instance->getType(),
65+
'items_id' => $instanceId,
6666
'actor_role' => \PluginFormcreatorTarget_Actor::ACTOR_ROLE_REQUESTER,
6767
'actor_type' => \PluginFormcreatorTarget_Actor::ACTOR_TYPE_AUTHOR,
6868
]
6969
]);
7070
$observerActor->getFromDBByCrit([
7171
'AND' => [
72-
'itemtype' => $targetTicket->getType(),
73-
'items_id' => $targetTicketId,
72+
'itemtype' => $instance->getType(),
73+
'items_id' => $instanceId,
7474
'actor_role' => \PluginFormcreatorTarget_Actor::ACTOR_ROLE_OBSERVER,
7575
'actor_type' => \PluginFormcreatorTarget_Actor::ACTOR_TYPE_VALIDATOR
7676
]

tests/src/CommonTestCase.php

+16
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,22 @@ protected function getFormAnswer(array $input): ?\PluginFormcreatorFormAnswer {
294294
return $formAnswer;
295295
}
296296

297+
protected function getTargetProblem($input = []) {
298+
if (!isset($input['name'])) {
299+
$input['name'] = $this->getUniqueString();
300+
}
301+
302+
$formFk = \PluginFormcreatorForm::getForeignKeyField();
303+
if (!isset($input[$formFk])) {
304+
$input[$formFk] = $this->getForm()->getID();
305+
}
306+
307+
$targetProblem = new \PluginFormcreatorTargetProblem();
308+
$targetProblem->add($input);
309+
310+
return $targetProblem;
311+
}
312+
297313
/**
298314
* Tests the session has a specific message
299315
* this may be replaced by a custom asserter for atoum

0 commit comments

Comments
 (0)