diff --git a/Plugin.php b/Plugin.php index 44c4d2d..44b20dc 100644 --- a/Plugin.php +++ b/Plugin.php @@ -3,6 +3,7 @@ namespace Kanboard\Plugin\QualKard; use Kanboard\Core\Plugin\Base; +use Kanboard\Model\TaskModel; /** * QualKard -- flashcard spaced repetition on Kanboard cards. @@ -17,10 +18,36 @@ class Plugin extends Base { public function initialize() { + $container = $this->container; + // Per-board setup/reset/disable on Settings -> Integrations. $this->template->hook->attach('template:project:integrations', 'qualKard:project/integration'); - // (The grade handler and the badge are wired in later versions.) + // New card on a QualKard board -> reset it (unread, armed inert, moved to Drafts). + $this->hook->on('model:task:creation:aftersave', function ($task_id) use ($container) { + $helper = new \Kanboard\Plugin\QualKard\Helper\QualKardHelper($container); + $task = $container['taskFinderModel']->getById($task_id); + if (! empty($task) && $helper->isEnabled($task['project_id'])) { + $helper->resetCard($task_id, (int) $task['project_id']); + } + }); + + // Card dragged INTO a grade column -> grade it (RecoReco then handles the movement). The + // plugin on() wrapper drops the event, so we subscribe on the dispatcher to get the TaskEvent. + $this->dispatcher->addListener(TaskModel::EVENT_MOVE_COLUMN, function ($event) use ($container) { + $task = $event['task']; + $helper = new \Kanboard\Plugin\QualKard\Helper\QualKardHelper($container); + if (! $helper->isEnabled($task['project_id'])) { + return; + } + $dst = (int) $event['dst_column_id']; + foreach (array('hairy', 'hard', 'medium', 'easy') as $role) { + if ($dst === $helper->col($task['project_id'], $role)) { + $helper->grade($task['id'], \Kanboard\Plugin\QualKard\Helper\QualKardHelper::SCORE[$role]); + return; + } + } + }); } public function getHelpers() @@ -47,7 +74,7 @@ class Plugin extends Base public function getPluginVersion() { - return '0.3.0'; + return '0.4.0'; } public function getPluginHomepage() diff --git a/Template/project/integration.php b/Template/project/integration.php index 0ad15dd..fd45f3a 100644 --- a/Template/project/integration.php +++ b/Template/project/integration.php @@ -26,3 +26,4 @@ +
diff --git a/VERSION b/VERSION index 66e2f07..d19cc72 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -QualKard v0.3 +QualKard v0.4