示例#1
0
        // 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.
            $request = $app->request();
            $input = json_decode($request->getBody());
            $rows = is_object($input) ? get_object_vars($input) : $input;
            // Update all rows.
            for ($i = 0; $i < count($rows); $i++) {
                $entry = Assistance::find($rows[$i]->id);
                $attributes = is_object($rows[$i]) ? get_object_vars($rows[$i]) : $rows[$i];
                $creation = is_object($rows[$i]->creation) ? get_object_vars($rows[$i]->creation) : $rows[$i]->creation;
                $attributes['creation'] = $creation['date'];
                if ($entry != null) {
                    $entry->update_attributes($attributes);
                }
            }
            // Return result.
            echo json_encode(array("error" => null));
        } else {
            // Return error message.
            ApiUtils::returnError($app, 'UserNotAdmin');
        }
    } catch (Exception $e) {
        // An exception ocurred. Return an error message.
示例#2
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);
    }
});