t('Ninguno'), 'geo_ve' => t('Entidades de Venezuela'), ); $form['ubicacion'] = array( '#type' => 'fieldset', '#title' => t('Terminos de UbicaciĆ³n'), ); $form['ubicacion']['terminos'] = array( '#type' => 'select', '#title' => t('Terminos a Actualizar'), '#options' => $terms, '#description' => t('Seleccione la Lista de terminos a importar.'), ); $vocabularies = taxonomy_get_vocabularies(); $availables_vocabulary = array(); if (count($vocabularies)) { foreach ($vocabularies as $vocabulary) { $availables_vocabulary[$vocabulary->vid] = check_plain($vocabulary->name); } } $vocabulary = taxonomy_vocabulary_load(variable_get('ente_ubicacion_vocabulary', 0)); $availables_vocabulary[0] = t('Ninguno'); ksort($availables_vocabulary); $form['ubicacion']['vocabulary'] = array( '#type' => 'select', '#title' => t('Vocabulario'), '#options' => $availables_vocabulary, '#description' => t('Seleccione el vocabulario en el que se han de importar los terminos.'), ); $form['ubicacion']['submit'] = array( '#type' => 'submit', '#value' => t('Guardar Terminos'), '#submit' => array('ente_planificador_term_fields_import_form_submit'), ); } } /** * Process import country taxonomies into of drupal */ function ente_planificador_term_fields_import_form_submit($form, &$form_state) { module_load_include('php', 'ente_planificador_term_fields', '/includes/ente_planificador_geo_ve.inc'); if (!(empty($form_state['values']['terminos']))) { if ($form_state['values']['terminos'] == 'geo_ve') { $entidades = lista_entidades(); $vocabulary = taxonomy_vocabulary_load($form_state['values']['vocabulary']); _batch_ente_planificador_term_fields_states_export($entidades, $vocabulary); } } } /** * Batch add setting batch to import country taxonomies into of drupal */ function _batch_ente_planificador_term_fields_states_export($entidades, $vocabulary = 0) { module_load_include('php', 'ente_planificador_term_fields', '/includes/ente_planificador_geo_ve.inc'); $entidades = lista_entidades(); if (empty($vocabulary)) { return FALSE; } $batch = array( 'title' => t('Importando Entidades...'), 'operations' => array(), 'init_message' => t('Comenzando a importar los terminos'), 'progress_message' => t('Procesando @current Entidades de @total.'), 'error_message' => t('Ocurrio un error durante el proceso'), 'finished' => '_ente_planificador_term_fields_import_finished', ); foreach ($entidades as $id => $title) { $batch['operations'][] = array('_ente_planificador_term_fields_import_bacth', array($id, $vocabulary)); } batch_set($batch); batch_process('admin/settings/ente_planificador'); // The path to redirect to when done. } /** * Batch callback term taxonomy into the Drupal */ function _ente_planificador_term_fields_import_bacth($id_entidad, $vocabulary, &$context) { module_load_include('php', 'ente_planificador_term_fields', '/includes/ente_planificador_geo_ve.inc'); $entidad = lista_entidades($id_entidad); $edit = array( 'name' => t($entidad), 'description' => '', 'parent' => array(0), 'vid' => $vocabulary->vid, 'fields' => array( 'codigo_geo_localizacion' => array( 'value' => $id_entidad, ), ), ); $term_e = $edit; $term_e = taxonomy_save_term($term_e); $municipios = lista_municipios($id_entidad); if (count($municipios)) { // agregando los municipios $countm = 0; foreach ($municipios as $id_e => $value_m) { $edit = array( 'name' => t($value_m[1]), 'description' => '', 'parent' => array($term_e['tid']), 'vid' => $vocabulary->vid, 'fields' => array( 'codigo_geo_localizacion' => array( 'value' => $value_m[0] ), ), ); $term_m = $edit; $term_m = taxonomy_save_term($term_m); $countm++; $parroquias = lista_parroquias($value_m[0]); if (count($parroquias)) { $countp = 0; foreach ($parroquias as $id_m => $value_p) { // agregando las parroquias $edit = array( 'name' => t($value_p[1]), 'description' => '', 'parent' => array($term_m['tid']), 'vid' => $vocabulary->vid, 'fields' => array( 'codigo_geo_localizacion' => array( 'value' => $value_p[0] ), ), ); $term_p = $edit; $term_p = taxonomy_save_term($term_p); $countp++; } } } } $context['message'] = t('Se Esta agregando los Municipios y Parroquias del Estado: @entidad.', array('@entidad' => $entidad)); $context['results'][] = t('La Entidad @name fue agregado @count Municipios y @countp Parroquias.', array('@name' => $entidad, '@count' => $countm, '@countp' => $countp)); } /** * Batch 'finished' callback */ function _ente_planificador_term_fields_import_finished($success, $results, $operations) { if ($success) { // Here we do something meaningful with the results. $message = t('%count Entidades procesadas: !items', array('%count' => count($results), '!items' => theme('item_list', array('items' => $results)))); } else { // An error occurred. // $operations contains the operations that remained unprocessed. $error_operation = reset($operations); $message = t('An error occurred while processing %error_operation with arguments: @arguments', array('%error_operation' => $error_operation[0], '@arguments' => print_r($error_operation[1], TRUE))); } drupal_set_message($message); }