Need OOP design advice

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Need OOP design advice

Post by jmut »

Say we have a report system to display.
Making report for different periods (monthly, weekly statistics).
Also should display report on html,clear text etc. (hence different type of output).

What would be an efficient way to design/organize classes so that the system is flexible.
So for example there is factory method that determines if it is monthly weekly etc.
There is factory method to build the output etc.

Should I create abstract class for a statistic
and then extend for weekly stats with html out
weekly stats for clear text output

The idea is to be flexible as to adding for example yearly view or other means of showing the report hte whole stuff is easily expandable.
Any comments - design idea woulld be great.

Thanks for spending time reading this.

btw using php5 :)
GRemm
Forum Newbie
Posts: 17
Joined: Fri Jul 08, 2005 3:37 pm
Location: California
Contact:

Post by GRemm »

What are the reports composed of?

If the weekly report is the basic unit and the yearly is simply 52 weekly reports then a good idea would be to have each piece of weekly data as an object and the report as a container / statistics generator for weekly report objects.

If you want a yearly report you load the report with 52 weekly objects and have the container class compute statistics on the collection. If you need a month load it with 4 objects. If you need a week load it with only one.

As for output you could use an intercepting filter / decorator / rendering class (with subclasses for output types) to take the raw report data and spit it out as text / html etc. The easiest storage for this might be xml or some sort of php object notation. For object rendering with a lot of flexibility you could look at smarty as a template system. You can actually use the mime type header to send plain text to the browser.

Using gzip and file functions you could easily zip the report and send it as a download prompt to the user or provide a link to a compressed file for download from the html rendered view screen. Php can also spit out excel files / csv files for viewing in a spreadsheet.

If your report are structured so the actual data (not the summaries / statistics) changes from report type to report type then you could write a generic report object class and extend the functionality for each specific report into subclasses and write a container / controller class to handle the various types by invoking an abstract factory based on the type returned from the individual report object subclass.

***

On a totally unrelated note.. someone needs to work in some clever bbcode system / tag system for embedding uml into forums. Doesn't seem like it would be too hard using gd / tag replacement / tag parameters.

***
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

Thanks a lot for your pointers.
The format of the reports is pretty much the same.
Once I have to show stuff by weekly bases (there is calendar....you choose which week to see stats for.)
And there is monthly view (the same as week but instead of week days there are months names as report headings)

Actually getting data perday basis is just a simple sql query for the required week.
Then a small countTotal function and that is it.
The same goes with monthly but instead of DAYNAME(date_to_consider) I take MONTHNAME(date_to consider).

I am using smarty for this. Will see how exactly to implement it best.
And the output required so far is html and xls.
Will use ExcelWriter form PEAR for this one.

Anyway, thanks again.
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post by BDKR »

I would say there are a couple of distinct "stages" here required for building your report.

1) Determination of time frame / range
2) Data gathering
3) Formatting

The architecture for 1 and 2 should be simple assuming (talking about number 1) the UI is fixed and (talking about number 2) the data gathered is a constant other then the requested time frames.

3 is where the flexibility is required, but it seems as simple as determing the requested format and instantiating the correct object after that. A controller would make a lot of sense right here.

That's what I see.

Cheers,
BDKR
Post Reply