Conjunto 74b36d0 en sipes
- Fecha y hora:
- 28/03/2017 11:51:58 (hace 7 años)
- Branches:
- version-3.0
- Children:
- 2a0f72e
- Parents:
- 720b2a9
- Fichero:
-
- 1 editado
Leyenda
- No modificado
- Añadido
- Eliminado
-
0.3-modules/ente_planificador_importar/ente_planificador_importar.module
r3ce658b r74b36d0 24 24 * @author Cenditel Merida - Msc. Juan Vizcarrondo 25 25 * @date 2016-07-07 // (año-mes-dia) 26 * @date 2017-03-22 // (año-mes-dia) 26 27 * @version 0.2 // (0.1) 27 28 * … … 33 34 function ente_planificador_importar_perm() { 34 35 return array( 35 'importar entes planificadores', 36 'access import entes planificadores', 37 'import entes planificadores', 38 'import term', 39 'update proyecto state', 36 40 ); 37 41 } … … 44 48 $items['ente_planificador_importar'] = array( 45 49 'title' => 'Importar Entes Planificadores', 50 'page callback' => '_ente_planificador_importar_listar', 51 'access arguments' => array('access import entes planificadores'), 52 'type' => MENU_NORMAL_ITEM, 53 ); 54 $items['ente_planificador_importar/entes'] = array( 55 'title' => 'Importar Entes Planificadores', 46 56 'page callback' => 'drupal_get_form', 47 57 'page arguments' => array('ente_planificador_importar_form'), 48 'access arguments' => array('import arentes planificadores'),58 'access arguments' => array('import entes planificadores'), 49 59 'type' => MENU_CALLBACK, 50 60 ); 51 /*52 $items['ente_planificador_importar/execute'] = array(53 'title' => 'Importar entes',54 'page callback' => '_ente_planificador_importar_execute',55 'page arguments' => array(2),56 'access arguments' => array('importar entes planificadores'),57 'type' => MENU_CALLBACK,58 );59 */60 61 $items['ente_planificador_importar/terminos'] = array( 61 62 'title' => 'Importar Terminos', 62 63 'page callback' => 'drupal_get_form', 63 64 'page arguments' => array('ente_planificador_importar_terminos_form'), 64 'access arguments' => array('import ar entes planificadores'),65 'access arguments' => array('import term'), 65 66 'type' => MENU_CALLBACK, 66 67 ); 68 $items['ente_planificador_importar/estadoproyecto'] = array( 69 'title' => 'Modificar estado de poyectos', 70 'page callback' => 'drupal_get_form', 71 'page arguments' => array('ente_planificador_importar_aprobar_proyectos_form'), 72 'access arguments' => array('update proyecto state'), 73 'type' => MENU_CALLBACK, 74 ); 75 76 return $items; 77 } 78 67 79 /* 68 $items['ente_planificador_importar/terminos/execute'] = array( 69 'title' => 'Importar terminos', 70 'page callback' => '_ente_planificador_importar_terminos_execute', 71 'page arguments' => array(3), 72 'access arguments' => array('importar entes planificadores'), 73 'type' => MENU_CALLBACK, 74 ); 75 */ 76 77 return $items; 78 } 80 * Implementation of _ente_planificador_importar_listar() 81 * Muestra las opciones de importacion disponibles 82 */ 83 function _ente_planificador_importar_listar() { 84 $links = array(); 85 drupal_alter('ente_planificador_importar_links', $links); 86 return theme('item_list', $links); 87 } 88 89 /* 90 * Implementation of hook_ente_planificador_importar_links_alter() 91 */ 92 function ente_planificador_ente_planificador_importar_links_alter(&$links) { 93 if (user_access('import entes planificadores')) { 94 $links['entes'] = array( 95 'data' => l(t('Importar Entes Planificadores'), 'ente_planificador_importar/entes'), 96 'class' => 'ente-planificador-importar-entes', 97 ); 98 } 99 if (user_access('import term')) { 100 $links['term'] = array( 101 'data' => l(t('Importar terminos'), 'ente_planificador_importar/terminos'), 102 'class' => 'ente-planificador-importar-term', 103 ); 104 } 105 if (user_access('update proyecto state')) { 106 $links['estadoproyecto'] = array( 107 'data' => l(t('Actualizar estado de proyectos'), 'ente_planificador_importar/estadoproyecto'), 108 'class' => 'ente-planificador-importar-estado-proyecto', 109 ); 110 } 111 } 112 79 113 80 114 /** … … 397 431 $tipo = 'email'; 398 432 } 399 if ($field['type'] == ' email') {400 $tipo = ' email';433 if ($field['type'] == 'link') { 434 $tipo = 'link'; 401 435 } 402 436 if ($field['type'] == 'content_taxonomy') { … … 423 457 } 424 458 batch_set($batch); 425 batch_process('ente_planificador_importar ');459 batch_process('ente_planificador_importar/entes'); 426 460 } 427 461 else { … … 615 649 return $fathers; 616 650 } 651 652 653 /** 654 * Implementation of ente_planificador_importar_aprobar_proyectos_form(). 655 * Form to load cvs file and setting in proyectos estate update 656 */ 657 function ente_planificador_importar_aprobar_proyectos_form() { 658 $form = array(); 659 // If this #attribute is not present, upload will fail on submit 660 $form['#attributes']['enctype'] = 'multipart/form-data'; 661 $form['file_import_proyectos'] = array( 662 '#title' => t('Proyectos a aprobar'), 663 '#type' => 'file', 664 '#description' => t('Archivo cvs con el contenido de los proyectos a aprobar'), 665 ); 666 $options = array(); 667 for($i = 0;$i < 11; $i++) { 668 if (!$i) { 669 $options[$i] = t('N/A'); 670 } 671 else { 672 $options[$i] = t('Fila') . ' ' . $i; 673 } 674 } 675 $form['sipes'] = array( 676 '#type' => 'select', 677 '#title' => t('Código SIPES del proyecto'), 678 '#options' => $options, 679 '#description' => t("La fila donde se encuentra el código SIPES del proyecto."), 680 '#required' => TRUE, 681 ); 682 $estados = _proyectos_operativos_reformula_obtiene_estados(); 683 $form['workflow'] = array( 684 '#type' => 'select', 685 '#title' => t('Nuevo estado del proyecto'), 686 '#options' => $estados['states'], 687 '#description' => t("Seleccione el nuevo estado que se colocara a los proyectos contenidos en el archivo de importación."), 688 '#required' => TRUE, 689 ); 690 $form['encabezado'] = array( 691 '#title' => 'Primera columna como encabezado', 692 '#type' => 'checkbox', 693 '#return_value' => '1', 694 ); 695 $form['submit'] = array( 696 '#type' => 'submit', 697 '#value' => 'Submit', 698 ); 699 return $form; 700 } 701 702 703 /** 704 * Implementation of ente_planificador_importar_aprobar_proyectos_form_submit(). 705 * Submit cvs file in proyectos estate update 706 */ 707 function ente_planificador_importar_aprobar_proyectos_form_submit($form, &$form_state) { 708 global $user; 709 $validators = array('file_validate_extensions' => array('csv')); 710 // Check for a new uploaded file. 711 $file = file_save_upload('file_import_proyectos', $validators); 712 if (isset($file)) { 713 // File upload was attempted. 714 if ($file) { 715 // Put the temporary file in form_values so we can save it on submit. 716 $csv = $file->filepath; 717 $file = fopen($csv, 'r'); 718 $time = time(); 719 $i = 1; 720 $datas = array(); 721 $batch = array( 722 'title' => t('Importing proyectos ...', array('@format' => $format)), 723 'operations' => array(), 724 'init_message' => t('Commencing'), 725 'progress_message' => t('Processed @current out of @total.'), 726 'error_message' => t('An error occurred during processing'), 727 'finished' => '_batch_proyecto_operativo_cambiar_estado_importar_finished', 728 ); 729 while (($data = fgetcsv($file)) !== FALSE) { 730 $sipes = check_plain($data[$form_state['values']['sipes'] - 1]); 731 if ($sipes != '') { 732 $proyecto = array( 733 'sipes' => $sipes, // codigo sipes 734 'workflow' => $form_state['values']['workflow'], // workflow 735 'workflows' => $form['workflow']['#options'], // workflow options 736 ); 737 if (!($form_state['values']['encabezado'] && $i == 1)) { 738 $batch['operations'][] = array('_batch_proyecto_operativo_cambiar_estado_importar', array($proyecto)); 739 } 740 $i++; 741 } 742 } 743 batch_set($batch); 744 batch_process('ente_planificador_importar/estadoproyecto'); 745 } 746 else { 747 748 // File upload failed. 749 form_set_error('file_import_proyectos', t('The proyectos file could not be uploaded.')); 750 } 751 } 752 } 753 754 755 /** 756 * Implementation of _batch_proyecto_operativo_cambiar_estado_importar(). 757 * Update state proyectos (used in ente_planificador_importar_aprobar_proyectos_form_submit) 758 * Batch run callback 759 */ 760 function _batch_proyecto_operativo_cambiar_estado_importar($proyecto, &$context) { 761 $context['message'] = t('Now processing proyecto: %submission', array('%submission' => check_plain($proyecto['sipes']))); 762 $query = db_query("SELECT nid FROM {node} WHERE title = '%s'", $proyecto['sipes']); 763 $proyecto_nid = db_fetch_object($query); 764 if ($proyecto_nid && $proyecto_nid->nid) { 765 $node = node_load($proyecto_nid->nid); 766 if ($node->nid) { 767 if ($node->_workflow != $proyecto['workflow']) { 768 $context['results'][] = t('Actualizado el proyecto @proyecto desde el estado @ant al @prox ', array('@proyecto' => $proyecto['sipes'], '@ant' => $proyecto['workflows'][$node->_workflow], '@prox' => $proyecto['workflows'][$proyecto['workflow']])); 769 $node->_workflow = $proyecto['workflow']; 770 $node->revision = 1; 771 $texto = t('Se cambio el proyecto @nombre del estado @estado al @estado_next', array('@nombre' => $node->title, '@estado' => $proyecto['workflows'][$node->_workflow], '@estado_next' => $proyecto['workflows'][$proyecto['workflow']])); 772 $node->log = $texto; 773 $node->_workflow = $proyecto['workflow']; 774 node_save($node); 775 } 776 else { 777 $context['results'][] = t('El proyecto @proyecto ya se encuentra en el estado @prox ', array('@proyecto' => $proyecto['sipes'], '@prox' => $proyecto['workflows'][$proyecto['workflow']])); 778 } 779 } 780 else { 781 $context['results'][] = t('No se encontro el proyecto @proyecto', array('@proyecto' => $proyecto['sipes'])); 782 } 783 } 784 else { 785 $context['results'][] = t('No se encontro el proyecto @proyecto', array('@proyecto' => $proyecto['sipes'])); 786 } 787 } 788 789 /** 790 * Implementation of _batch_ente_planificador_importar_finished(). 791 * Batch 'finished' callback 792 */ 793 function _batch_proyecto_operativo_cambiar_estado_importar_finished($success, $results, $operations) { 794 if ($success) { 795 // Here we do something meaningful with the results. 796 $message = t('!count_webform entes processed', array('!count_webform' => '<pre>' . print_r($results, TRUE) . '</pre>')); 797 } 798 else { 799 // An error occurred. 800 // $operations contains the operations that remained unprocessed. 801 $error_operation = reset($operations); 802 $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))); 803 } 804 drupal_set_message($message); 805 } 806
Nota: Vea TracChangeset
para ayuda en el uso del visor de conjuntos de cambios.