Show to whom the chore execution is assigned in calendar events (references #253)

This commit is contained in:
Bernd Bestel 2019-09-17 16:28:11 +02:00
parent 597a9e3d21
commit b5761ae544
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
2 changed files with 16 additions and 1 deletions

View File

@ -1411,3 +1411,6 @@ msgstr[1] ""
msgid "Assigned to me"
msgstr ""
msgid "assigned to %s"
msgstr ""

View File

@ -6,6 +6,7 @@ use \Grocy\Services\StockService;
use \Grocy\Services\TasksService;
use \Grocy\Services\ChoresService;
use \Grocy\Services\BatteriesService;
use \Grocy\Services\UsersService;
class CalendarService extends BaseService
{
@ -51,13 +52,24 @@ class CalendarService extends BaseService
);
}
$usersService = new UsersService();
$users = $usersService->GetUsersAsDto();
$chores = $this->Database->chores();
$titlePrefix = $this->LocalizationService->__t('Chore due') . ': ';
$choreEvents = array();
foreach($this->ChoresService->GetCurrent() as $currentChoreEntry)
{
$chore = FindObjectInArrayByPropertyValue($chores, 'id', $currentChoreEntry->chore_id);
$assignedToText = '';
if (!empty($currentChoreEntry->next_execution_assigned_to_user_id))
{
$assignedToText = ' (' . $this->LocalizationService->__t('assigned to %s', FindObjectInArrayByPropertyValue($users, 'id', $currentChoreEntry->next_execution_assigned_to_user_id)->display_name) . ')';
}
$choreEvents[] = array(
'title' => $titlePrefix . FindObjectInArrayByPropertyValue($chores, 'id', $currentChoreEntry->chore_id)->name,
'title' => $titlePrefix . $chore->name . $assignedToText,
'start' => $currentChoreEntry->next_estimated_execution_time,
'date_format' => 'datetime'
);