Conjunto 546c863 en sipes
- Fecha y hora:
- 29/07/2019 13:16:04 (hace 5 años)
- Branches:
- stable
- Children:
- bce0d38
- Parents:
- f9d3d85
- Fichero:
-
- 1 editado
Leyenda
- No modificado
- Añadido
- Eliminado
-
0.3-modules/ente_planificador_importar/ente_planificador_importar.module
rf9d3d85 r546c863 2 2 3 3 /** 4 * Modulo para importar entes y terminos 4 * Modulo para importar entes y terminos 5 5 * Sistema Automatizado para la Planificación Estratégico-Situacional en la Administración Pública Venezolana 6 6 * @file ente_planificador_importar.module … … 12 12 * the Free Software Foundation; either version 2 of the License, or 13 13 * (at your option) any later version. 14 * 14 * 15 15 * This program is distributed in the hope that it will be useful, 16 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 18 * GNU General Public License for more details. 19 * 19 * 20 20 * You should have received a copy of the GNU General Public License 21 21 * along with this program; if not, write to the Free Software … … 59 59 'type' => MENU_CALLBACK, 60 60 ); 61 $items['ente_planificador_importar/updb_proyectos'] = array( 62 'title' => 'Importar Entes Planificadores', 63 'page callback' => 'drupal_get_form', 64 'page arguments' => array('ente_planificador_importar_updb_proyectos_form'), 65 'access arguments' => array('import entes planificadores'), 66 'type' => MENU_CALLBACK, 67 ); 61 68 $items['ente_planificador_importar/terminos'] = array( 62 69 'title' => 'Importar Terminos', … … 120 127 $links['entes'] = array( 121 128 'data' => l(t('Importar Entes Planificadores'), 'ente_planificador_importar/entes'), 122 'class' => 'ente-planificador-importar-entes', 129 'class' => 'ente-planificador-importar-entes', 123 130 ); 124 131 } … … 126 133 $links['term1'] = array( 127 134 'data' => l(t('Importar terminos'), 'ente_planificador_importar/terminos'), 128 'class' => 'ente-planificador-importar-term', 135 'class' => 'ente-planificador-importar-term', 129 136 ); 130 137 $links['term2'] = array( 131 138 'data' => l(t('Importar Campos de terminos'), 'ente_planificador_importar/terminos/fields'), 132 'class' => 'ente-planificador-importar-term-fields', 139 'class' => 'ente-planificador-importar-term-fields', 133 140 ); 134 141 $links['term_parent'] = array( 135 142 'data' => l(t('Relacionar taxonomias y guardar valores en un campo del termino'), 'ente_planificador_importar/terminos/relations_fields'), 136 'class' => 'ente-planificador-importar-term-parents-fields', 143 'class' => 'ente-planificador-importar-term-parents-fields', 137 144 ); 138 145 } … … 140 147 $links['estadoproyecto'] = array( 141 148 'data' => l(t('Actualizar estado de proyectos'), 'ente_planificador_importar/estadoproyecto'), 142 'class' => 'ente-planificador-importar-estado-proyecto', 149 'class' => 'ente-planificador-importar-estado-proyecto', 143 150 ); 144 151 } … … 147 154 /** 148 155 * Implementation of ente_planificador_importar_terminos_form(). 149 * Form to load cvs file in term import 156 * Form to load cvs file in term import 150 157 */ 151 158 function ente_planificador_importar_terminos_relations_fields_form(&$form_state) { … … 193 200 /** 194 201 * Implementation of ente_planificador_importar_terminos_form_submit(). 195 * Submit cvs file in term import 202 * Submit cvs file in term import 196 203 */ 197 204 function ente_planificador_importar_terminos_relations_fields_form_submit($form, &$form_state) { … … 279 286 280 287 function ente_planificador_importar_terminos_relations_fields_name($vid) { 281 $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent 282 FROM {term_data} t 283 INNER JOIN {term_hierarchy} h 284 ON t.tid = h.tid 285 WHERE t.vid = %d 286 ORDER BY weight, name', 't', 'tid'), $vid); 287 288 $result = db_query(db_rewrite_sql('SELECT t.tid, t.*, parent FROM {term_data} t INNER JOIN {term_hierarchy} h ON t.tid = h.tid WHERE t.vid = %d ORDER BY weight, name', 't', 'tid'), $vid); 288 289 while ($term = db_fetch_object($result)) { 289 290 $terms[trim($term->name)] = $term; … … 422 423 $output = drupal_render($new_form); 423 424 print drupal_to_js(array('data' => $output, 'status' => true)); 424 exit(); 425 exit(); 425 426 print ''; 426 427 exit(); … … 431 432 * Implementation of _batch_ente_planificador_importar_term_fields(). 432 433 * display term saved (used in _ente_planificador_importar_terminos_execute) 433 * Batch run callback 434 * Batch run callback 434 435 */ 435 436 function _batch_ente_planificador_importar_term_relations_fields($term, &$context) { … … 460 461 461 462 /** 463 * Update values of field to type content 464 */ 465 function ente_planificador_importar_updb_proyectos_form(&$form_state) { 466 $form = array(); 467 // If this #attribute is not present, upload will fail on submit 468 $form['#attributes']['enctype'] = 'multipart/form-data'; 469 $form['file_import_entes'] = array( 470 '#title' => t('Archivo a importar'), 471 '#type' => 'file', 472 '#description' => t('Archivo cvs con el contenido de los terminos a importar'), 473 '#weight' => -1, 474 ); 475 476 $options = array(); 477 for ($i = 0;$i < 30; $i++) { 478 if (!$i) { 479 $options[$i] = t('N/A'); 480 } 481 else { 482 $options[$i] = t('Fila') . ' ' . $i; 483 } 484 } 485 486 $delimiter_option = array(",",";"); 487 $form['delimiter']= array( 488 '#type' => 'select', 489 '#title' => t('Tipo de Delimitador'), 490 '#options' => $delimiter_option, 491 '#description' => t("Delimitador del archivo csv."), 492 '#required' => TRUE, 493 '#weight' => -1, 494 '#default_value' => ",", 495 ); 496 497 $form['field_name'] = array( 498 '#type' => 'select', 499 '#title' => t('Nombre del campo'), 500 '#options' => $options, 501 '#description' => t("La fila donde se encuentra el nombre del Campo a modificar."), 502 '#required' => TRUE, 503 '#weight' => 0, 504 '#default_value' => 1, 505 ); 506 507 $form['field_nid'] = array( 508 '#type' => 'select', 509 '#title' => t('Nid del nodo'), 510 '#options' => $options, 511 '#description' => t("La fila donde se encuentra el nid del nodo a modificar."), 512 '#required' => TRUE, 513 '#weight' => 1, 514 '#default_value' => 2, 515 ); 516 517 $form['field_vid'] = array( 518 '#type' => 'select', 519 '#title' => t('Vid del campo'), 520 '#options' => $options, 521 '#description' => t("La fila donde se encuentra el vid del nodo a modificar."), 522 '#required' => TRUE, 523 '#weight' => 2, 524 '#default_value' => 3, 525 ); 526 527 $form['type_content'] = array( 528 '#type' => 'select', 529 '#title' => t('tipo de contenido del campo'), 530 '#options' => $options, 531 '#description' => t("seleccione la columna donde se encuentre el tipo de contenido del campo."), 532 '#required' => TRUE, 533 '#weight' => 3, 534 '#default_value' => 4, 535 ); 536 537 $form['field_delta'] = array( 538 '#type' => 'select', 539 '#title' => t('Delta del campo'), 540 '#options' => $options, 541 '#description' => t("si el campo es multiple seleccione la columna donde se encuentre el delta."), 542 '#required' => TRUE, 543 '#weight' => 4, 544 ); 545 546 $form['field_tid'] = array( 547 '#type' => 'select', 548 '#title' => t('tid del campo'), 549 '#options' => $options, 550 '#description' => t("si el campo es multiple seleccione la columna donde se encuentre el tid."), 551 '#required' => TRUE, 552 '#weight' => 5, 553 ); 554 555 $form['fields'] = array( 556 '#type' => 'fieldset', 557 '#title' => t('Campos'), 558 '#weight' => 6, 559 ); 560 for ($i=0; $i<12; $i++) { 561 $form['fields']['field_value_' . $i] = array( 562 '#type' => 'select', 563 '#title' => t('Valor del campo ' . $i), 564 '#options' => $options, 565 '#description' => t("La fila donde se encuentra el valor del nodo a modificar."), 566 '#required' => TRUE, 567 '#weight' => $i, 568 '#default_value' => ($i==0) ? 7 : 0 , 569 ); 570 } 571 572 $form['encabezado'] = array( 573 '#title' => 'Primera columna como encabezado', 574 '#type' => 'checkbox', 575 '#return_value' => '1', 576 '#weight' => 7, 577 '#default_value' => TRUE, 578 ); 579 580 $form['submit'] = array( 581 '#type' => 'submit', 582 '#value' => 'Submit', 583 '#weight' => 35, 584 ); 585 return $form; 586 } 587 588 /** 589 * Implementation of function ente_planificador_importar_updb_proyectos_form(). 590 * Update values of field to type content 591 */ 592 function ente_planificador_importar_updb_proyectos_form_submit($form, &$form_state) { 593 global $user; 594 $validators = array('file_validate_extensions' => array('csv')); 595 // Check for a new uploaded file. 596 $file = file_save_upload('file_import_entes', $validators); 597 if (isset($file)) { 598 include_once('./'. drupal_get_path('module', 'content') .'/content.install'); 599 drupal_load('module', 'content'); 600 // $types = content_types_install(); 601 // if (empty($types)) { 602 // return $ret; 603 // } 604 605 // File upload was attempted. 606 if ($file) { 607 608 // Put the temporary file in form_values so we can save it on submit. 609 $csv = $file->filepath; 610 $file = fopen($csv, 'r'); 611 $time = time(); 612 $i = 1; 613 $batch = array( 614 'title' => t('Update value proyects and acciones ...', array('@format' => $format)), 615 'operations' => array(), 616 'init_message' => t('Commencing'), 617 'progress_message' => t('Processed @current out of @total.'), 618 'error_message' => t('An error occurred during processing'), 619 'finished' => '_batch_ente_planificador_importar_finished', 620 ); 621 622 //read the csv archive 623 $data_all = fread($file, filesize($csv)); 624 $fgetslines = explode("\n",$data_all); 625 $process = count($fgetslines); 626 $process = $form_state['values']['encabezado'] && $i == 1 ? $process-1 : $process ; 627 $encabezado = $form_state['values']['encabezado'] && $i == 1 ? 1 : 0 ; 628 629 for ($k=$encabezado; $k < $process; $k++) { 630 $data_line = explode("\n",$data_all); 631 $data_line_all = $data_line[$k]; 632 $delimet = $form_state['values']['delimiter'] ? ";" : "," ; 633 $data = explode($delimet,$data_line_all); 634 635 $batch['operations'][] = array('_ente_planificador_importar_updb_proyectos_importar', array( $data, $form_state['values'])); 636 } 637 638 batch_set($batch); 639 batch_process('ente_planificador_importar/updb_proyectos'); 640 } 641 else { 642 643 // File upload failed. 644 form_set_error('file_import_entes', t('The entes file could not be uploaded.')); 645 } 646 } 647 } 648 649 /** 650 * Update values of field to type content 651 * Batch run callback 652 */ 653 function _ente_planificador_importar_updb_proyectos_importar( $data, $formstate_values, &$context) { 654 655 $fields_update = trim($data[$formstate_values['field_name']-1]); 656 $field = content_fields($fields_update, $data[$formstate_values['type_content']-1]); 657 $values[] = $field; 658 $index = array(); 659 for ($i=0; $i<12; $i++) { 660 $index[] = $i === 0? 'value' : 'value_' . $i; 661 } 662 663 $rate = 100000; 664 $sql = ''; 665 foreach ($values as $field) { 666 if ($field['multiple']) { 667 $sql.=' and delta = '. $data[$formstate_values['field_delta']-1]; 668 } 669 $db_info = content_database_info($field); 670 if (array_key_exists('tid', $db_info['columns'])) { 671 $sql.= ' and ' . $db_info['columns']['tid']['column'] . ' = ' . $data[$formstate_values['field_tid']-1] ; 672 673 } 674 $table = $db_info['table']; 675 $columns = array(); 676 677 foreach($index as $key => $id) { 678 if (isset($db_info['columns'][$id])) { 679 $value = trim($data[$formstate_values['field_value_' . $key]-1]); 680 $attributes = $db_info['columns'][$id]; 681 $column = $attributes['column']; 682 683 $decimals = ($field['scale']) && is_numeric($field['scale']) ? $field['scale'] : 0; 684 if(!$value==0) { 685 686 //$columns[] = $column . ' = round(' . $value . '/' . $rate . ', ' . 8 . ')'; 687 688 // Divide monto 689 // $value_table = round($value/$rate,8); 690 691 //Directamente sin dividir montos 692 $columns[] = $column .'='.$value; 693 694 } else { 695 $columns[] = $column . ' = 0 '; 696 } 697 } 698 } 699 700 //sql que se va a pasar visto en Entradas recientes del registro 701 // $sql1 =('UPDATE {'. $db_info['table'] . '} AS tab SET '. implode(', ', $columns) . ' FROM {node} AS n WHERE n.nid = tab.nid AND n.vid = tab.vid AND n.vid = ' . $data[$formstate_values['field_vid']-1] . ' AND n.nid =' . $data[$formstate_values['field_nid']-1] . $sql ); 702 // watchdog('Test Sipes', '$decimals @filename.', array('@filename' => print_r($sql1,1)), WATCHDOG_ERROR); 703 //endsql que se va a pasar visto en Entradas recientes del registro 704 705 update_sql('UPDATE {'. $db_info['table'] . '} AS tab SET '. implode(', ', $columns) . ' FROM {node} AS n WHERE n.nid = tab.nid AND n.vid = tab.vid AND n.vid = ' . $data[$formstate_values['field_vid']-1] . ' AND n.nid =' . $data[$formstate_values['field_nid']-1] . $sql ); 706 } 707 708 $context['message'] = t('Now processing nid of node: %submission', array('%submission' => trim($data[$formstate_values['field_nid']-1]))); 709 $context['results'][] = 'Node update: ' . trim($data[$formstate_values['field_nid']-1]) . '</pre>'; 710 711 if ($context['sandbox']['progress'] >= $context['sandbox']['max']) { 712 $context['finished'] = 1; 713 } else { 714 $context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max']; 715 } 716 } 717 718 719 720 /** 462 721 * Implementation of ente_planificador_importar_terminos_form(). 463 * Form to load cvs file in term import 722 * Form to load cvs file in term import 464 723 */ 465 724 function ente_planificador_importar_terminos_fields_form(&$form_state) { … … 499 758 /** 500 759 * Implementation of ente_planificador_importar_terminos_form_submit(). 501 * Submit cvs file in term import 760 * Submit cvs file in term import 502 761 */ 503 762 function ente_planificador_importar_terminos_fields_form_submit($form, &$form_state) { … … 530 789 531 790 while (($data = fgetcsv($file)) !== FALSE) { 532 $taxonomy = taxonomy_vocabulary_load($form_state['values']['vid']); 791 $taxonomy = taxonomy_vocabulary_load($form_state['values']['vid']); 533 792 $terms = taxonomy_get_tree($taxonomy->vid); 534 793 $name_field = check_plain($data[$form_state['values']['nombre'] - 1]); … … 567 826 * Implementation of _batch_ente_planificador_importar_term_fields(). 568 827 * display term saved (used in _ente_planificador_importar_terminos_execute) 569 * Batch run callback 828 * Batch run callback 570 829 */ 571 830 function _batch_ente_planificador_importar_term_fields($term, &$context) { … … 697 956 $output = drupal_render($new_form); 698 957 print drupal_to_js(array('data' => $output, 'status' => true)); 699 exit(); 958 exit(); 700 959 print ''; 701 960 exit(); … … 704 963 /** 705 964 * Implementation of ente_planificador_importar_terminos_form(). 706 * Form to load cvs file in term import 965 * Form to load cvs file in term import 707 966 */ 708 967 function ente_planificador_importar_terminos_form() { … … 787 1046 /** 788 1047 * Implementation of ente_planificador_importar_terminos_form_submit(). 789 * Submit cvs file in term import 1048 * Submit cvs file in term import 790 1049 */ 791 1050 function ente_planificador_importar_terminos_form_submit($form, &$form_state) { … … 850 1109 /** 851 1110 * Implementation of _ente_planificador_importar_terminos_execute(). 852 * Batch 'execute' callback 1111 * Batch 'execute' callback 853 1112 */ 854 1113 function _ente_planificador_importar_terminos_execute($execute_id){ … … 882 1141 /** 883 1142 * Implementation of _batch_ente_planificador_importar_term_finished(). 884 * Batch 'finished' callback 1143 * Batch 'finished' callback 885 1144 */ 886 1145 function _batch_ente_planificador_importar_term_finished($success, $results, $operations) { … … 901 1160 * Implementation of _batch_ente_planificador_importar_term(). 902 1161 * display term saved (used in _ente_planificador_importar_terminos_execute) 903 * Batch run callback 1162 * Batch run callback 904 1163 */ 905 1164 function _batch_ente_planificador_importar_term($term, &$context) { … … 914 1173 if ($parent->name == trim($term['search_parent']) && $parents_all[count($parents_all) - 1]->name == trim($term['term_parent'])) { 915 1174 $parents = array('name' => $parent->name, 'tid_parent' => $row['tid']); 916 1175 917 1176 $db_query2 = db_query(db_rewrite_sql("SELECT t.tid, t.name FROM {term_data} t inner join {term_hierarchy} as h on h.tid=t.tid WHERE LOWER(t.name) = LOWER('%s') AND t.vid = %d AND h.parent = %d", 't', 'tid'), trim($term['name']), $term['vid'], $row['tid']); 918 1177 $rows_query = db_fetch_array($db_query2); … … 941 1200 /** 942 1201 * Implementation of ente_planificador_importar_form(). 943 * Form to load cvs file in entes import 1202 * Form to load cvs file in entes import 944 1203 */ 945 1204 function ente_planificador_importar_form() { … … 1003 1262 ); 1004 1263 foreach($fields as $field_id => $field) { 1005 $campos[$field_id] = $field; 1264 $campos[$field_id] = $field; 1006 1265 $form['campos'][$field_id] = array( 1007 1266 '#type' => 'select', … … 1027 1286 /** 1028 1287 * Implementation of ente_planificador_importar_form_submit(). 1029 * Submit cvs file in entes import 1288 * Submit cvs file in entes import 1030 1289 */ 1031 1290 function ente_planificador_importar_form_submit($form, &$form_state) { … … 1114 1373 /** 1115 1374 * Implementation of _ente_planificador_importar_execute(). 1116 * Batch 'execute' callback 1375 * Batch 'execute' callback 1117 1376 */ 1118 1377 function _ente_planificador_importar_execute($execute_id){ … … 1145 1404 /** 1146 1405 * Implementation of _ente_planificador_importar_usuarios(). 1147 * Obtiene la cantidad de usuarios por tipo de ente 1406 * Obtiene la cantidad de usuarios por tipo de ente 1148 1407 */ 1149 1408 function _ente_planificador_importar_usuarios($tipo = 0) { … … 1175 1434 * Implementation of _batch_ente_planificador_importar(). 1176 1435 * Save entes (used in _ente_planificador_importar_execute) 1177 * Batch run callback 1436 * Batch run callback 1178 1437 */ 1179 1438 function _batch_ente_planificador_importar($ente, &$context) { … … 1218 1477 } 1219 1478 else { 1220 $acronimo = 'ente_' . $acronimo; 1479 $acronimo = 'ente_' . $acronimo; 1221 1480 } 1222 1481 //se crean los usuarios segun el tipo … … 1248 1507 /** 1249 1508 * Implementation of _batch_ente_planificador_importar_finished(). 1250 * Batch 'finished' callback 1509 * Batch 'finished' callback 1251 1510 */ 1252 1511 function _batch_ente_planificador_importar_finished($success, $results, $operations) { … … 1298 1557 /** 1299 1558 * Implementation of ente_planificador_importar_aprobar_proyectos_form(). 1300 * Form to load cvs file and setting in proyectos estate update 1559 * Form to load cvs file and setting in proyectos estate update 1301 1560 */ 1302 1561 function ente_planificador_importar_aprobar_proyectos_form() { … … 1401 1660 * Implementation of _batch_proyecto_operativo_cambiar_estado_importar(). 1402 1661 * Update state proyectos (used in ente_planificador_importar_aprobar_proyectos_form_submit) 1403 * Batch run callback 1662 * Batch run callback 1404 1663 */ 1405 1664 function _batch_proyecto_operativo_cambiar_estado_importar($proyecto, &$context) { … … 1434 1693 /** 1435 1694 * Implementation of _batch_ente_planificador_importar_finished(). 1436 * Batch 'finished' callback 1695 * Batch 'finished' callback 1437 1696 */ 1438 1697 function _batch_proyecto_operativo_cambiar_estado_importar_finished($success, $results, $operations) { … … 1449 1708 drupal_set_message($message); 1450 1709 } 1451
Nota: Vea TracChangeset
para ayuda en el uso del visor de conjuntos de cambios.