firefly-iii/app/Http/Controllers/ReminderController.php

129 lines
3.4 KiB
PHP
Raw Normal View History

2015-03-06 13:33:23 -06:00
<?php namespace FireflyIII\Http\Controllers;
use Auth;
use Carbon\Carbon;
2015-03-07 02:21:06 -06:00
use FireflyIII\Helpers\Reminders\ReminderHelperInterface;
2015-03-06 13:33:23 -06:00
use FireflyIII\Http\Requests;
use FireflyIII\Models\Reminder;
2015-03-07 02:21:06 -06:00
use Redirect;
2015-03-08 14:20:58 -05:00
use Session;
2015-03-10 11:26:31 -05:00
use URL;
2015-03-07 02:21:06 -06:00
/**
* Class ReminderController
*
* @package FireflyIII\Http\Controllers
*/
2015-03-06 13:33:23 -06:00
class ReminderController extends Controller
{
2015-03-08 14:20:58 -05:00
/**
* @param Reminder $reminder
*/
public function act(Reminder $reminder)
{
$data = [
'description' => 'Money for piggy bank "' . $reminder->remindersable->name . '"',
'amount' => round($reminder->metadata->perReminder, 2),
'account_to_id' => $reminder->remindersable->account_id,
2015-03-10 11:26:31 -05:00
'piggy_bank_id' => $reminder->remindersable_id,
'reminder_id' => $reminder->id,
2015-03-08 14:20:58 -05:00
];
2015-03-10 11:26:31 -05:00
Session::flash('_old_input', $data);
2015-03-08 14:20:58 -05:00
2015-03-10 11:26:31 -05:00
return Redirect::route('transactions.create', 'transfer');
2015-03-08 14:20:58 -05:00
}
2015-03-07 02:29:43 -06:00
/**
* @param Reminder $reminder
*/
public function dismiss(Reminder $reminder)
{
$reminder->notnow = true;
$reminder->save();
return Redirect::to(URL::previous());
}
2015-03-06 13:33:23 -06:00
/**
*
*/
2015-03-07 02:21:06 -06:00
public function index(ReminderHelperInterface $helper)
2015-03-06 13:33:23 -06:00
{
$reminders = Auth::user()->reminders()->get();
2015-03-07 02:29:43 -06:00
$reminders->each(
function (Reminder $reminder) use ($helper) {
$reminder->description = $helper->getReminderText($reminder);
}
);
2015-03-07 02:21:06 -06:00
2015-03-07 02:29:43 -06:00
$today = new Carbon;
2015-03-06 13:33:23 -06:00
// active reminders:
$active = $reminders->filter(
2015-03-07 02:21:06 -06:00
function (Reminder $reminder) use ($today) {
2015-03-06 13:33:23 -06:00
if ($reminder->notnow === false && $reminder->active === true && $reminder->startdate <= $today && $reminder->enddate >= $today) {
return $reminder;
}
}
);
// expired reminders:
$expired = $reminders->filter(
function (Reminder $reminder) use ($today) {
if ($reminder->notnow === false && $reminder->active === true && $reminder->startdate > $today || $reminder->enddate < $today) {
return $reminder;
}
}
);
// inactive reminders
$inactive = $reminders->filter(
function (Reminder $reminder) use ($today) {
if ($reminder->active === false) {
return $reminder;
}
}
);
// dismissed reminders
$dismissed = $reminders->filter(
function (Reminder $reminder) use ($today) {
if ($reminder->notnow === true) {
return $reminder;
}
}
);
$title = 'Reminders';
$mainTitleIcon = 'fa-clock-o';
return view('reminders.index', compact('dismissed', 'expired', 'inactive', 'active', 'title', 'mainTitleIcon'));
}
/**
* @param Reminder $reminder
*/
public function show(Reminder $reminder)
{
2015-03-08 14:20:58 -05:00
$title = 'Reminder';
2015-03-07 02:29:43 -06:00
$mainTitleIcon = 'fa-clock-o';
if ($reminder->notnow === true) {
$subTitle = 'Dismissed reminder';
} else {
$subTitle = 'Reminder';
}
$subTitle .= ' for piggy bank "' . $reminder->remindersable->name . '"';
2015-03-06 13:33:23 -06:00
2015-03-07 02:29:43 -06:00
return view('reminders.show', compact('reminder', 'title', 'subTitle', 'mainTitleIcon'));
2015-03-07 02:21:06 -06:00
}
2015-03-06 13:33:23 -06:00
}