Created
March 5, 2013 10:12
-
-
Save andylolz/5089259 to your computer and use it in GitHub Desktop.
Hack to get DataGrab (roughly) working with Assets 2, and Assets 2 inside a Matrix field.
This file contains 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
diff --git a/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_assets.php b/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_assets.php | |
index ea3f8ec..4f22dc2 100644 | |
--- a/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_assets.php | |
+++ b/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_assets.php | |
@@ -24,8 +24,21 @@ class Datagrab_assets extends Datagrab_fieldtype { | |
while( $subitem = $DG->datatype->get_sub_item( | |
$item, $DG->settings["cf"][ $field ], $DG->settings, $field ) ) { | |
- $data[ "field_id_" . $field_id ][] = $subitem; | |
- | |
+ $parts = explode('/', $subitem); | |
+ $this->EE->db->select( "exp_assets_files.file_id" ); | |
+ $this->EE->db->from( "exp_assets_files" ); | |
+ $this->EE->db->join( "exp_assets_folders", "exp_assets_files.folder_id = exp_assets_folders.folder_id" ); | |
+ $this->EE->db->join( "exp_assets_sources", "exp_assets_folders.source_id = exp_assets_sources.source_id" ); | |
+ if (count($parts) > 2) { | |
+ $this->EE->db->where( "exp_assets_folders.full_path", implode('/', array_slice($parts, 1, -1)) . '/' ); | |
+ } | |
+ $this->EE->db->where( "exp_assets_files.file_name", end($parts) ); | |
+ $this->EE->db->where( "exp_assets_sources.name", $parts[0] ); | |
+ $query = $this->EE->db->get(); | |
+ | |
+ foreach( $query->result_array() as $row ) { | |
+ $data[ "field_id_" . $field_id ][] = $row["file_id"]; | |
+ } | |
} | |
} | |
} | |
diff --git a/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_matrix.php b/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_matrix.php | |
index 8782e4c..a900e56 100644 | |
--- a/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_matrix.php | |
+++ b/assets/third_party_code/ajw_datagrab/fieldtypes/datagrab_matrix.php | |
@@ -156,6 +156,25 @@ class Datagrab_matrix extends Datagrab_fieldtype { | |
// Add data to row matrix | |
switch( $columns[ $col_id ]["col_type"] ) { | |
+ case "assets" : { | |
+ $parts = explode('/', $subitem); | |
+ $this->EE->db->select( "exp_assets_files.file_id" ); | |
+ $this->EE->db->from( "exp_assets_files" ); | |
+ $this->EE->db->join( "exp_assets_folders", "exp_assets_files.folder_id = exp_assets_folders.folder_id" ); | |
+ $this->EE->db->join( "exp_assets_sources", "exp_assets_folders.source_id = exp_assets_sources.source_id" ); | |
+ if (count($parts) > 2) { | |
+ $this->EE->db->where( "exp_assets_folders.full_path", implode('/', array_slice($parts, 1, -1)) . '/' ); | |
+ } | |
+ $this->EE->db->where( "exp_assets_files.file_name", end($parts) ); | |
+ $this->EE->db->where( "exp_assets_sources.name", $parts[0] ); | |
+ $query = $this->EE->db->get(); | |
+ | |
+ foreach( $query->result_array() as $row ) { | |
+ $matrix[ $row_num ][ "col_id_".$col_id ][] = $row["file_id"]; | |
+ $empty = FALSE; | |
+ } | |
+ break; | |
+ } | |
case "playa" : { | |
$matrix[ $row_num ][ "col_id_".$col_id ] = array(); | |
$this->EE->db->select( "entry_id" ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment