-
Notifications
You must be signed in to change notification settings - Fork 6
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
MBS-8974: Add repeating of cards #47
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
* Class to handle updating the board | ||
* | ||
* @package mod_kanban | ||
* @copyright 2023-2024 ISB Bayern | ||
* @copyright 2023-2024 ISB Bayern | ||
* @author Stefan Hanauska | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
@@ -34,7 +34,7 @@ | |
* Class to handle updating the board. It also sends notifications, but does not check permissions. | ||
* | ||
* @package mod_kanban | ||
* @copyright 2023-2024 ISB Bayern | ||
* @copyright 2023-2024 ISB Bayern | ||
* @author Stefan Hanauska | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
@@ -477,7 +477,6 @@ public function add_card(int $columnid, int $aftercard = 0, array $data = []): i | |
|
||
// Users can always edit cards they created. | ||
$data['canedit'] = $this->can_user_manage_specific_card($data['id']); | ||
; | ||
$data['columnname'] = clean_param($column->title, PARAM_TEXT); | ||
|
||
$this->formatter->put('cards', $data); | ||
|
@@ -547,7 +546,9 @@ public function move_card(int $cardid, int $aftercard, int $columnid = 0): void | |
// If target column has autoclose option set, update card to be completed. | ||
$options = json_decode($targetcolumn->options); | ||
if (!empty($options->autoclose)) { | ||
$updatecard['completed'] = 1; | ||
if ($card->completed) { | ||
self::set_card_complete($cardid, 1); | ||
} | ||
} | ||
$DB->update_record('kanban_card', $updatecard); | ||
// When inplace editing the title and moving the card happens quite fast in a row, | ||
|
@@ -581,11 +582,7 @@ public function move_card(int $cardid, int $aftercard, int $columnid = 0): void | |
$assignees = $this->get_card_assignees($cardid); | ||
helper::send_notification($this->cminfo, 'moved', $assignees, (object) $data); | ||
if (!empty($options->autoclose) && $card->completed == 0) { | ||
$data['title'] = clean_param($card->title, PARAM_TEXT); | ||
helper::send_notification($this->cminfo, 'closed', $assignees, (object) $data); | ||
helper::remove_calendar_event($this->kanban, $card); | ||
$this->write_history('completed', constants::MOD_KANBAN_CARD, [], $columnid, $cardid); | ||
$this->update_completion($assignees); | ||
self::set_card_complete($cardid, 1); | ||
} | ||
$this->write_history( | ||
'moved', | ||
|
@@ -688,6 +685,32 @@ public function set_card_complete(int $cardid, int $state): void { | |
$assignees = $this->get_card_assignees($cardid); | ||
if ($state) { | ||
helper::remove_calendar_event($this->kanban, $card, $assignees); | ||
if (!empty($card->repeat_enable)) { | ||
$newcard = clone $card; | ||
if ($card->repeat_newduedate == constants::MOD_KANBAN_REPEAT_NONEWDUEDATE) { | ||
$newcard->duedate = 0; | ||
$newcard->reminder = 0; | ||
} else { | ||
$timedifference = $newcard->duedate - $newcard->reminder; | ||
$timebase = ( | ||
$card->repeat_newduedate == constants::MOD_KANBAN_REPEAT_NEWDUEDATE_AFTERDUE && !empty($newcard->duedate) ? | ||
$newcard->duedate : | ||
time() | ||
); | ||
$newcard->duedate = strtotime( | ||
'+' . | ||
$card->repeat_interval . | ||
' ' . | ||
constants::MOD_KANBAN_REPEAT_INTERVAL_TYPE[$card->repeat_interval_type], | ||
$timebase | ||
); | ||
$newcard->reminder = $newcard->duedate - $timedifference; | ||
} | ||
$card->repeat_enable = 0; | ||
$this->update_card($cardid, (array) $card); | ||
$newcard->isrepeated = 1; | ||
$this->add_card($this->get_leftmost_column($card->kanban_board), 0, (array)$newcard); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PHPCS moniert das nicht |
||
} | ||
} else { | ||
helper::add_or_update_calendar_event($this->kanban, $card, $assignees); | ||
} | ||
|
@@ -813,6 +836,10 @@ public function update_card(int $cardid, array $data): void { | |
'kanban_column', | ||
'kanban_board', | ||
'completed', | ||
'repeat_enable', | ||
'repeat_interval', | ||
'repeat_interval_type', | ||
'repeat_newduedate', | ||
]; | ||
// Do some extra sanitizing. | ||
if (isset($data['title'])) { | ||
|
@@ -1230,4 +1257,24 @@ public function can_user_manage_specific_card(int $cardid, int $userid = 0): boo | |
|
||
return false; | ||
} | ||
|
||
/** | ||
* Returns the leftmost column of a board, 0 if none is found. | ||
* | ||
* @param int $boardid Id of the board, defaults to 0 (current board) | ||
* @return int | ||
*/ | ||
public function get_leftmost_column(int $boardid = 0): int { | ||
global $DB; | ||
if (empty($boardid) || $this->board->id == $boardid) { | ||
$sequence = $this->board->sequence; | ||
} else { | ||
$sequence = $DB->get_field('kanban_board', 'sequence', ['id' => $boardid]); | ||
} | ||
if (empty($sequence)) { | ||
return 0; | ||
} | ||
$columnids = explode(',', $sequence, 2); | ||
return $columnids[0]; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,13 +21,14 @@ | |
use core_form\dynamic_form; | ||
use mod_kanban\boardmanager; | ||
use mod_kanban\helper; | ||
use mod_kanban\constants; | ||
use moodle_url; | ||
|
||
/** | ||
* From for editing a card. | ||
* | ||
* @package mod_kanban | ||
* @copyright 2023-2024 ISB Bayern | ||
* @copyright 2023-2024 ISB Bayern | ||
* @author Stefan Hanauska | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
@@ -80,6 +81,32 @@ public function definition() { | |
|
||
$mform->addElement('date_time_selector', 'reminderdate', get_string('reminderdate', 'kanban'), ['optional' => true]); | ||
|
||
$repeatgroup = []; | ||
$repeatgroup[] = $mform->createElement('advcheckbox', 'repeat_enable', get_string('enable')); | ||
$repeatgroup[] = $mform->createElement('text', 'repeat_interval', get_string('repeat_interval', 'kanban'), ['size' => 3]); | ||
$repeatgroup[] = $mform->createElement('select', 'repeat_interval_type', get_string('repeat_interval_type', 'kanban'), [ | ||
constants::MOD_KANBAN_REPEAT_HOURS => get_string('hours'), | ||
constants::MOD_KANBAN_REPEAT_DAYS => get_string('days'), | ||
constants::MOD_KANBAN_REPEAT_WEEKS => get_string('weeks'), | ||
constants::MOD_KANBAN_REPEAT_MONTHS => get_string('months'), | ||
constants::MOD_KANBAN_REPEAT_YEARS => get_string('years'), | ||
]); | ||
$repeatgroup[] = $mform->createElement('select', 'repeat_newduedate', get_string('repeat_newduedate', 'kanban'), [ | ||
constants::MOD_KANBAN_REPEAT_NONEWDUEDATE => get_string('nonewduedate', 'kanban'), | ||
constants::MOD_KANBAN_REPEAT_NEWDUEDATE_AFTERDUE => get_string('afterdue', 'kanban'), | ||
constants::MOD_KANBAN_REPEAT_NEWDUEDATE_AFTERCOMPLETION => get_string('aftercompletion', 'kanban'), | ||
]); | ||
|
||
$mform->addElement('group', 'repeatgroup', get_string('repeat', 'kanban'), $repeatgroup, ' ', false); | ||
|
||
$mform->setType('repeat_interval', PARAM_INT); | ||
$mform->setType('repeat_interval_type', PARAM_INT); | ||
$mform->setDefault('repeat_interval', 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bei mir ist der default leider 0 (also 0 Stunden). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Das kommt wohl daher, dass der Standard-Wert in der DB 0 ist. Ich habe das angepasst. |
||
$mform->disabledIf('repeatgroup', 'repeat_enable', 'notchecked'); | ||
$mform->disabledIf('repeat_interval', 'repeat_newduedate', 'eq', constants::MOD_KANBAN_REPEAT_NONEWDUEDATE); | ||
$mform->disabledIf('repeat_interval_type', 'repeat_newduedate', 'eq', constants::MOD_KANBAN_REPEAT_NONEWDUEDATE); | ||
$mform->addHelpButton('repeatgroup', 'repeat', 'kanban'); | ||
|
||
$mform->addElement('filemanager', 'attachments', get_string('attachments', 'kanban')); | ||
|
||
$mform->addElement('color', 'color', get_string('color', 'mod_kanban'), ['size' => 5]); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ | |
* mod_kanban db upgrades. | ||
* | ||
* @package mod_kanban | ||
* @copyright 2023-2024 ISB Bayern | ||
* @copyright 2023-2024 ISB Bayern | ||
* @author Stefan Hanauska | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | ||
*/ | ||
|
@@ -29,6 +29,60 @@ | |
* @param int $oldversion Version number the plugin is being upgraded from. | ||
*/ | ||
function xmldb_kanban_upgrade($oldversion) { | ||
// No upgrade steps until now. | ||
global $DB; | ||
$dbman = $DB->get_manager(); | ||
|
||
if ($oldversion < 2024121602) { | ||
// Define field repeat_enable to be added to kanban_card. | ||
$table = new xmldb_table('kanban_card'); | ||
$field = new xmldb_field('repeat_enable', XMLDB_TYPE_INTEGER, '2', null, XMLDB_NOTNULL, null, '0', 'timemodified'); | ||
|
||
// Conditionally launch add field repeat_enable. | ||
if (!$dbman->field_exists($table, $field)) { | ||
$dbman->add_field($table, $field); | ||
} | ||
|
||
$field = new xmldb_field('repeat_interval', XMLDB_TYPE_INTEGER, '11', null, XMLDB_NOTNULL, null, '0', 'repeat_enable'); | ||
|
||
// Conditionally launch add field repeat_interval. | ||
if (!$dbman->field_exists($table, $field)) { | ||
$dbman->add_field($table, $field); | ||
} | ||
|
||
$field = new xmldb_field( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Warum wird hier eine unterschiedliche Formatierung genutzt? Oben inline, hier über mehrere Zeilen. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wegen der maximalen Zeilenlänge von 132 Zeichen. |
||
'repeat_interval_type', | ||
XMLDB_TYPE_INTEGER, | ||
'11', | ||
null, | ||
XMLDB_NOTNULL, | ||
null, | ||
'0', | ||
'repeat_interval' | ||
); | ||
|
||
// Conditionally launch add field repeat_interval_type. | ||
if (!$dbman->field_exists($table, $field)) { | ||
$dbman->add_field($table, $field); | ||
} | ||
|
||
$field = new xmldb_field( | ||
'repeat_newduedate', | ||
XMLDB_TYPE_INTEGER, | ||
'5', | ||
null, | ||
XMLDB_NOTNULL, | ||
null, | ||
'0', | ||
'repeat_interval_type' | ||
); | ||
|
||
// Conditionally launch add field repeat_newduedate. | ||
if (!$dbman->field_exists($table, $field)) { | ||
$dbman->add_field($table, $field); | ||
} | ||
|
||
// Kanban savepoint reached. | ||
upgrade_mod_savepoint(true, 2024121602, 'kanban'); | ||
} | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wo wird isrepeated noch verwendet?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ist entfernt, das ist wohl ein Überrest einer alten Implementierung