Project

General

Profile

Download (3.83 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/**
4
 * @file
5
 * Allows to export classifications into a flat csv file.
6
 *
7
 * @copyright
8
 *   (C) 2007-2012 EDIT
9
 *   European Distributed Institute of Taxonomy
10
 *   http://www.e-taxonomy.eu
11
 *
12
 *   The contents of this module are subject to the Mozilla
13
 *   Public License Version 1.1.
14
 * @see http://www.mozilla.org/MPL/MPL-1.1.html
15
 *
16
 * @author
17
 * Oppermann, Alexander <a.oppermann@BGBM.org>
18
 *
19
 */
20

    
21

    
22
/**
23
 * 
24
 * @param unknown $path
25
 *  Which path of the site we're using to display help
26
 * @param unknown $arg
27
 *  Array that holds the current path as returned from arg() function
28
 * @return string
29
 */
30
function cdm_csv_export_help($path, $arg){
31

    
32
switch ($path) {
33
  case "admin/help#cdm_csv_export":
34
  return '<h1>'.t('CDM CSV Export Help'). '</h1>'. '<p>' . t("In order 
35
    to export the data with special export options, it is essential 
36
    to configure a feature tree with the desired features. Then set
37
    this feature tree as the default feature tree for this portal."
38
    ) . '</p>';
39
  break;
40
  }
41
}
42

    
43
/**
44
 * Implements hook_block_info() 
45
 * 
46
 * Prepares the content for the help menu
47
 * 
48
 * @return multitype:string Ambigous <The, string, A, Optional>
49
 */
50
function cdm_csv_export_block_info() {
51
  $blocks['cdm_csv_export'] = array(
52
    'info' => t('CDM CSV Export Module'), //The name that will appear in the block list.
53
    'cache' => DRUPAL_CACHE_PER_ROLE, //Default
54
  );
55
  return $blocks;
56
}
57

    
58
/**
59
 * Implements hook_block_view().
60
 * 
61
 * Prepares the contents of the block.
62
 *  
63
 * @param string $delta
64
 * @return multitype:Ambigous <The, boolean, string>
65
 */
66
function cdm_csv_export_block_view($delta='') {
67
  $block['subject'] = t('Export into CSV');
68
  $block['content']= array(
69
      drupal_get_form('cdm_csv_export_my_form'),
70
  );
71
  return $block;
72
}
73

    
74
/**
75
 * Creates the drupal form and returns it
76
 * 
77
 * @param unknown $form_state
78
 * @return multitype:string multitype:string  
79
 *          multitype:string multitype:string   
80
 *          Ambigous <A, string> multitype:NULL  
81
 *          multitype:string multitype: Ambigous <The, string, A, Optional>  The
82
 */
83
function cdm_csv_export_my_form($form_state) {
84
  $form['combobox'] = array(
85
    '#type' => 'select',
86
    '#title' => t('Classification').':',
87
    '#default_value' => variable_get(CDM_TAXONOMICTREE_UUID, FALSE),
88
    '#options' => cdm_get_taxontrees_as_options(),
89
    '#attributes' => array('name' => 'classification'),
90
  );
91

    
92
  $form['csvExportOptions'] = array(
93
      '#type'=>'checkboxes',
94
      '#title'	=>t('Download Options'),
95
      '#options' => array(),
96
  );
97
    
98
   // ---- LAYOUT PER FEATURE ---- //
99
$feature_tree = get_profile_featureTree();
100
  if (isset($feature_tree->root->children)) {
101
    foreach ($feature_tree->root->children as $featureNode) {
102
      if (isset($featureNode->feature)) {
103

    
104
       // Must not exceed 45 characters !!!
105
        $subform_id =  $featureNode->feature->uuid; //LAYOUT_SETTING_PREFIX .
106
        $settings = mixed_variable_get($subform_id, FEATURE_TREE_LAYOUT_DEFAULTS);
107
        $systemDefaults = unserialize(FEATURE_TREE_LAYOUT_DEFAULTS);
108
        $form['csvExportOptions'][$subform_id] = array(
109
          '#type' => 'checkbox',
110
          '#title' => $featureNode->feature->representation_L10n,
111
          '#default_value' => $featureNode->feature->uuid,//$settings,
112
          '#attributes' => array('value' => $featureNode->feature->uuid,
113
                                  'name' => 'features'
114
            ),
115
        );
116
      }
117
    }
118
  }
119
  $form['downloadTokenValueId'] = array(
120
    '#type' => 'hidden',
121
    '#attributes' => array('name' => 'downloadTokenValueId',
122
                           'id' => 'downloadTokenValueId',                     
123
      ),
124
    );
125

    
126
  $form['button'] = array(
127
    '#type'  => 'submit',
128
    '#value' => 'Export',
129
    );
130
  
131
  $form['#action'] = url('../../csv/exportRedlist');
132
  $form['#attributes'] = array('onsubmit' => 'return blockUIForDownload()');
133
  
134
  return $form;
135
}
(2-2/2)