You are here

function biblio_parse_field_type_data_csv in Bibliography Module 7.2

Gets data from biblio.field.type.data.csv and returns it as an array

@todo remove this after development. I'm only keeping it for the time being, so that I can retrieve data easily during development.

File

includes/biblio.fields.inc, line 107

Code

function biblio_parse_field_type_data_csv() {
  $csv_file = drupal_get_path('module', 'biblio') . '/misc/biblio.field.type.data.csv';
  $file_handle = fopen($csv_file, 'r');

  // array containing an array for each row in the csv
  $file_data = array();

  // the first line containing column names
  $header_line = fgetcsv($file_handle, 10000, ",");
  $info = entity_get_info('biblio');
  $fields = field_info_fields();
  while (!feof($file_handle)) {

    // the rest of the lines in the csv containing actual field data
    $row = fgetcsv($file_handle, 10000, ',');

    // Convert the human-readable name of the pubtype to machine name
    $bundle = str_replace(' ', '_', trim(strtolower($row[0])));

    // only for bundles that exist...
    if (isset($info['bundles'][$bundle])) {
      foreach ($header_line as $key => $field_name) {

        // only for fields that exist...
        if (isset($fields[$field_name]) && $row[$key] != '' && $row[$key] != '~') {
          $file_data[$bundle][$field_name] = $row[$key];
        }
      }
    }
  }
  fclose($file_handle);
  ksort($file_data);
  return $file_data;
}