Skip to content

Commit 666d3a9

Browse files
authored
Merge pull request #13 from creecros/remove_req
Remove requirement
2 parents bb41252 + f6b8d2c commit 666d3a9

File tree

3 files changed

+121
-7
lines changed

3 files changed

+121
-7
lines changed

Action/AutoCreateSubtaskVanilla.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
namespace Kanboard\Plugin\AutoSubtasks\Action;
4+
5+
use Kanboard\Model\TaskModel;
6+
use Kanboard\Action\Base;
7+
8+
class AutoCreateSubtaskVanilla extends Base
9+
{
10+
11+
public function getDescription()
12+
{
13+
return t('Create one or more Subtasks Automatically');
14+
}
15+
16+
public function getCompatibleEvents()
17+
{
18+
19+
return array(
20+
TaskModel::EVENT_CREATE,
21+
TaskModel::EVENT_MOVE_COLUMN,
22+
);
23+
}
24+
25+
public function getActionRequiredParameters()
26+
{
27+
//changed 'titles' to 'multitasktitles' to have a clean way to render the title-textfield as a textarea
28+
return array(
29+
'column_id' => t('Column'),
30+
'user_id' => t('Assignee'),
31+
'multitasktitles' => t('Subtask Title(s)'),
32+
'time_estimated' => t('Estimated Time in Hours'),
33+
'check_box' => t('Apply to all Columns'),
34+
);
35+
}
36+
37+
public function getEventRequiredParameters()
38+
{
39+
return array(
40+
'task_id',
41+
'task' => array(
42+
'project_id',
43+
'column_id',
44+
'title',
45+
),
46+
);
47+
}
48+
49+
public function doAction(array $data)
50+
{
51+
//get the value of 'multitasktitles' in stead of the original 'titles'
52+
$title_test = $this->getParam('multitasktitles');
53+
$title_test = preg_replace("/^\s+/m", $data['task']['title'] . "\r\n", $title_test);
54+
55+
$values = array(
56+
'title' => $title_test,
57+
'task_id' => $data['task_id'],
58+
'user_id' => $this->getParam('user_id'),
59+
'time_estimated' => $this->getParam('time_estimated'),
60+
'time_spent' => 0,
61+
'status' => 0,
62+
);
63+
64+
$subtasks = explode("\r\n", isset($values['title']) ? $values['title'] : '');
65+
$subtasksAdded = 0;
66+
67+
foreach ($subtasks as $subtask) {
68+
$subtask = trim($subtask);
69+
70+
if (! empty($subtask)) {
71+
$subtaskValues = $values;
72+
$subtaskValues['title'] = $subtask;
73+
74+
list($valid, $errors) = $this->subtaskValidator->validateCreation($subtaskValues);
75+
76+
if (! $valid) {
77+
$this->create($values, $errors);
78+
return false;
79+
}
80+
81+
if (! $this->subtaskModel->create($subtaskValues)) {
82+
$this->flash->failure(t('Unable to create your sub-task.'));
83+
$this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('project_id' => $task['project_id'], 'task_id' => $task['id']), 'subtasks'), true);
84+
return false;
85+
}
86+
87+
$subtasksAdded++;
88+
}
89+
}
90+
//restore the messaging with a flash but this message doesn't seem to appear in the flash area. Only the create message from (kanboard/app/Controller/ActionCreationController.php).
91+
if ($subtasksAdded > 0) {
92+
if ($subtasksAdded === 1) {
93+
$this->flash->success(t('Subtask added successfully.'));
94+
} else {
95+
$this->flash->success(t('%d subtasks added successfully.', $subtasksAdded));
96+
}
97+
}
98+
}
99+
100+
public function hasRequiredCondition(array $data)
101+
{
102+
103+
if ($this->getParam('check_box')) {
104+
return $data['task']['column_id'] == $data['task']['column_id'];
105+
} else {
106+
return $data['task']['column_id'] == $this->getParam('column_id');
107+
}
108+
}
109+
}

Plugin.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
use Kanboard\Core\Plugin\Base;
88
use Kanboard\Plugin\AutoSubtasks\Action\AutoCreateSubtask;
9-
9+
use Kanboard\Plugin\AutoSubtasks\Action\AutoCreateSubtaskVanilla;
1010

1111
class Plugin extends Base
1212

@@ -15,7 +15,13 @@ public function initialize()
1515

1616
{
1717
$this->template->setTemplateOverride('action_creation/params', 'autoSubtasks:action_creation/params');
18-
$this->actionManager->register(new AutoCreateSubtask($this->container));
18+
19+
if (file_exists('plugins/Subtaskdate')) {
20+
$this->actionManager->register(new AutoCreateSubtask($this->container));
21+
} else {
22+
$this->actionManager->register(new AutoCreateSubtaskVanilla($this->container));
23+
}
24+
1925
}
2026

2127
public function getPluginName()
@@ -30,7 +36,7 @@ public function getPluginAuthor()
3036

3137
public function getPluginVersion()
3238
{
33-
return '0.0.3';
39+
return '1.0.4';
3440
}
3541

3642
public function getPluginDescription()

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,13 @@
55
Kanboard Plugin to create Automatic Actions for subtasks.
66
This Automatic Action will allow you to add a subtask when the task is moved to another column or upon Task creation within a column.
77

8+
# Requirements
9+
- Kanboard >=1.0.48
10+
- Previous requirement to install [Subtaskdate](https://github.com/eSkiSo/Subtaskdate) plugin, has been removed.
811

912
# Install
1013
Create a directory **AutomaticAction** under the folder **plugins**
1114
- Copy all source files in this new directory.
1215

13-
# Requirements
14-
Since this adds a due date to the subtask, you may need to also have Subtask Due Date Plugin installed as well.
15-
https://github.com/eSkiSo/Subtaskdate
16-
1716
# Screenshot
1817
![Screenshot](https://github.com/creecros/AutoSubtasks/blob/master/screenshot/image.png)

0 commit comments

Comments
 (0)