本文整理汇总了PHP中League\Fractal\Resource\Collection::setData方法的典型用法代码示例。如果您正苦于以下问题:PHP Collection::setData方法的具体用法?PHP Collection::setData怎么用?PHP Collection::setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类League\Fractal\Resource\Collection
的用法示例。
在下文中一共展示了Collection::setData方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Handle domain logic for an action.
*
* @param array $input
* @return PayloadInterface
*/
public function __invoke(array $input)
{
//Authorize user to be able to view shifts
$this->authorizeUser($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('entity'), 'view', 'shifts');
//Validate input
$inputValidator = v::key('startDateTime', v::stringType())->key('endDateTime', v::stringType());
$inputValidator->assert($input);
//Retrieve shifts between in time period
$shifts = $this->shiftRepository->getShiftsBetween(Carbon::parse($input['startDateTime']), Carbon::parse($input['endDateTime']));
$this->collection->setData($shifts)->setTransformer($this->shiftTransformer);
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes(['manager', 'employee'])->createData($this->collection)->toArray());
}
示例2: __invoke
/**
* Handle domain logic for an action.
*
* @param array $input
* @return PayloadInterface
* @throws UserNotAuthorized
*/
public function __invoke(array $input)
{
//Make sure requested user matches auth user
//todo: figure out if managers can access all employees' hours
if ($input['id'] != $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('id')) {
throw new UserNotAuthorized();
}
//Get hours and transform to more readable collection
$employee = $this->userRepository->getOneByIdOrFail($input['id']);
$hours = $this->shiftRepository->getHoursCountGroupedByWeekFor($employee);
$this->collection->setData($hours)->setTransformer($this->hoursTransformer);
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->createData($this->collection)->toArray());
}
示例3: __invoke
/**
* @param array $input
* @return PayloadInterface
* @throws UserNotAuthorized
*/
public function __invoke(array $input)
{
//Don't allow employees to view other employee's shifts
//todo: figure out if managers can access all employees' shifts
if ($input['id'] != $input[AuthHandler::TOKEN_ATTRIBUTE]->getMetaData('id')) {
throw new UserNotAuthorized();
}
//Validate input
$inputValidator = v::key('id', v::intVal());
$inputValidator->assert($input);
//Get shifts and transform
$employee = $this->userRepository->getOneByIdOrFail($input['id']);
$shifts = $this->shiftRepository->getByEmployee($employee);
$this->collection->setData($shifts)->setTransformer($this->shiftTransformer);
$include = array_key_exists('include', $input) ? $input['include'] : '';
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes($include)->createData($this->collection)->toArray());
}
示例4: __invoke
/**
* Handle domain logic for an action.
*
* @param array $input
* @return PayloadInterface
* @throws UserNotAuthorized
*/
public function __invoke(array $input)
{
//Check that the auth user matches the requested user
//todo: determine if manager's should have access
if ($input[AuthHandler::TOKEN_ATTRIBUTE]->getMetadata('id') != $input['id']) {
throw new UserNotAuthorized();
}
$employee = $this->userRepository->getOneByIdOrFail($input['id']);
$shifts = $this->shiftRepository->getByEmployee($employee);
//Loop over shifts getting employees that work at the same time for each shift
foreach ($shifts as $shift) {
$coworkers = $this->userRepository->getEmployeesWorkingBetween($shift->getStartTime(), $shift->getEndTime(), [$employee]);
$shift->setCoworkers($coworkers);
}
$this->collection->setData($shifts)->setTransformer($this->shiftTransformer);
return $this->payload->withStatus(PayloadInterface::OK)->withOutput($this->fractal->parseIncludes('coworkers')->createData($this->collection)->toArray());
}