Created
November 20, 2009 13:15
-
-
Save dogmatic69/239495 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// the view to create csv's | |
$a = array_keys( ClassRegistry::init( Inflector::singularize( $this->name ) )->_schema ); | |
$needed = array( | |
Inflector::singularize( $this->name ) => $a | |
); | |
$row = array(); | |
if ( !empty( $data ) ) | |
{ | |
foreach( $needed[key( $needed )] as $head ) | |
{ | |
$parts[] = Inflector::humanize( str_replace( '_id', '', $head ) ); | |
} | |
$row[] = implode( ',', $parts ); | |
foreach( $data as $k => $array ) | |
{ | |
$parts = array(); | |
foreach( $array[key( $needed )] as $field => $value ) | |
{ | |
if ( $field != 'id' ) | |
{ | |
if ( strpos( $field, '_id' ) && in_array( $field, $needed[key( $needed )] ) ) | |
{ | |
$parts[] = $array[Inflector::camelize( str_replace( '_id', '' , $field ) )][ClassRegistry::init( Inflector::camelize( str_replace( '_id', '' , $field ) ) )->displayField]; | |
} | |
else if ( in_array( $field, $needed[key( $needed )] ) ) | |
{ | |
$parts[] = $value; | |
} | |
else | |
{ | |
$parts[] = ''; | |
} | |
} | |
} | |
$row[] = implode( ',', $parts ); | |
unset( $parts ); | |
} | |
} | |
$csv = implode( "\n", $row ); | |
echo $csv; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment