Importazioni dati tabella.
Allora sò di essere quasi off topic ma ho bsogno della combricola degli smanettoni per importare dati da excel a Drupal con feeds.
Ho una sitazione di questo genere.
Tipo di Contenuto 1 "Tabella1 in Excel" con 2 campi:
Id1 Titolo1
Id2 Titolo2
Id3 Titolo3
Tipo di contenuto 2 "Tabella2 in Excel" relazionato al Tipo di contenuto 1, con 3 campi
IdA | Paragrafo1 | Reference_Id1
idB | Paragrafo2 | Reference_Id1
IdC | Paragrafo3 | Reference_Id2
IdD | Paragrafo 4 | Reference_Id3
IdE | Paragrafo 5 | Reference_Id3
Avrei bisogno di fare una query di aggregazione per ottenere questa situazione.
Id1| Titolo1| IdA,idB
Id2| Titolo2| IdC
Id3|Titolo3 | IdD, IdE
In modo da poter importare i dati con feeds e sottomoduli.

Risposte
Ciao, gli script vanno
Ciao, gli script vanno fatti... semplice!
<?php /** * Form builder function to allow choice of which batch to run */ function companycsv_imports_form($form, &$form_state) { $form['import'] = array( '#type' => 'fieldset', '#title' => t('Import'), '#collapsible' => false, '#collapsed' => false, ); $form['import']['batch'] = array( '#type' => 'select', '#title' => 'Select', '#description' => 'I files csv si trovano nel modulo', '#options' => array( '0' => t('Importa da export--aziende.csv'), ), ); $form['import']['submit'] = array( '#type' => 'submit', '#attributes' => array('onclick' => 'alert("Do you confirm?");'), '#value' => 'Submit'); return $form; } /** * Handles import form validation. */ function companycsv_imports_form_validate($form, &$form_state) { $options = &$form_state['values']; } /** * Form submit */ function companycsv_imports_form_submit($form, &$form_state) { @set_time_limit(720); $options = &$form_state['values']; $_SESSION['http_request_count'] = 0; if ($options['batch'] == 0) { /* * active */ $batch = companycsv_imports_active_batch_import(); } batch_set($batch); } /** * Implements _batch process * */ function companycsv_imports_active_batch_import() { $operations = array(); $c = 1; $num_rows = 0; $limit = variable_get('companycsv_imports_limit_rows', 65356); $file_filepath = 'sites/all/modules/companycsv_imports/content/export--aziende.csv'; if (!file_exists($file_filepath)) return drupal_set_message(t('Attenzione il file %$file_filepath non esiste. Si prega di povvedere per il funzionamento dello script.', array('%file_handle' => $file_filepath)), 'error'); if (($f = fopen($file_filepath, "r")) !== false) { $counttotal = count(file($file_filepath)); while (($row = fgetcsv($f, filesize($file_filepath), ",")) !== false) { if ($c > 0 ) { $operations[] = array('companycsv_imports_active_batch_operation', array( $c, $row, $rid, t('(Operation for total %counttotal object)', array('%counttotal' => $counttotal)), )); } $c++; } fclose($f); } $batch = array( 'operations' => $operations, 'finished' => 'companycsv_imports_batch_finished', 'title' => t('Import Batch Operation'), 'init_message' => t('Batch is starting...'), 'progress_message' => t('Import product batch mode: processed object @current'), 'error_message' => t('Batch incurring error...')); return $batch; } /** * Implements operation */ function companycsv_imports_active_batch_operation($c, $row, $rid, $operation_details, &$context) { if (!isset($context['results']['time'])) { $context['results']['time'] = microtime(true); } $hasrecord = db_query("SELECT COUNT(uid) FROM {users} WHERE uid = :uid", array(':uid' => (int)$row[0]))->fetchField(); if ($hasrecord) { // } else { // $node = new stdClass(); // We create a new node object $node->type = "company"; // Or any other content type you want $node->title = "Your title goes jere"; $node->language = LANGUAGE_NONE; // Or any language code if Locale module is enabled. More on this below * $node->path = array('alias' => 'your node path'); // Setting a node path node_object_prepare($node); // Set some default values. $node->uid = 1; // Or any id you wish // Let's add standard body field $node->body[$node->language][0]['value'] = 'This is a body text'; $node->body[$node->language][0]['summary'] = 'Here goes a summary'; $node->body[$node->language][0]['format'] = 'filtered_html'; // If field has a format, you need to define it. Here we define a default filtered_html format for a body field if($node = node_submit($node)) { node_save($node); drupal_set_message('submitted successfully'); } } // ultimate action results scanning $context['results'][] = 'Ultimate action results: ' . $c; // Optional message displayed under the progressbar. $context['message'] = t('Loading file product @c | ', array('@c' => $c)) . ' ' . $operation_details; _companycsv_imports_update_http_requests(); } /** * Implements http request */ function _companycsv_imports_update_http_requests() { if (isset($_SESSION['http_request_count'])) $_SESSION['http_request_count']++; } /** * Implements http request */ function _companycsv_imports_get_http_requests() { return !empty($_SESSION['http_request_count']) ? $_SESSION['http_request_count'] : 0; } /** * Batch finished callback used always */ function companycsv_imports_batch_finished($success, $results, $operations) { if ($success) { drupal_set_message(t('%count results processed in @requests HTTP requests see @path', array( '%count' => count($results), '@requests' => $_SESSION['http_request_count'], '@path' => 'Home » Administration » Reports » dblog', ))); } else { // An error occurred. // $operations contains the operations that remained unprocessed. $error_operation = reset($operations); drupal_set_message(t('An error occurred while processing @operation with arguments : @args', array('@operation' => $error_operation[0], '@args' => print_r($error_operation[0], true))), 'error'); } }Il codice sopra è solo un esempio: da un modulo custom si accede al form che avviato fa partire il processo batch di importazione da csv. L'oggetto row passato alla funzione va compilato ad ok. Vengono cosi creati i nodi da file csv, piu semplice che da xls.
Vedi il modulo examples per la comprensione del processo batch.