# Article Export Functionality

This document describes the export functionality that has been added to the articles table in the Filament admin panel.

## 🎯 Export Features

### 1. Export All Articles
- **Location**: Header action button in the articles list page
- **Label**: "Export All"
- **Icon**: Download arrow icon
- **Functionality**: Exports all articles (respecting user permissions) to Excel format
- **File Format**: .xlsx
- **File Naming**: `articles-YYYY-MM-DD-HH-MM-SS.xlsx`

### 2. Export Selected Articles
- **Location**: Bulk actions in the articles table
- **Label**: "Export Selected"
- **Icon**: Download arrow icon
- **Functionality**: Exports only the selected articles to Excel format
- **File Format**: .xlsx
- **File Naming**: `selected-articles-YYYY-MM-DD-HH-MM-SS.xlsx`

## 📊 Exported Data Fields

The exported Excel file includes the following columns:

1. **ID** - Article ID in the system
2. **Title** - Article title
3. **Keywords** - Article keywords
4. **Article Type** - Type of article
5. **Journal** - Journal name
6. **Publication Date** - Date of publication
7. **Overall Score** - Validation score percentage
8. **State** - Current processing state
9. **Created At** - When the article was added to the system
10. **Original Article URL** - Direct link to the original article on PMC
11. **Email Preview** - Link to the email preview page

## 🔐 User Permissions

### Admin Users
- Can export all articles regardless of state
- Can export any selected articles

### Non-Admin Users
- Can only export articles with state 'summarized'
- Export actions automatically filter to show only accessible articles

## 🚀 How to Use

### Export All Articles
1. Navigate to the Articles section in the admin panel
2. Click the "Export All" button in the top-right corner
3. The file will download automatically

### Export Selected Articles
1. Navigate to the Articles section in the admin panel
2. Select one or more articles using the checkboxes
3. Click the "Export Selected" button in the bulk actions
4. The file will download automatically

## 🔧 Technical Implementation

### Routes
- `GET /export/articles/all` - Export all articles
- `GET /export/articles/selected` - Export selected articles

### Controller Methods
- `NewController@exportAllArticles()` - Handles export of all articles
- `NewController@exportSelectedArticles()` - Handles export of selected articles

### Dependencies
- **PhpSpreadsheet**: Used for Excel file generation
- **Filament Actions**: Used for UI components

## 📝 Notes

- Files are generated as temporary files and automatically deleted after download
- Export respects all current filters applied to the table
- Large exports may take a few moments to process
- The export functionality uses the same permission system as the article viewing

## 🐛 Troubleshooting

If exports are not working:

1. **Check Permissions**: Ensure you have the correct user permissions
2. **Check Database Connection**: Ensure the database is accessible
3. **Check File Permissions**: Ensure the temp directory is writable
4. **Check PhpSpreadsheet**: Ensure the package is properly installed

## 🔄 Future Enhancements

Potential improvements for the export functionality:

- Add CSV export option
- Add PDF export option
- Add custom field selection for export
- Add export scheduling
- Add export history tracking 
