Creating custom reports

New reports can be created in Admin > System > Reports. A ResourceSpace report is simply an SQL query - those with knowledge of SQL should be able to write new reports given an understanding of the ResourceSpace database. You can view and edit existing reports within the system from the same location.

Example: Create report for pending submissions

The following line of SQL would create a report that showed all the resources pending submission.

select * from resource where archive=-2;

Note: Allowing date range selection

The following lines of SQL would allow a report to recieve a date range input from the front end.

# --- date ranges
# Make sure date is greater than FROM date
(d.year=[from-y] and d.month>[from-m])
(d.year=[from-y] and d.month=[from-m] and>=[from-d])
# Make sure date is less than TO date
(d.year=[to-y] and d.month<[to-m])
(d.year=[to-y] and d.month=[to-m] and<=[to-d])

An alternative date range SQL can also be:

AND >= date('[from-y]-[from-m]-[from-d]')
AND <= adddate(date('[to-y]-[to-m]-[to-d]'), 1)

Report applied to search results

From version 9.6+ ResourceSpace will have a new report placeholder - [non_correlated_sql] - which will allow a particular report to be run only on search results.

The placeholder will only add the actual search query. The user writing the report can then use either the IN/ NOT IN clause to filter the set based on the report needs. For example, this is how the default report "Resource download summary (search results)" is written:

  SELECT r.ref AS 'Resource ID',
            SELECT `value`
              FROM resource_data AS rd
             WHERE rd.resource = r.ref
               AND rd.resource_type_field = [title_field]
             LIMIT 1
         ) AS 'Title', 
         count(*) AS 'Downloads' 
    FROM resource_log rl
    JOIN resource r on rl.resource = r.ref
   WHERE rl.type = 'd'
     AND >= date('[from-y]-[from-m]-[from-d]')
     AND <= adddate(date('[to-y]-[to-m]-[to-d]'), 1)
     AND r.ref IN [non_correlated_sql]
GROUP BY r.ref
ORDER BY 'Downloads' DESC;

These reports will only be runnable from a search result. Go to Advanced search, do a search and view the search results. From the top unified dropdown actions, you can select Run report on these results which will take you to the report page.

Please note that the report page will filter out reports depending how you've reached the page:

  • Showing normal reports when coming from Admin > Reports
  • Showing only reports supporting search results when coming from a search