tags:

views:

103

answers:

3

I'm working on a report that displays information about our company's sales locations. One of the bits of information is the 'last visit date' of the location. If the location has never been visited, I have to display (in the current language) 'Never' in red. There are several values like this one, this is just the example I'm using.

Currently my location model returns NULL (direct from the database) if the location hasn't been visited.

So my question is, do I use the

  1. View to check for the NULL value, and then display 'Never' in red.
  2. Controller to check for the NULL value, change it to 'Never' and then the View would detect 'Never' and display that in red
  3. Should the Model call some isValid() method with the 'last visit date' which could check all manner of business rules(false on NULL, older then 6 months, etc) then return the date or 'Never' along with a flag to tell the view to display the value in red or black.

With #3, I think that is the most flexible. But is this simple case too soon to add that advanced functionality?

Any ideas are very appreciated!

Note: Our company's framework is some in-house PHP framework written many years ago.

+2  A: 

Option 3 would be the best decision. The model should be responsible for all of the data values, the controller the business logic, and the view presentation.

It's always a good idea to keep the views as simple as possible and avoid embedding code in them. While you could do handle this in the controller it would need to be duplicated in each controller which utilizes this model. That could create problems down the road if you needed to make a change.

Doomspork
This is what I want to do. I am worried about changing the Model return value as I don't know what else depends on that NULL value at this time. I may still have to put this off.
ryanday
The model can have additional methods on it, there is no restriction on that. You could simplify have a helper method that returned what you needed for the view and was only accessed for views.
Doomspork
+4  A: 

Since the view has to examine the value anyway to determine whether it should be red or not, I see no reason not to let it deal with null directly. After all, the "Never" is a display detail.

Pesto
This may be the way I end up going. The view has to check something no matter what, and this would keep things simple.
ryanday
+1  A: 

It's the responsability of the model to give meaningful data. In your case null is probably as meaningful as you can get. My approach to MVC (there are as many approaches as people using MVC) is to use a ViewHelper class: 1) to decouple view and model 2) to return data to the view in a way optimized for presenting

Note: Different views can have different ViewHelpers. Note: $this->salesLocations->lastVisit would pass by a SalesLocationViewHelper method.

hope this makes sense

koen