Esempio n. 1
0
         $groupArr['expired'] = $group->isExpired();
         $groupList[] = $groupArr;
     }
     $view->render('json.php', $groupList);
 });
 $app->post('/', function () use($app, $view) {
     $data = json_decode($app->request->getBody(true));
     g::createGroup(['name' => $data->name, 'description' => $data->description]);
 });
 $app->get('/:id', function ($id) use($app, $view) {
     $group = is_numeric($id) ? g::findGroupById($id) : g::findGroupByName($id);
     $view->render('json.php', $group->toArray());
 });
 $app->delete('/:id', function ($id) use($app, $view) {
     $group = g::findGroupById($id);
     g::deleteGroup($group);
 });
 $app->get('/:id/permission', function ($groupId) use($app, $view) {
     $permissions = g::findGroupById($groupId)->permissions;
     $view->render('json.php', $permissions->toArray(true));
 });
 $app->put('/:id/permission/:permId', function ($groupId, $permId) use($app, $view) {
     $group = g::findGroupById($groupId);
     if ($group->hasPermission($permId) === false) {
         $group->addPermission($permId);
     }
 });
 $app->delete('/:id/permission/:permId', function ($groupId, $permId) use($app, $view) {
     $group = g::findGroupById($groupId);
     $group->removePermission($permId);
 });