ResponseRepository
extends ApiRepository
in package
uses
SaveTrait, RegisterEventTrait, AdvertScopeHintTrait
Front repository that reads through the Api bridge and uses the query cache when the service has it enabled (`cache.config.enabledServices`).
This is the deliberate opposite of ApiRepository: the front end only displays data, so a 5 minute old number is at most cosmetic, whereas the admin reads it into a form that is written back to the DB.
->useCache(false) on the query object overrides the policy for one query; it travels
to the payload as ApiBridge::PARAM_USE_CACHE.
IMPORTANT: null is passed on as null (no opinion), not as true. If this layer
substituted true, it would override QueryCacheContext, and
reads through a front manager inside an admin request (AssetManager, ThemeManager,
UserManager) would still be served from the cache. The true default therefore lives
in the bridge.
Table of Contents
Properties
- $apiEndpoint : string
- Api presenter path (e.g. `api/system/page`); set by each concrete repository.
- $bridge : ApiBridge
Methods
- __construct() : mixed
- find() : array<string|int, mixed>
- findAll() : array<string|int, mixed>
- Reads responses through the dedicated internal action `:Api:Bazaar:Response:myList` ({@see \App\Core\Traits\Api\Presenters\AdvertScopedListTrait}), not `:Api:Bazaar:Response:getAll`.
- findBy() : array<string|int, mixed>
- markReadByKey() : Result
- Marks a response as read from an e-mail link through the internal Api action `markReadByKey` ({@see \App\UI\Api\Bazaar\Presenters\ResponsePresenter::internalActionMarkReadByKey()}, no `action*()`).
- registerEvent() : Result
- save() : Result
- updateColumns() : Result
- advertScopeHint() : int|null
- failSoftRead() : array<string|int, mixed>
- Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
- getApiCallSource() : string
- Returns the caller branch ({@see \App\Core\Bridge\ApiBridge::PARAM_SOURCE}); implemented by the Front and Admin base `ApiRepository`.
Properties
$apiEndpoint
Api presenter path (e.g. `api/system/page`); set by each concrete repository.
protected
string
$apiEndpoint
= 'api/bazaar/response'
$bridge read-only
protected
ApiBridge
$bridge
Methods
__construct()
public
__construct(ApiBridge $bridge) : mixed
Parameters
- $bridge : ApiBridge
find()
public
find(int $id[, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
- $id : int
- $includes : string|array<string|int, mixed> = []
- $useCache : bool|null = null
Return values
array<string|int, mixed>findAll()
Reads responses through the dedicated internal action `:Api:Bazaar:Response:myList` ({@see \App\Core\Traits\Api\Presenters\AdvertScopedListTrait}), not `:Api:Bazaar:Response:getAll`.
public
findAll([array<int, mixed>|null $filters = [] ][, array<string, mixed>|null $orderBys = null ][, int|null $offset = null ][, int|null $limit = null ][, array<int, string>|null $columns = null ][, bool $computeTotalCount = false ][, string|array<int, string> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
getAll has actionGetAll() (externally reachable) and the Response entity carries the
sender name, e-mail, phone and message; a grant would open foreign responses to every token
holder. myList has no action*() and the server sets the scope.
IMPORTANT: there are two callers with different scopes, so advertId is sent separately.
/odpovedi-na-inzeraty(ResponseListTrait) filters byadvert.insertUserId("my adverts"), so the hint isnulland the server setsadvert.insertUserId = jwt.userId;- the Responses tab on the advert edit page
(EditResponsesTrait) filters by
advertId, and the editor may prove access with the advert password, without any identity. AuserId-scoped filter would not serve that case, so the server verifiesadvertIdagainst the DB (capability,insertUserIdor privileged role).
advertId is only a hint which advert (AdvertScopeHintTrait), never proof; the
server loads the advert from the DB and decides itself.
Parameters
- $filters : array<int, mixed>|null = []
- $orderBys : array<string, mixed>|null = null
- $offset : int|null = null
- $limit : int|null = null
- $columns : array<int, string>|null = null
- $computeTotalCount : bool = false
- $includes : string|array<int, string> = []
- $useCache : bool|null = null
Return values
array<string|int, mixed>findBy()
public
findBy([array<string|int, mixed>|null $filters = [] ][, string|array<string|int, mixed> $includes = [] ][, bool|null $useCache = null ]) : array<string|int, mixed>
Parameters
- $filters : array<string|int, mixed>|null = []
- $includes : string|array<string|int, mixed> = []
- $useCache : bool|null = null
Return values
array<string|int, mixed>markReadByKey()
Marks a response as read from an e-mail link through the internal Api action `markReadByKey` ({@see \App\UI\Api\Bazaar\Presenters\ResponsePresenter::internalActionMarkReadByKey()}, no `action*()`).
public
markReadByKey(int $id, string $key) : Result
Sends only id and key from the URL; the Api verifies the key, not the Front.
Parameters
- $id : int
- $key : string
Return values
ResultregisterEvent()
public
registerEvent(array<string|int, int> $ids, string $property) : Result
Parameters
- $ids : array<string|int, int>
- $property : string
Return values
Resultsave()
public
save(array<string, mixed> $data[, array<string, mixed> $meta = [] ][, array<int, string> $skipFields = [] ]) : Result
Parameters
- $data : array<string, mixed>
-
extracted entity payload
- $meta : array<string, mixed> = []
- $skipFields : array<int, string> = []
Return values
ResultupdateColumns()
public
updateColumns(array<string|int, mixed> $ids, array<string, mixed> $values) : Result
Parameters
- $ids : array<string|int, mixed>
-
ids or composite-id arrays
- $values : array<string, mixed>
-
property name => new value
Return values
ResultadvertScopeHint()
protected
static advertScopeHint(array<int, mixed>|null $filters[, string $field = 'advertId' ]) : int|null
Parameters
- $filters : array<int, mixed>|null
- $field : string = 'advertId'
-
field name in the caller filter;
advertIdfor collections,advertfor the follow button (FollowTraitfilters by the association, not a scalar)
Return values
int|nullfailSoftRead()
Normalizes a bridge response to plain data; a failed envelope or a non-array gives `[]`.
protected
failSoftRead(mixed $response, string $endpoint) : array<string|int, mixed>
NOTE: it does not log on purpose. ApiBridge::call(), which sees both the
endpoint and the caller, has already written the API_FAILSOFT source=bridge line; a second
copy would turn one failure into three lines in auth.log.
Parameters
- $response : mixed
- $endpoint : string
-
only for call readability; the log takes the endpoint from the bridge
Return values
array<string|int, mixed>getApiCallSource()
Returns the caller branch ({@see \App\Core\Bridge\ApiBridge::PARAM_SOURCE}); implemented by the Front and Admin base `ApiRepository`.
protected
abstract getApiCallSource() : string