PHP code example of trendyminds / craft-reporter

1. Go to this page and download the library: Download trendyminds/craft-reporter library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

trendyminds / craft-reporter example snippets




use craft\elements\Entry;
use craft\elements\Asset;

return [
    // The name to use throughout the control panel (defaults to "Reporter")
    'displayName' => 'Reports',

    // The asset volume handle where your reports should be saved
    // NOTE: Your reports are publicly accessible if your volume has "Assets in this volume have public URLs" enabled
    'volume' => 'uploads',

    // An optional folder path if you would like to nest the reports in a specific directory
    'folder' => 'resources/reports',

    // An optional batch size to use when processing reports (defaults to 100)
    'batchSize' => 100,

    // An array of reports to produce
    'reports' => [
        'pages' => function () {
            return [
                'name' => 'All Pages',
                'description' => 'A simple export of all the pages on the site.',
                'elementType' => Entry::class,
                'criteria' => [
                    'section' => 'pages'
                ],
                'transformer' => function (Entry $entry) {
                    return [
                        "id" => $entry->id,
                        "title" => $entry->title,
                        "url" => $entry->url,
                    ];
                }
            ];
        },

        'allImages' => function () {
            return [
                'name' => 'Uploaded Images',
                'description' => 'A list of all images uploaded into Craft',
                'elementType' => Asset::class,
                'criteria' => [
                    'kind' => 'image'
                ],
                'transformer' => function (Asset $asset) {
                    // Skip example
                    // Ignore assets that have an even number for an ID
                    if ($asset->id % 2 === 0) {
                        return [];
                    }

                    return [
                        "id" => $asset->id,
                        "title" => $asset->title,
                        "filename" => $asset->filename,
                    ];
                }
            ];
        },
    ]
];