Changes between Version 14 and Version 15 of S3XRC/ResourceReport
- Timestamp:
- 08/28/10 19:32:51 (14 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
S3XRC/ResourceReport
v14 v15 4 4 == Report Function for your Resource == 5 5 6 === The Idea ===6 === The idea === 7 7 8 8 You have a module {{{xxx}}} and within it a resource {{{yyy}}}, which has a number of components. You're providing CRUD functions for the resource and its components using {{{shn_rest_controller()}}}. … … 12 12 This tutorial shows you how this can be integrated in the REST interface of your resource. 13 13 14 === Creating a Custom Method Handler === 15 16 The reporting function shall be added as a custom method handler. 17 Add this function to your model file and add it as a method to your resource, like: 14 === Techniques to use === 15 16 ==== Creating a custom method handler ==== 17 18 Reporting is a method of your resource, the reporting function will therefore be implemented as a custom method handler. 19 20 Add the reporting function to your model file, and add it as a method to your resource, like: 18 21 19 22 {{{ … … 46 49 meaning, it already implements a RESTful API for your reporting function, e.g. does the parsing/validating of the URL for you, implements the full range of URL queries for your resource and so forth. Nothing you need to care about now. 47 50 48 === Providing different Report Formats === 49 50 As mentioned before, you want to provide the report in various formats. 51 To know which format has been requested, use r.representation inside the method handler: 51 ==== Providing different Report Formats ==== 52 53 You want to provide the report in various formats, hence you need to know what format the user has requested. The best way is to check for the format that has been specified in the URL. 54 55 To know which format has been specified, simply use r.representation inside the method handler: 52 56 53 57 {{{ … … 95 99 }}} 96 100 97 === How to get at the data===101 ==== How to get at the data ==== 98 102 99 103 How can you find out which data have to be processed by your reporting function, and yet more important: how can you get at them? … … 101 105 {{{r}}} (the {{{S3Request}}} object) contains an interface to your resource as {{{S3Resource}}} object in: {{{r.resource}}} 102 106 103 And this is what you can use to access yourdata. Some examples:107 And this is what you can use to easily access the resource data. Some examples: 104 108 105 109 {{{ … … 145 149 146 150 147 === The sum of all values in a field... === 148 149 The case: 151 === The concrete case: Total costs within a time interval === 152 150 153 Your resource contains a "timestmp" field (type datetime) and a field "cost" (type double), and now the user shall select a time interval in aform, and your report function shall provide the sum of all "cost" for those records with a timestmp within the selected time interval. 151 154 152 155 Let's go: 153 154 156 First of all, we implement our method handler as before: 155 157