Esempio n. 1
0
            if ($type == "user") {
                // Verify if the user is used by assistances.
                $count = Assistance::count(array('conditions' => 'user_id = ' . $id));
                if ($count <= 0) {
                    // Delete officer.
                    $row = User::find($id);
                    $row->delete();
                } else {
                    // Set error.
                    $error = "CantDeleteUser";
                    $message = "The user could not be deleted since some assistance lists are linked to him";
                    $statusCode = 422;
                }
            }
            // Return result.
            ApiUtils::returnSimpleMessage($app, $error, $message, $statusCode);
        } else {
            // Return error message.
            ApiUtils::returnError($app, 'UserNotAdmin');
        }
    } catch (Exception $e) {
        // An exception ocurred. Return an error message.
        ApiUtils::handleException($app, $e);
    }
});
// Service for update the values of an assistance list.
$app->put('/assistanceList', function () use($app) {
    try {
        // Verify that the user is logged.
        if (ApiUtils::isLogged()) {
            // Get input.