Ejemplo n.º 1
0
        } else {
            // Return error message.
            ApiUtils::returnError($app, 'UserNotLogged');
        }
    } catch (Exception $e) {
        // An exception ocurred. Return an error message.
        ApiUtils::handleException($app, $e);
    }
});
// Service for get all persons from a group.
$app->get('/assistanceList/:groupId/:eventId/:date', function ($groupId, $eventId, $date) use($app) {
    try {
        // Verify that the user is logged.
        if (isset($_SESSION['user'])) {
            // Get list of persons in the group.
            $now = new DateTime();
            $rows = ApiUtils::rowsToMaps(Assistance::find_by_sql("select * from get_assistance(" . $_SESSION['user']['id'] . "," . $groupId . "," . $eventId . "," . "'" . ($date !== 'today' ? $date : $now->format('Y-m-d')) . "')"));
            // Get name of event and group.
            $event = ApiUtils::rowToMap(Event::find($eventId));
            $group = ApiUtils::rowToMap(Group::find($groupId));
            // Return result.
            echo json_encode(array("rows" => $rows, "date" => $date !== 'today' ? $date : $now->format('Y-m-d'), "event" => $event, "group" => $group, "error" => null));
        } else {
            // Return error message.
            ApiUtils::returnError($app, 'UserNotLogged');
        }
    } catch (Exception $e) {
        // An exception ocurred. Return an error message.
        ApiUtils::handleException($app, $e);
    }
});