public function apiVolunteerActivity($req, $res) { $route = new ApiRoute(); $route->addQueryParams(['module' => 'volunteers', 'model' => 'app\\volunteers\\models\\Volunteer', 'organization' => $req->query('organization'), 'start' => $req->query('start'), 'end' => $req->query('end')])->addParseSteps(['parseRequireJson', 'parseModelFindOneParameters'])->addQueryStep('queryModelFindOne')->addTransformSteps(['transformModelFindOne', function (&$result, $route) { $volunteer = $result; $modelClass = $route->getQueryParams('model'); if ($volunteer instanceof $modelClass) { $org = new Organization($route->getQueryParams('organization')); // look up volunteer hours using the organization $hIter = $org->hours($route->getQueryParams('start'), $route->getQueryParams('end'), $volunteer); $hours = []; foreach ($hIter as $hour) { $hours[] = $hour->toArray([], [], ['place']); } $result = ['volunteer_hours' => $hours]; } }, 'transformOutputJson']); $route->execute($req, $res, $this->app); }