RecoReco: config modal + metadata storage, off Skeleton (v0.2)
This commit is contained in:
92
Controller/RecurrenceController.php
Normal file
92
Controller/RecurrenceController.php
Normal file
@@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Plugin\RecoReco\Controller;
|
||||
|
||||
use Kanboard\Controller\BaseController;
|
||||
use Kanboard\Model\TaskModel;
|
||||
|
||||
/**
|
||||
* The "Recurring schedule" modal: configure a card's calendar recurrence and store it in task
|
||||
* metadata. v0.2 is storage only -- no spawning (that is the CLI engine in later versions).
|
||||
*
|
||||
* Gate: a card can only be enabled when it has a due date (the recurrence anchor) and is not
|
||||
* already a native-recurring card (RecoReco and native recurrence are mutually exclusive).
|
||||
*/
|
||||
class RecurrenceController extends BaseController
|
||||
{
|
||||
public function edit(array $values = array(), array $errors = array())
|
||||
{
|
||||
$task = $this->getTask();
|
||||
|
||||
if (empty($values)) {
|
||||
$values = $this->getStoredValues($task);
|
||||
}
|
||||
|
||||
$this->response->html($this->template->render('recoReco:recurrence/edit', array(
|
||||
'task' => $task,
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
'columns_list' => $this->columnModel->getList($task['project_id']),
|
||||
'frequency_list' => $this->getFrequencyList(),
|
||||
'has_due_date' => ! empty($task['date_due']),
|
||||
'is_native' => $task['recurrence_status'] != TaskModel::RECURRING_STATUS_NONE,
|
||||
)));
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$task = $this->getTask();
|
||||
$input = $this->request->getValues();
|
||||
|
||||
// Only a plain card (has a due date, not native-recurring) may be enabled.
|
||||
$can_recur = ! empty($task['date_due']) && $task['recurrence_status'] == TaskModel::RECURRING_STATUS_NONE;
|
||||
$enabled = ($can_recur && isset($input['recoreco_enabled']) && $input['recoreco_enabled'] == 1) ? 1 : 0;
|
||||
|
||||
$frequency = isset($input['recoreco_frequency']) && array_key_exists($input['recoreco_frequency'], $this->getFrequencyList())
|
||||
? $input['recoreco_frequency']
|
||||
: 'monthly_day';
|
||||
|
||||
$values = array(
|
||||
'recoreco_enabled' => $enabled,
|
||||
'recoreco_target_column' => isset($input['recoreco_target_column']) ? (int) $input['recoreco_target_column'] : (int) $task['column_id'],
|
||||
'recoreco_frequency' => $frequency,
|
||||
'recoreco_last_day' => isset($input['recoreco_last_day']) ? 1 : 0,
|
||||
'recoreco_days_before' => isset($input['recoreco_days_before']) && ctype_digit((string) $input['recoreco_days_before']) ? (int) $input['recoreco_days_before'] : 0,
|
||||
);
|
||||
|
||||
// Capture the anchor (the due date at enable time) -- the drift-free pattern. The engine
|
||||
// (v0.3) reads it to compute occurrences.
|
||||
if ($enabled) {
|
||||
$values['recoreco_anchor'] = (int) $task['date_due'];
|
||||
}
|
||||
|
||||
$this->taskMetadataModel->save($task['id'], $values);
|
||||
$this->flash->success(t('Recurring schedule saved.'));
|
||||
|
||||
return $this->response->redirect($this->helper->url->to('TaskViewController', 'show', array('task_id' => $task['id'])), true);
|
||||
}
|
||||
|
||||
private function getStoredValues(array $task)
|
||||
{
|
||||
$meta = $this->taskMetadataModel->getAll($task['id']);
|
||||
|
||||
return array(
|
||||
'recoreco_enabled' => isset($meta['recoreco_enabled']) ? (int) $meta['recoreco_enabled'] : 0,
|
||||
'recoreco_target_column' => isset($meta['recoreco_target_column']) ? (int) $meta['recoreco_target_column'] : (int) $task['column_id'],
|
||||
'recoreco_frequency' => isset($meta['recoreco_frequency']) ? $meta['recoreco_frequency'] : 'monthly_day',
|
||||
'recoreco_last_day' => isset($meta['recoreco_last_day']) ? (int) $meta['recoreco_last_day'] : 0,
|
||||
'recoreco_days_before' => isset($meta['recoreco_days_before']) ? (int) $meta['recoreco_days_before'] : 0,
|
||||
);
|
||||
}
|
||||
|
||||
private function getFrequencyList()
|
||||
{
|
||||
return array(
|
||||
'yearly' => t('Yearly'),
|
||||
'monthly_day' => t('Monthly by day'),
|
||||
'monthly_dow' => t('Monthly by weekday'),
|
||||
'weekly' => t('Weekly'),
|
||||
'daily' => t('Daily'),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user