advance template installment on RecoReco spawn (v1.0.3)
This commit is contained in:
@@ -73,6 +73,19 @@ class FinancePersistence extends Base
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* recoreco:task:spawned -- RecoReco (calendar recurrence) just spawned a copy. Its ongoing card
|
||||
* is the TEMPLATE that stays (unlike native recurrence, whose ongoing card is the new child), so
|
||||
* advance the SOURCE template's installment. The clone already copied the current installment
|
||||
* verbatim via onDuplication during RecoReco's duplicate() call.
|
||||
*/
|
||||
public function onRecoRecoSpawn(array &$payload)
|
||||
{
|
||||
if (! empty($payload['source_task_id'])) {
|
||||
$this->advanceInstallment((int) $payload['source_task_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* model:task:modification:prepare -- fires before UPDATE, $values by reference. The task id is
|
||||
* removed from $values by core, but it is the route parameter of the modification request.
|
||||
@@ -176,6 +189,31 @@ class FinancePersistence extends Base
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Advance a task's current installment by one, in place. A finite plan clamps at the total
|
||||
* (p10/10 stays p10/10); an open-ended one (no total) increments unbounded (p2 -> p3). Cards
|
||||
* with no numeric current installment are left alone.
|
||||
*/
|
||||
private function advanceInstallment($task_id)
|
||||
{
|
||||
$current = $this->taskMetadataModel->get($task_id, FinanceHelper::INSTALLMENT_CURRENT_KEY, '');
|
||||
|
||||
if ($current === '' || ! ctype_digit((string) $current)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$total = $this->taskMetadataModel->get($task_id, FinanceHelper::INSTALLMENT_TOTAL_KEY, '');
|
||||
$next = (int) $current + 1;
|
||||
|
||||
if ($total !== '' && ctype_digit((string) $total) && $next > (int) $total) {
|
||||
$next = (int) $total;
|
||||
}
|
||||
|
||||
$this->taskMetadataModel->save($task_id, array(
|
||||
FinanceHelper::INSTALLMENT_CURRENT_KEY => (string) $next,
|
||||
));
|
||||
}
|
||||
|
||||
private function intOrBlank($raw)
|
||||
{
|
||||
$raw = trim((string) $raw);
|
||||
|
||||
Reference in New Issue
Block a user