forked from eileenmcnaughton/civimigrate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
civimigrate.module
executable file
·140 lines (134 loc) · 3.59 KB
/
civimigrate.module
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
<?php
/*
* Implementation of hook_migrate_api().
*/
function civimigrate_migrate_api() {
$api = array(
'api' => 2,
);
return $api;
}
function civimigrate_menu() {
return array(
'civimigrate-mapper' => array(
'page callback' => 'civimigrate_callback',
'access arguments' => array(
'administer nodes'
),
'type' => MENU_CALLBACK
),
'civimigrate-mapper/%cmid/edit' => array(
'page callback' => 'drupal_get_form',
'page arguments' => array(
'civimigrate_form',
1
),
'type' => MENU_CALLBACK,
'access arguments' => array(
'administer nodes'
)
)
);
}
function cmid_load($cmid) {
$results = db_query("SELECT * FROM {civimigrate_mappings} WHERE cmid = :cmid", array(
':cmid' => $cmid
));
$cmid = array();
foreach ($results as $result) {
$cmid = array(
'cmid' => $result->cmid,
'source_field' => $result->source_field,
'destination_field' => $result->destination_field,
'description' => $result->description,
'table' => $result->table,
'issuegroup' => $result->issuegroup
);
}
return $cmid;
}
function civimigrate_callback() {
drupal_set_title("Civimigrate_mappings table");
$results = db_query("SELECT * FROM {civimigrate_mappings}");
$table = array(
'header' => array(
'cmid',
'source_field',
'destination_field',
'description',
'table',
'issuegroup',
'Edit'
),
'rows' => array()
);
foreach ($results as $result) {
$table['rows'][] = array(
$result->cmid,
$result->source_field,
$result->destination_field,
$result->description,
$result->table,
$result->issuegroup,
l('Edit', "civimigrate-mapper/{$result->cmid}/edit")
);
}
return theme('table', $table);
}
function civimigrate_form($form, &$form_state, $cmid) {
drupal_set_title("Editing mapping {$cmid['cmid']}");
$form['source_field'] = array(
'#title' => 'Source Field',
'#type' => 'textfield',
'#default_value' => $cmid['source_field']
);
$form['destination_field'] = array(
'#title' => 'Destination Field',
'#type' => 'textfield',
'#default_value' => $cmid['destination_field']
);
$form['description'] = array(
'#title' => 'Description',
'#type' => 'textarea',
'#default_value' => $cmid['description']
);
$form['table'] = array(
'#title' => 'Table',
'#type' => 'textfield',
'#default_value' => $cmid['table']
);
$form['issuegroup'] = array(
'#title' => 'Issue Group',
'#type' => 'textfield',
'#default_value' => $cmid['issuegroup']
);
$form['cmid'] = array(
'#type' => 'hidden',
'#value' => $cmid['cmid']
);
$form['submit'] = array(
'#type' => 'submit',
'#value' => 'Save'
);
return $form;
}
function civimigrate_form_validate($form, &$form_state) {
foreach ($form_state['values'] as $key => $value) {
$value = trim($value);
if (empty($value) && $value != 0) {
$form_state['values'][$key] = NULL;
}
}
}
function civimigrate_form_submit($form, &$form_state) {
$record = array(
'source_field' => $form_state['values']['source_field'],
'destination_field' => $form_state['values']['destination_field'],
'description' => $form_state['values']['description'],
//'table' => $form_state['values']['table'],
'issuegroup' => $form_state['values']['issuegroup']
);
$result = db_update('civimigrate_mappings')->fields($record)->condition('cmid', $form_state['values']['cmid'])->execute();
drupal_set_message("$result row(s) updated.");
drupal_goto('civimigrate-mapper');
}