示例#1
0
 public function apiDashboard($req, $res)
 {
     $app = $this->app;
     $route = new ApiRoute();
     $route->addQueryParams(['model' => 'app\\organizations\\models\\Organization', 'model_id' => $req->params('id')])->addParseSteps(['parseRequireJson', 'parseModelFindOneParameters'])->addQueryStep('queryModelFindOne')->addTransformSteps([function (&$result, $route) use($app) {
         $org = $result;
         if (!$org->exists) {
             $route->getResponse()->setCode(404);
             return false;
         }
         if (!$org->can('admin', $app['user'])) {
             $route->getResponse()->setCode(403);
             return false;
         }
         $start = strtotime('-11 months');
         $end = time();
         $result = ['dashboard' => ['totals' => ['volunteers' => $org->numVolunteers(), 'hours' => $org->totalHoursVolunteered(), 'places' => $org->numPlaces()], 'alerts' => $org->alerts(), 'period' => $org->activityForPeriod($start, $end)]];
     }, 'transformOutputJson']);
     $route->execute($req, $res, $app);
 }