Files
monica/app/Http/Controllers/Contacts/ActivitiesController.php
T
dependabot-preview[bot] 387e45b85d chore(deps): bump laravel/cashier from 8.0.1 to 9.3.5 (#2857)
* chore(deps): bump laravel/cashier from 8.0.1 to 9.3.5

Bumps [laravel/cashier](https://github.com/laravel/cashier) from 8.0.1 to 9.3.5.
- [Release notes](https://github.com/laravel/cashier/releases)
- [Changelog](https://github.com/laravel/cashier/blob/9.0/CHANGELOG.md)
- [Upgrade guide](https://github.com/laravel/cashier/blob/9.0/UPGRADE.md)
- [Commits](https://github.com/laravel/cashier/compare/v8.0.1...v9.3.5)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>
2019-08-10 16:12:47 +02:00

67 lines
2.2 KiB
PHP

<?php
namespace App\Http\Controllers\Contacts;
use Carbon\Carbon;
use Illuminate\Http\Request;
use App\Models\Contact\Contact;
use App\Http\Controllers\Controller;
use App\Services\Account\Activity\ActivityStatisticService;
class ActivitiesController extends Controller
{
/**
* Statistics about an activity.
*
* @var ActivityStatisticService
*/
protected $activityStatisticService;
public function __construct(ActivityStatisticService $service)
{
$this->activityStatisticService = $service;
}
/**
* Get all the activities for this contact.
*/
public function index(Contact $contact)
{
// get the year of the most recent activity done with the contact
$year = $contact->activities->sortByDesc('date_it_happened')->first()->date_it_happened->year;
return redirect()->route('people.activities.year', [$contact, $year]);
}
/**
* Get all the activities for this contact for a specific year.
*/
public function year(Request $request, Contact $contact, int $year)
{
$startDate = Carbon::create($year, 1, 1);
$endDate = Carbon::create($year, 12, 31);
$activitiesLastTwelveMonths = $this->activityStatisticService
->activitiesWithContactInTimeRange($contact, now()->subMonths(12), now())
->count();
$uniqueActivityTypes = $this->activityStatisticService
->uniqueActivityTypesInTimeRange($contact, $startDate, $endDate);
$activitiesPerYear = $this->activityStatisticService->activitiesPerYearWithContact($contact);
$activitiesPerMonthForYear = $this->activityStatisticService
->activitiesPerMonthForYear($contact, $year)
->sortByDesc('month');
return view('people.activities.index')
->withTotalActivities($contact->activities->count())
->withActivitiesLastTwelveMonths($activitiesLastTwelveMonths)
->withUniqueActivityTypes($uniqueActivityTypes)
->withActivitiesPerYear($activitiesPerYear)
->withActivitiesPerMonthForYear($activitiesPerMonthForYear)
->withYear($year)
->withContact($contact);
}
}