Hi,

[Warnung: pretty long email about trying to make use of MVC and php5]

I'm seeking some input in (architectually) designed my code so I can reach the 
following:

- "overview" from the subject is defined as a table rows/columns displaying simple or 
complex results from an sql query
- it is part of a backend for administrating data, e.g. displayig the procuts, 
customers, etc

In simple ascii, the visual output would be:

id | name     | last login
---+----------+-----------
1  | schubert | yesterday
2  | haydn    | last year

Ok, so far nothing new; I just want to make clear what I'm talking about.

The feature list this overview should have:
- sortable rows, i.e. clicking on a column header sorts the select row
- clicking on a row links to editing the specific entry
- optional: provides ability (e.g. via small graphical buttons) to move an entry 
up/down (aka sorting)
- optional: display a checkbox next to each entry; UI to delete all selected entries

To achive this, I've currently separated the code into a few classes:

abstract class OverviewController
abstract class OverviewData
interface OverviewView

OverviewData:
        "Knows" what colums are defined and how they're set up (e.g. which columns are sortable, 
what type they display) and also "knows" how to fetch the data and convert it into a format so 
OverviewView can work with it.

OverviewView:
        "Knowns" how to draw the output, e.g. the table/columns/rows/links for the 
client (browser)

OverviewController:
        Takes OverviewData and OverviewView and controls them to generated the 
relevant output.

The classes only define the basic architecture and don't work immidiately. The 
implementation of OverviewView should idially work with any class extending 
OverviewData; so I've kept CustomOverviewView generic to handle this.

As I've started working on it, a few things have shown up which I need to resolve as 
intellegent as possible so I don't screw up the design:

- How to a build the the links in the OverviewView output which control simple things 
like sorting for a specific column?
What's the deal here? Well, OverviewView should be generic, not bound to anything specific. So when I integrate it into a application, the 
application definitely needs some GET/POST parameters which need to be present to handle its own state, not related to the OverviewView at all. So 
I started to give each instance of CustomOverviewView a distinct "name" by which the OverviewView known it can refer to itself without 
interfering with other variables used in the GET request. In the specific implementation, I'm using "name" as the basis for an array, so 
every state which needs to be remembered will be a entry in that array, e.g. "name" is "procuctView" then all states will be 
handled as "productView[sortby]", etc. But this alone doesn't fix the complete problem. There are certainly parameters which 
additionally need to be passed from the application itself. Therefore I've added a "setParameterGetCallback" method on the OverviewView 
interface by which a callback handler will be
set; this callback is "into" the application itself, because this is the best place (I 
could think of) where this should be handled. The application _knows_ its state. The callback 
handler just additionally takes the parameters which need to be set by the CustomOverviewView 
implementation and returns the complete content for the GET request (e.g. for the 
href-Attribute).

The next thing about sorting is: somewhere I need to know which column to sort. Idially 
(for me) this would be in the OverviewData implementation. Because this is where I fetch 
the data and I plan to have it fetched and stored for OverviewView right the way it is 
needed -> sorted correctly by the choosen column.

On the other hand, I need to sorting column information still in the OverviewView 
implementation too, because I need visual indication (up/down arrow).


- The next thing: when I want to move an entry up/down (e.g. manuall sort), basically I'm fireing off a command: this entry ID <whatever> should be sorted UP. But I'm not quite sure where these action should be done. Is it part of the OverviewData implementation to execute this action (because it already does some action for sorting after the right column, albeit this is more a "read only" thing, whereas sorting an entry manually is like "writing" to the database, updating existing entries). Or is it a Controller thing? Or something I haven't yet thought off?

And still, things I haven't completely considered are:
- searching (not too different from sorting, anyway)
- deleting (same problem as moving manually entries I guess: need to write to the 
database, but where from?)

For simplicity I haven't included user-level permissions yet, but they've to come (but 
may currently be part of the Application itself).

I do not want to make the design too complex; I want to make it "practical". The current design 
for me "is practical". I just use another CustomOverviewView and the table interface is 
different, I just use another CustomOverviewData and have completely diffrent data there for viewing. Hmm, 
reading this line, I guess this answers my question, where I should put the database writing part: into 
the OverviewData class ...

thanks in advance for any hints / suggestions / poiners,

- Markus

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Reply via email to