registerAccessLevels

This function registers new access levels for an event, defining their properties including ticket price, access level name, and whitelist status. It takes four parameters:

  • _eventId: The unique identifier for the event to which the new access levels belong.

  • _newAccessLevels: An array containing the names of the new access levels being registered.

  • _newTicketPrices: An array containing the prices of tickets for the new access levels.

  • _newWhitelists: An array of boolean values indicating whether each new access level requires whitelisting.

```remix-solidity
/**
     * @notice Register new access levels for an event, including ticket price, access level name, and whitelist status.
     * @dev This function allows event managers to add new access levels to their events.
     *      It verifies that the caller is an event manager, checks for existing access levels,
     *      and updates the mappings with the new access level information.
     *
     * @param _eventId The unique identifier for the event.
     * @param _newAccessLevels An array of names for the new access levels.
     * @param _newTicketPrices An array of ticket prices for the new access levels, corresponding to the names.
     * @param _newWhitelists An array of booleans indicating whether each new access level requires whitelisting.
     *
     * Requirements:
     * - The length of `_newAccessLevels`, `_newTicketPrices`, and `_newWhitelists` must be the same.
     * - The caller must be an event manager for the event specified by `_eventId`.
     * - Each access level name in `_newAccessLevels` must not already exist for the event.
     *
     * Format: eventId, accessLevel, ticketPrice, isWhitelisted
     */

    function registerAccessLevels(
        string calldata _eventId,
        string[] calldata _newAccessLevels,
        uint256[] calldata _newTicketPrices,
        bool[] calldata _newWhitelists
    ) public {
        // Ensure all input arrays have the same length
        if (
            _newAccessLevels.length != _newTicketPrices.length ||
            _newTicketPrices.length != _newWhitelists.length ||
            _newAccessLevels.length != _newWhitelists.length
        ) revert();

        // Check if the caller is an event manager
        if (!checkIfCallerIsEventManager(_eventId, _msgSender()))
            revert DecastGating__UserIsNotAnEventManager();

        for (uint256 i = 0; i < _newAccessLevels.length; ++i) {
            // Check if the access level already exists for the event
            if (checkAccessLevelExists(_eventId, _newAccessLevels[i]))
                revert DecastGating__AccessLevelAlreadyExists();

            // Generate a new token ID for the access level
            uint256 tokenId = generateTokenId(
                _eventId,
                _msgSender(),
                _newAccessLevels[i]
            );

            // Update mappings with the new access level information
            s_eventIdToTokenIds[_eventId].push(tokenId);
            s_eventIdToAccessLevels[_eventId].push(_newAccessLevels[i]);
            s_tokenIdToTicketPrice[tokenId] = _newTicketPrices[i];
            s_tokenIdToWhitelist[tokenId] = _newWhitelists[i];
        }
    }
```

Explanation:

The function begins by verifying whether the caller is authorized to register access levels for the specified event. This is done by checking if the caller is an event manager using the checkIfCallerIsEventManager function. If the caller is not authorized, the function reverts the transaction to maintain security.

Next, the function checks if each access level being registered already exists for the event by calling the checkAccessLevelExists function. If any access level already exists, indicating a duplication attempt, the function reverts the transaction to prevent conflicts.

If the access level is new, the function proceeds to generate a new token ID for the access level using the generateTokenId internal function. It then updates the storage mappings with the information related to the new access levels. Specifically:

  • It appends the new token ID to the array of token IDs associated with the event.

  • It adds the new access level name to the array of access levels for the event.

  • It assigns the provided ticket price and whitelist status to the respective token ID in the storage mappings.

Overall, this function facilitates the registration of new access levels for events, ensuring that event managers can define various ticketing options and configurations tailored to their specific needs.

Last updated