Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 0.9.3

Request #3157 Use get* method(s) if available
Submitted: 2005-01-11 00:20 UTC
From: justinpatrin Assigned: asnagy
Status: Closed Package: Structures_DataGrid
PHP Version: Irrelevant OS: Irrelevant
Roadmaps: (Not assigned)    
Subscription  


 [2005-01-11 00:20 UTC] justinpatrin
Description: ------------ This doesn't support overloading, but overloading is dangerous in PHP4 anyway. This patch uses a get method for a field if it exists. Reproduce code: --------------- @@ -218,7 +218,10 @@ // Build Fields $rec = array(); foreach ($fieldList as $fName) { - if (isset($this->_dataobject->$fName)) { + $getMethod = 'get'.$fName; + if (method_exists($this->_dataobject, $getMethod)) { + $rec[$fName] = $this->_dataobject->$getMethod(); + } elseif (isset($this->_dataobject->$fName)) { $rec[$fName] = $this->_dataobject->$fName; } else { $rec[$fName] = null;

Comments

 [2005-01-11 18:42 UTC] arne at gellhaus dot de
I propose a change to how the method is called. When called with a reference to the calling object the get*-method is able to return values depending on the caller: $this->_dataobject->$getMethod(&$this); To make my case clear: the get*-method is now able to call get_class() and return a human readable string to DataGrid and a array to FormBuilder.
 [2005-01-19 23:07 UTC] justinpatrin
After further consideration, this seems like a very application specific feature. It could be quite possible for a getter to have an optional parameter that expects something totally different, so sending in $this would be just wrong. You *could* use debug_backtrace() to get the calling class. Also, what kind of field is this? If you make it a linked field the linked object's display value will automatically be pulled with the other FormBuilder enhacement patch.
 [2005-01-20 11:32 UTC] ylf at xung dot org
I believe that overriding the dataobject's fetch() method is sufficient for many customization needs. Now, if someone wants to use getters and setters, this should only be possible with the dataobject's default ones (no parameter). And because this may create a conflict in case some of these methods expect a parameter, there should be an option to enable/disable calling them, which IMHO should be turned off by default. Of course, there may be a need to retrieve data according to some contextual parameters, but can't this be achieved by using column formatter callbacks ? If so, one could use any method, wether they are dataobject getters or not.
 [2005-01-24 16:16 UTC] asnagy at webitecture dot org
Well their is a problem with using the column formatter, you have to make another query instead of including it with your first query. I am going to not implement arne's suggestion; however, this might be a nice column extension. It might be nice to be able to pass in other elements into a get* method. For example, if you have a date as a column and you have a getDate method. You may want to pass in a format string for the date, so that you get a human readable datastring instead of a timestamp or some other date string.
 [2005-07-13 16:46 UTC] asnagy
No follow up, I am closing this.