# EFET-Intranet Project Guide

## Project Overview
This is an intranet application for EFET (European Federation of Energy Traders) built using Laravel. The application includes an interactive map, document management, member management, committee workgroups, and various other features.

## Key Components

### Interactive Map
- The map feature uses MapItem and MapInformation models
- Each country (MapItem) can have multiple MapInformation records
- Filters include: countryId, counterpartyType, settlementType, and relevantCommodity
- Every MapItem has 24 possible combinations of MapInformation

### Content Types
- The application uses a custom ContentType system
- Models extend ContentTypeModel
- Utilize full() scope for queries which automatically applies status checks

### Authentication
- API routes use Sanctum authentication
- CheckUserMemberState middleware ensures users have appropriate permissions

## Development Guidelines

### API Endpoints
- All API endpoints are in routes/api.php under the '/v1' prefix
- Protected routes use the 'auth:sanctum' middleware
- Controller naming convention: Api\[Model]Controller

### Coding Standards
- Use type hints for function parameters and return values
- Camel case for method names (e.g., getMapInfoFilters)
- Snake case for database column names (e.g., map_item_id)
- Document complex logic with comments

### Models
- All models are in the App\Models namespace
- Many models use LanguageSupportTrait for multi-language content
- Query scope 'full()' is available on content type models

### Services
- Business logic is encapsulated in service classes
- Services are in App\Libs\Services namespace
- Use dependency injection for services in controllers

## Common Tasks

### Working with MapItems
- Always filter by 'status' => 'published'
- When listing MapItems, use the full() scope
- Filter MapInformation by map_item_id, counterparty_type, settlement_type, and relevant_commodity

### Form Requests
- Input validation is handled by Form Requests
- Requests are in App\Http\Requests\Api namespace
- Use SanitizesInput trait to clean inputs

### File Handling
- Upload files through Api\FileController@uploadFile
- Download files through Api\FileController@downloadFile
- Paths are relative to storage directory

## Database Structure

### Key Tables
- entries: Contains pages and other content entries
- map_items: Countries for the interactive map
- map_informations: Information related to map items
- users: User accounts
- members: Organization members
- committees: Committees information
- work_groups: Working groups information

### Recently Added Features
- password_protected field to entries table for protected content
- MapItemService.getMapInfoFilters for dynamic filtering of map data

## API Filters Logic

### Map Information Filters
When working with the interactive map filters:

1. Countries (MapItems): 
   - Always show all published countries regardless of filter selection
   - If a country is selected, move it to the top of the list
   - If a selected country does not exist or is not published, return all countries with empty filter lists

2. Other Filters (counterpartyType, settlementType, relevantCommodity):
   - When no filter is selected, show all available options based on other selected filters
   - When a filter is selected, always include it in the response
   - Additionally include all other valid options that would return results

3. Filter Option Formatting:
   - counterpartyTypes: Replace underscores with spaces and capitalize
   - settlementTypes: Simply capitalize
   - relevantCommodities: Use custom mapping (e.g., power_gas → Power/Gas)

## Project Structure Notes

- Custom database Eloquent collection: ContentTypeCollection
- Extensive use of trait-based functionality (LanguageSupportTrait, SanitizesInput)
- XSS cleaning via XSSCleanFilter
- Backend configuration in /config/backoffice/ directory
