示例#1
0
                ApiUtils::returnSimpleMessage($app, "EntryNotUpdated", "The entry could not be updated", 422);
            }
        } else {
            // Return error message.
            ApiUtils::returnError($app, 'UserNotAdmin');
        }
    } catch (Exception $e) {
        // An exception ocurred. Return an error message.
        ApiUtils::handleException($app, $e);
    }
});
// Service for delete a row from the database.
$app->delete('/:type/:id', function ($type, $id) use($app) {
    try {
        // Verify that the user is logged as administrator.
        if (ApiUtils::isAdmin()) {
            $error = null;
            $message = null;
            $statusCode = null;
            // Groups.
            if ($type == "group") {
                // Verify if the groups is used by persons.
                $count = Person::count(array('conditions' => 'group_id = ' . $id));
                if ($count <= 0) {
                    // Delete group.
                    $row = Group::find($id);
                    $row->delete();
                } else {
                    // Set error.
                    $error = "CantDeleteGroup";
                    $message = "The group could not be deleted since they are persons that belong to them";