01.11 php saved
robby
Tags add more
afterFind, columnPrefix and legacy data  
Note
The beginnings of my search for an elegant column prefix solution.
  1.     // Strip out column names
  2.     function afterFind ($results, $primary = false){
  3.  
  4.         // Ignore non-array data. These aren't the droids we're looking for
  5.         if ( !is_array($results) ) {
  6.             return $results;
  7.         }
  8.  
  9.         // Figure out what prefixes need to be stripped from which models
  10.         $stripPrefixes = array();
  11.  
  12.         foreach( array_keys($results[0]) as $thisModel ){
  13.             if ( $thisModel == $this->name ) {
  14.                 if ( !empty($this->columnPrefix) ) {
  15.                     $stripPrefixes[$thisModel] = $this->columnPrefix;
  16.                 }
  17.             } elseif ( isset($this->{$thisModel}) ) {
  18.                 if ( !empty($this->{$thisModel}->columnPrefix) ) {
  19.                     $stripPrefixes[$thisModel] = $this->{$thisModel}->columnPrefix;
  20.                 }
  21.             }
  22.         }
  23.  
  24.         // Now, loop through the results returned and strip out column names
  25.         foreach( array_keys($results) as $recordKey ){
  26.  
  27.             foreach( array_keys($results[$recordKey]) as $thisModel ){
  28.                 if ( !isset($stripPrefixes[$thisModel]) ) {
  29.                     continue;
  30.                 }
  31.  
  32.                 $stripLen = strlen($stripPrefixes[$thisModel]);
  33.                 foreach( array_keys($results[$recordKey][$thisModel]) as $thisField ){
  34.                     $results[$recordKey][$thisModel][substr($thisField, $stripLen)] = $results[$recordKey][$thisModel][$thisField];
  35.                     unset($results[$recordKey][$thisModel][$thisField]);
  36.                 }
  37.             }
  38.         }
  39.  
  40.         return $results;
  41.     }
  42.  
Parsed in 0.057 seconds, using GeSHi 1.0.7.14

Modify this Paste