InitTrait
Prepares the data of the job header, the work item table and the detail of one expanded work item (including the comment thread). Shared with {@see FormTrait}: the comment form needs `fetchLists()`/`prepareWorkDetail()` before the presenter calls `render()`.
WorkList is the job, WorkSheet is a work sheet inside a job. The job detail (this trait)
groups work items by sheet (groupItemsBySheet()).
Table of Contents
Methods
- belongsToCurrentList() : bool
- Tells whether the expanded work item belongs to the job `$this->workListId` (replaces the removed `WorkItem::getWorkListId()`, see {@see prepareWorkDetail()}). `myItems` returns only the work items of this job (the server verified ownership), so membership in the {@see fetchItems()} result is the answer.
-
fetchItems()
: WorkSheet>, unreadComments: array
} - Returns `WorkItemManager::findMyItems()` memoized for the lifetime of this component instance, for the same reason as {@see fetchLists()}: the guard of `prepareWorkDetail()` ({@see belongsToCurrentList()}) can run before `render()` and `prepareDetail()` calls it again; without memoization that would be two bridge queries per request.
-
fetchLists()
: WorkList>, totalCount: int, workItemCounts: array
} - Returns `WorkListManager::findMyLists()` memoized for the lifetime of this component instance (one request). Required because the comment form can be created before `render()` (a form POST calls `createComponent*()` first); same as {@see \App\UI\Front\Company\Components\BookingCalendarComponent\Traits\InitTrait::fetchAvailability()}.
- findOwnedList() : WorkList|null
- Returns the owned job from `myList` by `$this->workListId`, or `null` (foreign or nonexistent).
- groupItemsBySheet() : array<int, WorkItem>, sumHours: string, sumPrice: string}>
- Groups work items by work sheet for the template (sheet heading + its items + hours/price sum per group).
- prepareDetail() : void
- prepareEmptyWorkDetail() : void
- prepareWorkDetail() : void
- sumGroupHours() : string
- Returns the hours sum of a group: the same value as shown on the row (`actualHours ?? estimatedHours`, {@see \App\UI\Front\Company\Components\MyWorkDetailComponent\Templates\Default\Sections\Items.latte}), so the sum matches the table above it.
- sumGroupPrice() : string
Methods
belongsToCurrentList()
Tells whether the expanded work item belongs to the job `$this->workListId` (replaces the removed `WorkItem::getWorkListId()`, see {@see prepareWorkDetail()}). `myItems` returns only the work items of this job (the server verified ownership), so membership in the {@see fetchItems()} result is the answer.
private
belongsToCurrentList(WorkItem $detail) : bool
Parameters
- $detail : WorkItem
Return values
boolfetchItems()
Returns `WorkItemManager::findMyItems()` memoized for the lifetime of this component instance, for the same reason as {@see fetchLists()}: the guard of `prepareWorkDetail()` ({@see belongsToCurrentList()}) can run before `render()` and `prepareDetail()` calls it again; without memoization that would be two bridge queries per request.
private
fetchItems() : WorkSheet>, unreadComments: array}
Return values
WorkSheet>, unreadComments: arrayfetchLists()
Returns `WorkListManager::findMyLists()` memoized for the lifetime of this component instance (one request). Required because the comment form can be created before `render()` (a form POST calls `createComponent*()` first); same as {@see \App\UI\Front\Company\Components\BookingCalendarComponent\Traits\InitTrait::fetchAvailability()}.
private
fetchLists() : WorkList>, totalCount: int, workItemCounts: array}
Return values
WorkList>, totalCount: int, workItemCounts: arrayfindOwnedList()
Returns the owned job from `myList` by `$this->workListId`, or `null` (foreign or nonexistent).
private
findOwnedList() : WorkList|null
Return values
WorkList|nullgroupItemsBySheet()
Groups work items by work sheet for the template (sheet heading + its items + hours/price sum per group).
private
groupItemsBySheet(array<int, WorkItem> $items, array<int, WorkSheet> $sheets) : array<int, WorkItem>, sumHours: string, sumPrice: string}>
IMPORTANT: the group order follows the first occurrence in $items. The Api returns them
already sorted work_sheets.order -> work_items.order -> id
(WorkItemManager::sortForInvoice()), i.e. exactly in
the order they would go on the invoice. They are not sorted again here, only grouped, so the
order never differs from what the client sees on the document.
An item without _references (should not happen, every work item has a sheet) gets
sheet: null; the template then shows the work item without a sheet header rather than silently
dropping it (degrade, not fatal, as in EntityHydrator).
Sums are computed by the server (PHP), not in the template; bcadd is used because of the
decimal columns (decimal in the DB, string on the entity), like
WorkListManager::sumItemPrices().
Parameters
Return values
array<int, WorkItem>, sumHours: string, sumPrice: string}>prepareDetail()
private
prepareDetail() : void
prepareEmptyWorkDetail()
private
prepareEmptyWorkDetail() : void
prepareWorkDetail()
private
prepareWorkDetail() : void
sumGroupHours()
Returns the hours sum of a group: the same value as shown on the row (`actualHours ?? estimatedHours`, {@see \App\UI\Front\Company\Components\MyWorkDetailComponent\Templates\Default\Sections\Items.latte}), so the sum matches the table above it.
private
sumGroupHours(array<int, WorkItem> $items) : string
Parameters
- $items : array<int, WorkItem>
Return values
stringsumGroupPrice()
private
sumGroupPrice(array<int, WorkItem> $items) : string
Parameters
- $items : array<int, WorkItem>