|
@@ -1270,12 +1270,23 @@ function tripal_bulk_loader_duplicate_template_record_form_submit($form, &$form_
|
|
|
function tripal_bulk_loader_template_field_form_default_values($mode, &$form_state) {
|
|
|
$v = array();
|
|
|
|
|
|
- $v['template_id'] = (isset($form_state['build_info']['args'][0])) ? $form_state['build_info']['args'][0] : FALSE;
|
|
|
+ $v['mode'] = $mode;
|
|
|
+ $v['template_id'] = (isset($form_state['build_info']['args'][1])) ? $form_state['build_info']['args'][1] : FALSE;
|
|
|
$form_state['storage']['template_id'] = $v['template_id'];
|
|
|
$template_id = $v['template_id'];
|
|
|
- $v['record_id'] = (isset($form_state['build_info']['args'][1])) ? $form_state['build_info']['args'][1] : FALSE;
|
|
|
+ $v['record_id'] = (isset($form_state['build_info']['args'][2])) ? $form_state['build_info']['args'][2] : FALSE;
|
|
|
+ $v['no_record_id'] = ($mode == 'create_record') ? TRUE : FALSE;
|
|
|
$form_state['storage']['record_id'] = $v['record_id'];
|
|
|
$record_id = $v['record_id'];
|
|
|
+ $priority = $record_id;
|
|
|
+ $v['field_index'] = (isset($form_state['build_info']['args'][3])) ? $form_state['build_info']['args'][3] : FALSE;
|
|
|
+ $v['no_field_index'] = (isset($form_state['build_info']['args'][3])) ? FALSE : TRUE;
|
|
|
+ $form_state['storage']['field_index'] = $v['field_index'];
|
|
|
+ $field_index = $v['field_index'];
|
|
|
+
|
|
|
+ if (!isset($form_state['values'])) {
|
|
|
+ $form_state['values'] = array();
|
|
|
+ }
|
|
|
|
|
|
// Get the template if not already stored
|
|
|
if (!isset($form_state['storage']['template'])) {
|
|
@@ -1299,12 +1310,53 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
|
|
|
$template = $form_state['storage']['template'];
|
|
|
}
|
|
|
|
|
|
+ // If we are editing then get the original values
|
|
|
+ if ($mode == 'edit' && !$v['no_field_index']) {
|
|
|
+ $template_field = $form_state['storage']['template_array'][$v['record_id']]['fields'][$field_index];
|
|
|
+ $original_field = $template_field;
|
|
|
+ $form_state['storage']['original_field'] = $template_field;
|
|
|
+ $form_state['storage']['original_field']['priority'] = $priority;
|
|
|
+ $form_state['storage']['original_field']['field_index'] = $field_index;
|
|
|
+ }
|
|
|
+
|
|
|
$v['template_name'] = (isset($template->name)) ? $template->name : '';
|
|
|
|
|
|
- $v['field_type'] = (isset($form_state['values']['field_type'])) ? $form_state['values']['field_type'] : 'table field';
|
|
|
+ if (isset($form_state['values']['field_type'])) {
|
|
|
+ $v['field_type'] = $form_state['values']['field_type'];
|
|
|
+ }
|
|
|
+ elseif (isset($original_field['type'])) {
|
|
|
+ $v['field_type'] = $original_field['type'];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $v['field_type'] = 'table field';
|
|
|
+ }
|
|
|
$field_type = $v['field_type'];
|
|
|
|
|
|
// Set field type options
|
|
|
+ // First set original field values in $form_state['values'] if not already set
|
|
|
+ switch ($v['field_type']) {
|
|
|
+ case 'table field':
|
|
|
+ if (!isset($form_state['values']['column_number'])) {
|
|
|
+ $form_state['values']['column_number'] = (isset($original_field['spreadsheet column'])) ? $original_field['spreadsheet column'] : '';
|
|
|
+ $form_state['values']['column_exposed'] = (isset($original_field['exposed'])) ? $original_field['exposed'] : FALSE;
|
|
|
+ $form_state['values']['column_exposed_desc'] = (isset($original_field['exposed_description'])) ? $original_field['exposed_description'] : FALSE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'constant':
|
|
|
+ if (!isset($form_state['values']['constant_value'])) {
|
|
|
+ $form_state['values']['constant_value'] = (isset($original_field['constant value'])) ? $original_field['constant value'] : '';
|
|
|
+ $form_state['values']['constant_exposed'] = (isset($original_field['exposed'])) ? $original_field['exposed'] : FALSE;
|
|
|
+ $form_state['values']['constant_validate'] = (isset($original_field['exposed_validate'])) ? $original_field['exposed_validate'] : FALSE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 'foreign key':
|
|
|
+ if (!isset($form_state['values']['foreign_record'])) {
|
|
|
+ $form_state['values']['foreign_record'] = (isset($original_field['foreign key'])) ? $original_field['foreign key'] : FALSE;
|
|
|
+ $form_state['values']['foreign_field'] = (isset($original_field['foreign field'])) ? $original_field['foreign field'] : FALSE;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
// Ensure other field type fields are reset/cleared except for those of the current type
|
|
|
// ie: if the type is changed from spreadsheet column to constant, the spreadsheet column
|
|
|
// fields should be cleared since they don't apply to a constant
|
|
@@ -1336,8 +1388,13 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
|
|
|
}
|
|
|
|
|
|
// Use the record_id as the priority/field_group
|
|
|
- if ($record_id) {
|
|
|
+ if ($v['no_record_id']) {
|
|
|
+ $form_state['values']['field_group'] = 'NEW';
|
|
|
+ $v['field_group'] = 'NEW';
|
|
|
+ }
|
|
|
+ else {
|
|
|
$form_state['values']['field_group'] = $record_id;
|
|
|
+ $v['field_group'] = $record_id;
|
|
|
if (preg_match('/\d+/', $record_id)) {
|
|
|
$priority = $form_state['values']['field_group'];
|
|
|
$table = $form_state['storage']['template_array'][$priority]['table'];
|
|
@@ -1382,6 +1439,9 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
|
|
|
$field = current($chado_fields);
|
|
|
}
|
|
|
}
|
|
|
+ elseif (isset($original_field['field'])) {
|
|
|
+ $field = $original_field['field'];
|
|
|
+ }
|
|
|
else {
|
|
|
$field = current($chado_fields);
|
|
|
}
|
|
@@ -1420,7 +1480,15 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
|
|
|
$v['chado_field_options'] = $chado_fields;
|
|
|
|
|
|
$v['record_name'] = (isset($form_state['values']['record_name'])) ? $form_state['values']['record_name'] : '';
|
|
|
- $v['field_title'] = (isset($form_state['values']['field_title'])) ? $form_state['values']['field_title'] : '';
|
|
|
+ if (isset($form_state['values']['field_title'])) {
|
|
|
+ $v['field_title'] = $form_state['values']['field_title'];
|
|
|
+ }
|
|
|
+ elseif (isset($original_field['title'])) {
|
|
|
+ $v['field_title'] = $original_field['title'];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $v['field_title'] = '';
|
|
|
+ }
|
|
|
|
|
|
$v['show_all_records'] = (isset($form_state['values']['show_all_records'])) ? $form_state['values']['show_all_records'] : FALSE;
|
|
|
|
|
@@ -1520,15 +1588,19 @@ function tripal_bulk_loader_template_field_form_default_values($mode, &$form_sta
|
|
|
*
|
|
|
* @ingroup tripal_bulk_loader
|
|
|
*/
|
|
|
-function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
+function tripal_bulk_loader_template_field_form($form, $form_state = NULL) {
|
|
|
$form['#cache'] = TRUE; // Make sure the form is cached.
|
|
|
|
|
|
// if there is no template supplied don't return rest of form
|
|
|
- if (!isset($form_state['build_info']['args'][0])) {
|
|
|
+ if (!isset($form_state['build_info']['args'][1])) {
|
|
|
return $form;
|
|
|
}
|
|
|
|
|
|
- $values = tripal_bulk_loader_template_field_form_default_values('add', $form_state);
|
|
|
+ $v['mode'] = (isset($form_state['build_info']['args'][0])) ? $form_state['build_info']['args'][0] : 'create';
|
|
|
+ $form_state['storage']['mode'] = $v['mode'];
|
|
|
+ $mode = $v['mode'];
|
|
|
+
|
|
|
+ $values = tripal_bulk_loader_template_field_form_default_values($mode, $form_state);
|
|
|
|
|
|
$form['template_name'] = array(
|
|
|
'#type' => 'item',
|
|
@@ -1541,13 +1613,13 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
'#value' => $values['template_id'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields'] = array(
|
|
|
+ $form['fields'] = array(
|
|
|
'#type' => 'markup',
|
|
|
- '#prefix' => '<div id="tripal_bulk_loader_template-add_field">',
|
|
|
+ '#prefix' => '<div id="tripal_bulk_loader_template-template_fields">',
|
|
|
'#suffix' => '</div>',
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['field_type'] = array(
|
|
|
+ $form['fields']['field_type'] = array(
|
|
|
'#type' => 'radios',
|
|
|
'#title' => t('Type of Field'),
|
|
|
'#options' => array(
|
|
@@ -1558,13 +1630,13 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
'#required' => TRUE,
|
|
|
'#default_value' => $values['field_type'],
|
|
|
'#ajax' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_add_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-add_field',
|
|
|
+ 'callback' => 'tripal_bulk_loader_template_fields_ahah',
|
|
|
+ 'wrapper' => 'tripal_bulk_loader_template-template_fields',
|
|
|
'effect' => 'fade'
|
|
|
),
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['field_group'] = array(
|
|
|
+ $form['fields']['field_group'] = array(
|
|
|
'#type' => 'select',
|
|
|
'#title' => 'Record',
|
|
|
'#description' => 'This is used to group a set of fields together allowing '
|
|
@@ -1572,15 +1644,15 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
'#options' => $values['field_group_options'],
|
|
|
'#default_value' => $values['field_group'],
|
|
|
'#ajax' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_add_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-add_field',
|
|
|
+ 'callback' => 'tripal_bulk_loader_template_fields_ahah',
|
|
|
+ 'wrapper' => 'tripal_bulk_loader_template-template_fields',
|
|
|
'effect' => 'fade'
|
|
|
),
|
|
|
'#required' => TRUE,
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['record_name'] = array(
|
|
|
- '#type' => (preg_match('/NEW/', $values['field_group'])) ? 'textfield' : 'hidden',
|
|
|
+ $form['fields']['record_name'] = array(
|
|
|
+ '#type' => ($values['no_record_id']) ? 'textfield' : 'hidden',
|
|
|
'#title' => 'Unique Record Name',
|
|
|
'#prefix' => '<div id="tripal_bulk_loader_template-add_record">',
|
|
|
'#suffix' => '</div>',
|
|
@@ -1588,7 +1660,7 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
'#default_value' => $values['record_name'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['field_title'] = array(
|
|
|
+ $form['fields']['field_title'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => t('Human-readable Title for Field'),
|
|
|
'#default_value' => $values['field_title'],
|
|
@@ -1596,45 +1668,45 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
|
|
|
|
|
|
// Chado Field
|
|
|
- $form['add_fields']['chado'] = array(
|
|
|
+ $form['fields']['chado'] = array(
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => t('Chado Field/Column Details'),
|
|
|
'#description' => t('Specify the Table/Field in chado that this field maps to.'),
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['chado']['chado_table'] = array(
|
|
|
+ $form['fields']['chado']['chado_table'] = array(
|
|
|
'#type' => 'select',
|
|
|
'#title' => t('Chado Table'),
|
|
|
'#options' => $values['chado_table_options'],
|
|
|
'#default_value' => $values['chado_table'],
|
|
|
'#ajax' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_add_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-add_field',
|
|
|
+ 'callback' => 'tripal_bulk_loader_template_fields_ahah',
|
|
|
+ 'wrapper' => 'tripal_bulk_loader_template-template_fields',
|
|
|
'effect' => 'fade'
|
|
|
),
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['chado']['chado_field'] = array(
|
|
|
+ $form['fields']['chado']['chado_field'] = array(
|
|
|
'#type' => 'select',
|
|
|
'#title' => t('Chado Field/Column'),
|
|
|
'#options' => $values['chado_field_options'],
|
|
|
'#default_value' => $values['chado_field'],
|
|
|
'#ajax' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_add_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-add_field',
|
|
|
+ 'callback' => 'tripal_bulk_loader_template_fields_ahah',
|
|
|
+ 'wrapper' => 'tripal_bulk_loader_template-template_fields',
|
|
|
'effect' => 'fade'
|
|
|
),
|
|
|
);
|
|
|
|
|
|
// loading file data column
|
|
|
- $form['add_fields']['columns'] = array(
|
|
|
+ $form['fields']['columns'] = array(
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => t('Data File Column'),
|
|
|
'#collapsible' => TRUE,
|
|
|
'#collapsed' => ($values['field_type'] == 'table field')? FALSE : TRUE,
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['columns']['column_number'] = array(
|
|
|
+ $form['fields']['columns']['column_number'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => t('Column'),
|
|
|
'#description' => t('Specify the column in the data that this field maps to where the first column is 1.'),
|
|
@@ -1642,14 +1714,14 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
'#default_value' => $values['column_number'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['columns']['column_exposed'] = array(
|
|
|
+ $form['fields']['columns']['column_exposed'] = array(
|
|
|
'#type' => 'checkbox',
|
|
|
'#title' => t('Allow Column to be set for each Bulk Loading Job'),
|
|
|
'#description' => t('Adds a textbox field to the Bulk Loader Page to allow users to set this value.'),
|
|
|
'#default_value' => $values['column_exposed'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['columns']['column_exposed_desc'] = array(
|
|
|
+ $form['fields']['columns']['column_exposed_desc'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => t('Description for exposed field on bulk loading job'),
|
|
|
'#description' => t('This description should tell the user what column should be entered here.'),
|
|
@@ -1657,28 +1729,28 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
);
|
|
|
|
|
|
// Global Value
|
|
|
- $form['add_fields']['constant'] = array(
|
|
|
+ $form['fields']['constant'] = array(
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => t('Constant'),
|
|
|
'#collapsible' => TRUE,
|
|
|
'#collapsed' => ($values['field_type'] == 'constant')? FALSE : TRUE,
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['constant']['constant_value'] = array(
|
|
|
+ $form['fields']['constant']['constant_value'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => t('Constant Value'),
|
|
|
'#description' => t('Specify the value you wish this field to have regardless of data file value.'),
|
|
|
'#default_value' => $values['constant_value']
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['constant']['constant_exposed'] = array(
|
|
|
+ $form['fields']['constant']['constant_exposed'] = array(
|
|
|
'#type' => 'checkbox',
|
|
|
'#title' => t('Allow Constant to be set for each Bulk Loading Job'),
|
|
|
'#description' => t('Adds a textbox field to the Create Bulk Loader Form to allow users to set this value.'),
|
|
|
'#default_value' => $values['constant_exposed'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['constant']['constant_validate'] = array(
|
|
|
+ $form['fields']['constant']['constant_validate'] = array(
|
|
|
'#type' => 'checkbox',
|
|
|
'#title' => t('Ensure value is in table'),
|
|
|
'#description' => t('Checks the database when a bulk loading job is created to ensure the value entered already exists in the database.'),
|
|
@@ -1686,39 +1758,39 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
);
|
|
|
|
|
|
// Foreign Key / Referrer
|
|
|
- $form['add_fields']['foreign_key'] = array(
|
|
|
+ $form['fields']['foreign_key'] = array(
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => 'Record Referral',
|
|
|
'#collapsible' => TRUE,
|
|
|
'#collapsed' => ($values['field_type'] == 'foreign key')? FALSE : TRUE,
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['foreign_key']['show_all_records'] = array(
|
|
|
+ $form['fields']['foreign_key']['show_all_records'] = array(
|
|
|
'#type' => 'checkbox',
|
|
|
'#title' => 'Refer to any record',
|
|
|
'#description' => t('By default, the bulk loader will only allow referral to records in a foreign key relationship. To allow referral to any previous record, check this box'),
|
|
|
'#default_value' => $values['show_all_records'],
|
|
|
'#ajax' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_add_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-add_field',
|
|
|
+ 'callback' => 'tripal_bulk_loader_template_fields_ahah',
|
|
|
+ 'wrapper' => 'tripal_bulk_loader_template-template_fields',
|
|
|
'effect' => 'fade'
|
|
|
),
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['foreign_key']['foreign_record'] = array(
|
|
|
+ $form['fields']['foreign_key']['foreign_record'] = array(
|
|
|
'#type' => 'select',
|
|
|
'#title' => 'Record to refer to',
|
|
|
'#descripion' => 'Select the record that this value should refer to. The record needs to already exist.',
|
|
|
'#options' => $values['foreign_record_options'],
|
|
|
'#ajax' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_add_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-add_field',
|
|
|
+ 'callback' => 'tripal_bulk_loader_template_fields_ahah',
|
|
|
+ 'wrapper' => 'tripal_bulk_loader_template-template_fields',
|
|
|
'effect' => 'fade'
|
|
|
),
|
|
|
'#default_value' => $values['foreign_record'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['foreign_key']['foreign_field'] = array(
|
|
|
+ $form['fields']['foreign_key']['foreign_field'] = array(
|
|
|
'#type' => 'select',
|
|
|
'#title' => 'Field to refer to',
|
|
|
'#descripion' => 'Select the record that this value should refer to. The record needs to already exist.',
|
|
@@ -1727,27 +1799,27 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
);
|
|
|
|
|
|
|
|
|
- $form['add_fields']['additional'] = array(
|
|
|
+ $form['fields']['additional'] = array(
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => 'Additional Options',
|
|
|
'#collapsible' => TRUE,
|
|
|
'#collapsed' => TRUE
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['required'] = array(
|
|
|
+ $form['fields']['additional']['required'] = array(
|
|
|
'#type' => 'checkbox',
|
|
|
'#title' => 'Make this field required',
|
|
|
'#default_value' => $values['required'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform'] = array(
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => 'Transform Data File Value Rules',
|
|
|
'#collapsible' => TRUE,
|
|
|
'#collapsed' => $values['regex_are_set'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['regex_description'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['regex_description'] = array(
|
|
|
'#type' => 'item',
|
|
|
'#markup' => 'A transformation rule allows you to transform the original value '
|
|
|
.'(usually from a user submitted data file) into the form you would like it stored '
|
|
@@ -1758,7 +1830,7 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
.'previous rule.'
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['regex-data'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['regex-data'] = array(
|
|
|
'#tree' => TRUE,
|
|
|
);
|
|
|
foreach ($values['regex-pattern'] as $index => $pattern) {
|
|
@@ -1790,20 +1862,20 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
'#name' => $index,
|
|
|
),
|
|
|
);
|
|
|
- $form['add_fields']['additional']['regex_transform']['regex-data'][$index] = $data_element;
|
|
|
+ $form['fields']['additional']['regex_transform']['regex-data'][$index] = $data_element;
|
|
|
}
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['submit-reorder_regex'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['submit-reorder_regex'] = array(
|
|
|
'#type' => ($values['regex_are_set']) ? 'submit' : 'hidden',
|
|
|
'#value' => 'Save Transformation Rule Order'
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['new_regex'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['new_regex'] = array(
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => 'Add a new Transformation Rule',
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['new_regex']['pattern'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['new_regex']['pattern'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => 'Match Pattern',
|
|
|
'#description' => 'You can use standard php regular expressions in this field to specify a '
|
|
@@ -1814,7 +1886,7 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
.' To match and capture any value use <i>.*</i>',
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['new_regex']['replace'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['new_regex']['replace'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => 'Replacement Pattern',
|
|
|
'#description' => 'This pattern should contain the text you want to replace the match pattern '
|
|
@@ -1825,7 +1897,7 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
|
|
|
if ($values['field_type'] == 'table field') {
|
|
|
$tab = '        ';
|
|
|
- $form['add_fields']['additional']['regex_transform']['new_regex']['replace']['#description'] .= '<p>'
|
|
|
+ $form['fields']['additional']['regex_transform']['new_regex']['replace']['#description'] .= '<p>'
|
|
|
.'The following references are also available for data file fields: <b><#column:<i>number</i>#></b>. '
|
|
|
.'This allows you to substitute other data file values into the current field. For example, '
|
|
|
.'if you had the following line:<br />'
|
|
@@ -1836,17 +1908,17 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
.'Pattern could be \1_<#column:2#> which would insert SNP_15-Jan-2011 into the database.</p>';
|
|
|
}
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['new_regex']['submit-add_transform'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['new_regex']['submit-add_transform'] = array(
|
|
|
'#type' => 'submit',
|
|
|
'#value' => 'Add Transformation',
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['test_regex'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['test_regex'] = array(
|
|
|
'#type' => 'fieldset',
|
|
|
'#title' => 'Test Transformation Rules',
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['test_regex']['test_string'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['test_regex']['test_string'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => 'Test Value',
|
|
|
'#description' => 'This should be a value that you expect the above transformation rules '
|
|
@@ -1854,7 +1926,7 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
'#default_value' => $values['regex-test-string'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['test_regex']['test_result'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['test_regex']['test_result'] = array(
|
|
|
'#type' => 'textfield',
|
|
|
'#title' => 'Test Result',
|
|
|
'#description' => 'This is the value that would be saved to the database after the above transformation '
|
|
@@ -1862,17 +1934,17 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
'#default_value' => $values['regex-test-result'],
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['additional']['regex_transform']['test_regex']['submit-test'] = array(
|
|
|
+ $form['fields']['additional']['regex_transform']['test_regex']['submit-test'] = array(
|
|
|
'#type' => 'submit',
|
|
|
'#value' => 'Test Transformation Rules'
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['submit-add_field'] = array(
|
|
|
+ $form['fields']['submit-save'] = array(
|
|
|
'#type' => 'submit',
|
|
|
'#value' => 'Save Changes'
|
|
|
);
|
|
|
|
|
|
- $form['add_fields']['submit-cancel'] = array(
|
|
|
+ $form['fields']['submit-cancel'] = array(
|
|
|
'#type' => 'submit',
|
|
|
'#value' => 'Cancel'
|
|
|
);
|
|
@@ -1885,7 +1957,7 @@ function tripal_bulk_loader_add_template_field_form($form, $form_state = NULL) {
|
|
|
*
|
|
|
* @ingroup tripal_bulk_loader
|
|
|
*/
|
|
|
-function tripal_bulk_loader_add_template_field_form_validate($form, $form_state) {
|
|
|
+function tripal_bulk_loader_template_field_form_validate($form, $form_state) {
|
|
|
|
|
|
// Don't worry about validation when Cancel button is clicked
|
|
|
if ($form_state['clicked_button']['#value'] == 'Save Changes') {
|
|
@@ -1912,7 +1984,7 @@ function tripal_bulk_loader_add_template_field_form_validate($form, $form_state)
|
|
|
*
|
|
|
* @ingroup tripal_bulk_loader
|
|
|
*/
|
|
|
-function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state) {
|
|
|
+function tripal_bulk_loader_template_field_form_submit($form, &$form_state) {
|
|
|
|
|
|
$op = $form_state['values'][ $form_state['clicked_button']['#name'] ];
|
|
|
if ($op == 'Save Changes') {
|
|
@@ -1975,7 +2047,12 @@ function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state)
|
|
|
}
|
|
|
|
|
|
// Save Template
|
|
|
- $template[$priority]['fields'][] = $field;
|
|
|
+ if ($form_state['storage']['mode'] == 'create') {
|
|
|
+ $template[$priority]['fields'][] = $field;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $template[$priority]['fields'][$form_state['storage']['field_index']] = $field;
|
|
|
+ }
|
|
|
$form_state['storage']['template']->template_array = serialize($template);
|
|
|
$success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
|
|
|
|
|
@@ -1983,10 +2060,6 @@ function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state)
|
|
|
drupal_set_message(t('Successfully Added Field to Template'));
|
|
|
drupal_set_message(t('Template Saved.'));
|
|
|
|
|
|
- //$path = explode('?', $form_state['storage']['referring URL']);
|
|
|
- //parse_str($path[1], $query);
|
|
|
- //$query['template_id'] = $form_state['storage']['template']->template_id;
|
|
|
- //drupal_goto($path[0], $query);
|
|
|
$form_state['rebuild'] = FALSE;
|
|
|
$form_state['redirect'] = 'admin/tripal/loaders/bulk/template/'.$form_state['storage']['template_id'].'/edit';
|
|
|
}
|
|
@@ -2000,10 +2073,6 @@ function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state)
|
|
|
}
|
|
|
}
|
|
|
elseif ($op == 'Cancel') {
|
|
|
- //$path = explode('?', $form_state['storage']['referring URL']);
|
|
|
- //parse_str($path[1], $query);
|
|
|
- //$query['template_id'] = $form_state['storage']['template']->template_id;
|
|
|
- //drupal_goto($path[0], $query);
|
|
|
$form_state['rebuild'] = FALSE;
|
|
|
$form_state['redirect'] = 'admin/tripal/loaders/bulk/template/'.$form_state['storage']['template_id'].'/edit';
|
|
|
}
|
|
@@ -2051,15 +2120,9 @@ function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state)
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Edit Field Form
|
|
|
+ * Delete Field Form
|
|
|
*
|
|
|
- * This form is meant to be called from a bulk loader form. The following should be set
|
|
|
- * in the query section of the path:
|
|
|
- * - template_id=\d+: the template which the edited field is part of
|
|
|
- * - record_id=\d+: the priority or key in the template array of the record the field
|
|
|
- * is currently part of
|
|
|
- * - field_index=\d+: the key of the field in the fields array of the previously
|
|
|
- * specified record
|
|
|
+ * This form is meant to be called from a bulk loader form
|
|
|
*
|
|
|
* @param $form_state
|
|
|
* Contains the values and storage for the form
|
|
@@ -2068,966 +2131,120 @@ function tripal_bulk_loader_add_template_field_form_submit($form, &$form_state)
|
|
|
*
|
|
|
* @ingroup tripal_bulk_loader
|
|
|
*/
|
|
|
-function tripal_bulk_loader_edit_template_field_form($form, $form_state = NULL) {
|
|
|
+function tripal_bulk_loader_delete_template_field_form($form, $form_state) {
|
|
|
$form['#cache'] = TRUE; // Make sure the form is cached.
|
|
|
|
|
|
- // get template id from path
|
|
|
- $template_id = ($_GET['template_id']) ? $_GET['template_id'] : $form_state['values']['template_id'];
|
|
|
+ // get args from path
|
|
|
+ $template_id = (isset($form_state['build_info']['args'][0])) ? $form_state['build_info']['args'][0] : FALSE;
|
|
|
+ $form_state['storage']['template_id'] = $template_id;
|
|
|
+ $record_id = (isset($form_state['build_info']['args'][1])) ? $form_state['build_info']['args'][1] : FALSE;
|
|
|
+ $form_state['storage']['record_id'] = $record_id;
|
|
|
+ $field_id = (isset($form_state['build_info']['args'][2])) ? $form_state['build_info']['args'][2] : FALSE;
|
|
|
+ $form_state['storage']['field_id'] = $field_id;
|
|
|
|
|
|
// if there is no template supplied don't return rest of form
|
|
|
if (!$template_id) {
|
|
|
return $form;
|
|
|
}
|
|
|
|
|
|
- // Pre-set Variables needed for form proper------------------------------------------
|
|
|
-
|
|
|
- // If this is the first load of the form (no form state) we need to initialize some variables
|
|
|
- if (!$form_state['storage']['template']) {
|
|
|
- $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
|
|
|
- $template = db_query($sql, array(':template' => $template_id))->fetchObject();
|
|
|
- $form_state['storage']['template_array'] = unserialize($template->template_array);
|
|
|
- $form_state['storage']['template'] = $template;
|
|
|
-
|
|
|
- $form_state['storage']['record2priority'] = array();
|
|
|
- foreach ($form_state['storage']['template_array'] as $priority => $record_array) {
|
|
|
- if (!is_array($record_array)) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $form_state['storage']['record2priority'][$record_array['record_id']] = $priority;
|
|
|
- }
|
|
|
-
|
|
|
- $form_state['storage']['referring URL'] = $_SERVER["HTTP_REFERER"];
|
|
|
- }
|
|
|
- else {
|
|
|
- $template = $form_state['storage']['template'];
|
|
|
- }
|
|
|
-
|
|
|
- // get the field from the path
|
|
|
- if (!($_GET['record_id']===NULL || $_GET['field_index']===NULL)) {
|
|
|
- $priority = $_GET['record_id'];
|
|
|
- $field_index = $_GET['field_index'];
|
|
|
- $template_field = $form_state['storage']['template_array'][$priority]['fields'][$field_index];
|
|
|
- $form_state['storage']['original_field'] = $template_field;
|
|
|
- $form_state['storage']['original_field']['priority'] = $priority;
|
|
|
- $form_state['storage']['original_field']['field_index'] = $field_index;
|
|
|
- }
|
|
|
- // get field from the form_state
|
|
|
- elseif (!empty($form_state['storage']['original_field']['priority']) && !empty($form_state['storage']['original_field']['field_index'])) {
|
|
|
- $priority = $form_state['storage']['original_field']['priority'];
|
|
|
- $field_index = $form_state['storage']['original_field']['field_index'];
|
|
|
- $template_field = $form_state['storage']['template_array'][$priority]['fields'][$field_index];
|
|
|
- }
|
|
|
-
|
|
|
- $field_type = ($form_state['values']['field_type'])? $form_state['values']['field_type'] : $template_field['type'];
|
|
|
-
|
|
|
- // Get the tables array and default table
|
|
|
- $tables = tripal_core_get_chado_tables(TRUE);
|
|
|
- if ($form_state['values']) {
|
|
|
- $table = $form_state['values']['chado_table'];
|
|
|
- }
|
|
|
- else {
|
|
|
- $table = $form_state['storage']['template_array'][$priority]['table'];
|
|
|
- }
|
|
|
-
|
|
|
- $show_all = ($form_state['values']['show_all_records'] ? $form_state['values']['show_all_records'] : $template_field['show_all_records']);
|
|
|
- $table_description = tripal_core_get_chado_table_schema($table);
|
|
|
-
|
|
|
- // Fields and foreign key / referral mappings
|
|
|
- // build the fields array
|
|
|
- $chado_fields = array();
|
|
|
- foreach ($table_description['fields'] as $field_name => $field_array) {
|
|
|
- $chado_fields[$field_name] = $field_name;
|
|
|
- }
|
|
|
+ $_GET['record_name'] = (isset($_GET['record_name'])) ? $_GET['record_name'] : '';
|
|
|
+ $_GET['field_name'] = (isset($_GET['field_name'])) ? $_GET['field_name'] : '';
|
|
|
+ $_GET['chado_table'] = (isset($_GET['chado_table'])) ? $_GET['chado_table'] : '';
|
|
|
+ $_GET['chado_field'] = (isset($_GET['chado_field'])) ? $_GET['chado_field'] : '';
|
|
|
+ $_GET['data_column'] = (isset($_GET['data_column'])) ? $_GET['data_column'] : '';
|
|
|
+ $_GET['constant_value'] = (isset($_GET['constant_value'])) ? $_GET['constant_value'] : '';
|
|
|
+ $_GET['foreign_record'] = (isset($_GET['foreign_record'])) ? $_GET['foreign_record'] : '';
|
|
|
|
|
|
- $ref_chado_fields = array();
|
|
|
- $fk_options = array();
|
|
|
- $fk_options['NULL'] = 'None';
|
|
|
- if ($field_type == 'foreign key' and !$show_all) {
|
|
|
+ $description = '';
|
|
|
+ $description .= '<table>';
|
|
|
+ $description .= '<tr><th>Record Name</th><th>Field Name</th><th>Chado Table</th><th>Chado Field</th><th>Data Column</th><th>Constant Value</th><th>Foreign Key</th></tr>';
|
|
|
+ $description .= '<tr><td>' . $_GET['record_name']
|
|
|
+ . '</td><td>' . $_GET['field_name']
|
|
|
+ . '</td><td>' . $_GET['chado_table']
|
|
|
+ . '</td><td>' . $_GET['chado_field']
|
|
|
+ . '</td><td>' . $_GET['data_column']
|
|
|
+ . '</td><td>' . $_GET['constant_value']
|
|
|
+ . '</td><td>' . $_GET['foreign_record']
|
|
|
+ . '</td></tr>';
|
|
|
+ $description .= '</table>';
|
|
|
|
|
|
- $foreign_field2table = array();
|
|
|
- foreach ($table_description['foreign keys'] as $key_table => $key_array) {
|
|
|
- foreach ($key_array['columns'] as $left_field => $right_field) {
|
|
|
- //$chado_fields[$left_field] = $left_field;
|
|
|
- $foreign_field2table[$left_field] = $key_table;
|
|
|
- }
|
|
|
- }
|
|
|
-// reset($chado_fields);
|
|
|
+ $description .= '<p><strong>Are you sure you want to delete this field?</strong></p>';
|
|
|
+ $yes = 'Delete Field';
|
|
|
+ $no = 'Cancel';
|
|
|
|
|
|
- // set default field
|
|
|
- if (empty($chado_fields)) {
|
|
|
- $field = NULL;
|
|
|
- }
|
|
|
- elseif ($chado_fields[$form_state['values']['chado_field']]) {
|
|
|
- $field = $form_state['values']['chado_field'];
|
|
|
- }
|
|
|
- elseif ($template_field['field']) {
|
|
|
- $field = $template_field['field'];
|
|
|
- }
|
|
|
- else {
|
|
|
- $field = current($chado_fields);
|
|
|
- }
|
|
|
+ $form['#attributes']['class'][] = 'confirmation';
|
|
|
+ $form['description'] = array('#markup' => $description);
|
|
|
|
|
|
- // Foreign key options
|
|
|
- $foreign_table = $foreign_field2table[$field];
|
|
|
- if ($foreign_table) {
|
|
|
- foreach ($form_state['storage']['record2priority'] as $record_name_ => $priority_ ) {
|
|
|
- if (preg_match('/^' . $foreign_table . '$/', $form_state['storage']['template_array'][$priority_]['table'])) {
|
|
|
- $fk_options[$record_name_] = $record_name_;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- // the user wants to see all of the records
|
|
|
- elseif ($field_type == 'foreign key' and $show_all) {
|
|
|
- foreach ($form_state['storage']['record2priority'] as $record_name => $priority ) {
|
|
|
- $fk_options[$record_name] = $record_name;
|
|
|
- }
|
|
|
+ $form['actions'] = array('#type' => 'actions');
|
|
|
+ $form['actions']['submit'] = array(
|
|
|
+ '#type' => 'submit',
|
|
|
+ '#value' => $yes ? $yes : t('Confirm'),
|
|
|
+ );
|
|
|
+ $form['actions']['cancel'] = array(
|
|
|
+ '#type' => 'link',
|
|
|
+ '#title' => $no ? $no : t('Cancel'),
|
|
|
+ '#href' => 'admin/tripal/loaders/bulk/template/'.$template_id.'/edit',
|
|
|
+ );
|
|
|
+ // By default, render the form using theme_confirm_form().
|
|
|
+ if (!isset($form['#theme'])) {
|
|
|
+ $form['#theme'] = 'confirm_form';
|
|
|
}
|
|
|
|
|
|
- // build the list of referrer table fields
|
|
|
- if ($field_type == 'foreign key') {
|
|
|
- $fk_rec = $form_state['values']['foreign_record'] ? $form_state['values']['foreign_record'] : $template_field['foreign key'];
|
|
|
- if ($fk_rec and $fk_rec != 'None' and $fk_rec != 'NULL') {
|
|
|
-
|
|
|
- // first add in the foreign keys
|
|
|
- $fk_priority = $form_state['storage']['record2priority'][$fk_rec];
|
|
|
- $fk_table = $form_state['storage']['template_array'][$fk_priority]['table'];
|
|
|
- foreach ($table_description['foreign keys'] as $key_table => $key_array) {
|
|
|
- foreach ($key_array['columns'] as $left_field => $right_field) {
|
|
|
- if ($key_table == $fk_table and $left_field == $field) {
|
|
|
- $ref_chado_fields['Foreign Key'][$right_field] = $right_field;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- $fk_description = tripal_core_get_chado_table_schema($fk_table);
|
|
|
- foreach ($fk_description['fields'] as $fk_field_name => $fk_farray) {
|
|
|
- // don't include the FK field it's included above
|
|
|
- if (in_array('Foreign Key', $ref_chado_fields) and
|
|
|
- in_array($fk_field_name, $ref_chado_fields['Foreign Key'])) {
|
|
|
- continue;
|
|
|
- }
|
|
|
- $ref_chado_fields['Additional Table Fields'][$fk_field_name] = $fk_field_name;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ return $form;
|
|
|
+}
|
|
|
|
|
|
- // Ensure other field type fields are reset/cleared except for those of the current type
|
|
|
- // ie: if the type is changed from spreadsheet column to constant, the spreadsheet column
|
|
|
- // fields should be cleared since they don't apply to a constant
|
|
|
- switch ($field_type) {
|
|
|
- case 'table field':
|
|
|
- // clear constant
|
|
|
- $form_state['values']['constant_value'] = NULL;
|
|
|
- $template_field['constant value'] = NULL;
|
|
|
- $form_state['values']['constant_exposed'] = NULL;
|
|
|
- $template_field['exposed'] = NULL;
|
|
|
- $form_state['values']['constant_validate'] = NULL;
|
|
|
- $template_field['exposed_validate'] = NULL;
|
|
|
- // clear foreign key
|
|
|
- // clears by default :)
|
|
|
- break;
|
|
|
- case 'constant':
|
|
|
- // clear spreadsheet column
|
|
|
- $form_state['values']['column_number'] = NULL;
|
|
|
- $form_state['values']['column_exposed'] = NULL;
|
|
|
- $template_field['exposed'] = NULL;
|
|
|
- $form_state['values']['column_exposed_desc'] = NULL;
|
|
|
- $template_field['exposed_description'] = NULL;
|
|
|
- // clear foreign key
|
|
|
- // clears by default :)
|
|
|
- break;
|
|
|
- case 'foreign key':
|
|
|
- // clear constant
|
|
|
- $form_state['values']['constant_value'] = NULL;
|
|
|
- $template_field['constant value'] = NULL;
|
|
|
- $form_state['values']['constant_exposed'] = NULL;
|
|
|
- $template_field['exposed'] = NULL;
|
|
|
- $form_state['values']['constant_validate'] = NULL;
|
|
|
- $template_field['exposed_validate'] = NULL;
|
|
|
- // clear spreadsheet column
|
|
|
- $form_state['values']['column_number'] = NULL;
|
|
|
- $form_state['values']['column_exposed'] = NULL;
|
|
|
- $template_field['exposed'] = NULL;
|
|
|
- $form_state['values']['column_exposed_desc'] = NULL;
|
|
|
- $template_field['exposed_description'] = NULL;
|
|
|
- break;
|
|
|
- }
|
|
|
+/**
|
|
|
+ * Delete Field Form
|
|
|
+ *
|
|
|
+ * This form is meant to be called from a bulk loader form
|
|
|
+ *
|
|
|
+ * @param $form_state
|
|
|
+ * Contains the values and storage for the form
|
|
|
+ * @return
|
|
|
+ * A form array to be rendered by drupal_get_form
|
|
|
+ *
|
|
|
+ * @ingroup tripal_bulk_loader
|
|
|
+ */
|
|
|
+function tripal_bulk_loader_delete_template_field_form_submit($form, &$form_state) {
|
|
|
+ $form_state['rebuild'] = FALSE;
|
|
|
+ $form_state['redirect'] = 'admin/tripal/loaders/bulk/template/'.$form_state['storage']['template_id'].'/edit';
|
|
|
|
|
|
- // Start of Form Proper--------------------------------------------------------------
|
|
|
+ $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
|
|
|
+ $result = db_query($sql, array(':template' => $form_state['storage']['template_id']))->fetchObject();
|
|
|
+ $form_state['storage']['template'] = unserialize($result->template_array);
|
|
|
|
|
|
- $form['template_name'] = array(
|
|
|
- '#type' => 'item',
|
|
|
- '#title' => 'Template',
|
|
|
- '#value' => $template->name,
|
|
|
+ $new_template = tripal_bulk_loader_delete_field(
|
|
|
+ $form_state['storage']['record_id'],
|
|
|
+ $form_state['storage']['field_id'],
|
|
|
+ $form_state['storage']['template']
|
|
|
);
|
|
|
+ if (!empty($new_template)) {
|
|
|
+ $form_state['storage']['template'] = $new_template;
|
|
|
+ }
|
|
|
+ drupal_set_message(t('Deleted Field from Template.'));
|
|
|
|
|
|
- $form['template_id'] = array(
|
|
|
- '#type' => 'hidden',
|
|
|
- '#value' => $template_id,
|
|
|
+ $record = array(
|
|
|
+ 'template_id' => $form_state['storage']['template_id'],
|
|
|
+ 'template_array' => serialize($form_state['storage']['template'])
|
|
|
);
|
|
|
+ drupal_write_record('tripal_bulk_loader_template', $record, array('template_id'));
|
|
|
+ drupal_set_message(t('Template Saved.'));
|
|
|
+}
|
|
|
|
|
|
- $form['edit_fields'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#prefix' => '<div id="tripal_bulk_loader_template-edit_field">',
|
|
|
- '#suffix' => '</div>',
|
|
|
- );
|
|
|
+/**
|
|
|
+ * @section
|
|
|
+ * AHAH Callbacks
|
|
|
+ */
|
|
|
|
|
|
- $form['edit_fields']['field_type'] = array(
|
|
|
- '#type' => 'radios',
|
|
|
- '#title' => t('Type of Field'),
|
|
|
- '#options' => array(
|
|
|
- 'table field' => t('Data Field: Fields which maps to a data file column'),
|
|
|
- 'constant' => t('Constant: Field which remains Constant throughout the data file'),
|
|
|
- 'foreign key' => t('Record Referral: Fields which map to a record in another table'),
|
|
|
- ),
|
|
|
- '#required' => TRUE,
|
|
|
- '#default_value' => $field_type,
|
|
|
- '#ahah' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_edit_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-edit_field',
|
|
|
- 'effect' => 'fade'
|
|
|
- ),
|
|
|
- );
|
|
|
+/**
|
|
|
+ * AHAH Function: Replace $form['fields'] in tripal_bulk_loader_add_template_field_form
|
|
|
+ *
|
|
|
+ * @return
|
|
|
+ * JSON Data printed to the screen
|
|
|
+ *
|
|
|
+ * @ingroup tripal_bulk_loader
|
|
|
+ */
|
|
|
+function tripal_bulk_loader_template_fields_ahah($form, $form_state) {
|
|
|
+ return $form['fields'];
|
|
|
+}
|
|
|
|
|
|
- // check template array for records then edit one more
|
|
|
- if (!$form_state['storage']['record2priority']) {
|
|
|
- $groups = array();
|
|
|
- }
|
|
|
- else {
|
|
|
- $groups = array_flip($form_state['storage']['record2priority']);
|
|
|
- }
|
|
|
- $groups['NONE'] = 'Select a Record';
|
|
|
- $groups['NEW'] = 'New Record';
|
|
|
- $form['edit_fields']['field_group'] = array(
|
|
|
- '#type' => 'select',
|
|
|
- '#title' => 'Record',
|
|
|
- '#description' => 'This is used to group a set of fields together allowing '
|
|
|
- .'multiple records to be inserted into the same table per line of the data file',
|
|
|
- '#options' => $groups,
|
|
|
- '#default_value' => (preg_match('/(\d+|\w+)/', $form_state['values']['field_group'])) ? $form_state['values']['field_group'] : $priority,
|
|
|
- '#ahah' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_edit_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-edit_field',
|
|
|
- 'effect' => 'fade'
|
|
|
- ),
|
|
|
- '#required' => TRUE,
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['record_name'] = array(
|
|
|
- '#type' => (preg_match('/NEW/', $form_state['values']['field_group'])) ? 'textfield' : 'hidden',
|
|
|
- '#title' => 'Unique Record Name',
|
|
|
- '#prefix' => '<div id="tripal_bulk_loader_template-edit_record">',
|
|
|
- '#suffix' => '</div>',
|
|
|
- '#default_value' => $form_state['values']['record_name'],
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['field_title'] = array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Human-readable Title for Field'),
|
|
|
- '#default_value' => ($form_state['values']['field_title']) ? $form_state['values']['field_title'] : $template_field['title'],
|
|
|
- );
|
|
|
-
|
|
|
- // Chado Field
|
|
|
- $form['edit_fields']['chado'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => t('Chado Field/Column Details'),
|
|
|
- '#description' => t('Specify the Table/Field in chado that this field maps to.'),
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['chado']['chado_table'] = array(
|
|
|
- '#type' => 'select',
|
|
|
- '#title' => t('Chado Table'),
|
|
|
- '#options' => $tables,
|
|
|
- '#default_value' => $table,
|
|
|
- '#ahah' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_edit_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-edit_field',
|
|
|
- 'effect' => 'fade'
|
|
|
- ),
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['chado']['chado_field'] = array(
|
|
|
- '#type' => 'select',
|
|
|
- '#title' => t('Chado Field/Column'),
|
|
|
- '#options' => $chado_fields,
|
|
|
- '#default_value' => ($form_state['values']['chado_field']) ? $form_state['values']['chado_field'] : $template_field['field'],
|
|
|
- '#ahah' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_edit_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-edit_field',
|
|
|
- 'effect' => 'fade'
|
|
|
- ),
|
|
|
- );
|
|
|
-
|
|
|
- // data file column
|
|
|
- $form['edit_fields']['columns'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => t('Data File Column'),
|
|
|
- '#collapsible' => TRUE,
|
|
|
- '#collapsed' => ($field_type == 'table field')? FALSE : TRUE,
|
|
|
- );
|
|
|
-
|
|
|
- /**
|
|
|
- $form['edit_fields']['columns']['sheet_name'] = array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Worksheet'),
|
|
|
- '#description' => t('Specify the name of the worksheet.'),
|
|
|
- '#size' => 5,
|
|
|
- '#default_value' => ($form_state['values']['sheet_name'])? $form_state['values']['sheet_name'] : $template_field['spreadsheet sheet'],
|
|
|
- );
|
|
|
- */
|
|
|
-
|
|
|
- $form['edit_fields']['columns']['column_number'] = array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Column'),
|
|
|
- '#description' => t('Specify the column in the data file that this field maps to where the first column is 1.'),
|
|
|
- '#size' => 5,
|
|
|
- '#default_value' => ($form_state['values']['column_number']) ? $form_state['values']['column_number'] : $template_field['spreadsheet column'],
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['columns']['column_exposed'] = array(
|
|
|
- '#type' => 'checkbox',
|
|
|
- '#title' => t('Allow Column to be set for each Bulk Loading Job'),
|
|
|
- '#description' => t('Adds a textbox field to the Bulk Loader Page to allow users to set this value.'),
|
|
|
- '#default_value' => ($form_state['values']['column_exposed']) ? $form_state['values']['column_exposed'] : $template_field['exposed'],
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['columns']['column_exposed_desc'] = array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Description for exposed field on bulk loading job'),
|
|
|
- '#description' => t('This description should tell the user what column should be entered here.'),
|
|
|
- '#default_value' => ($form_state['values']['column_exposed_desc']) ? $form_state['values']['column_exposed_desc'] : $template_field['exposed_description'],
|
|
|
- );
|
|
|
-
|
|
|
- // Global Value
|
|
|
- $form['edit_fields']['constant'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => t('Constant'),
|
|
|
- '#collapsible' => TRUE,
|
|
|
- '#collapsed' => ($field_type == 'constant')? FALSE : TRUE,
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['constant']['constant_value'] = array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => t('Constant Value'),
|
|
|
- '#description' => t('Specify the value you wish this field to have regardless of data file value.'),
|
|
|
- '#default_value' => ($form_state['values']['constant_value']) ? $form_state['values']['constant_value'] : $template_field['constant value'],
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['constant']['constant_exposed'] = array(
|
|
|
- '#type' => 'checkbox',
|
|
|
- '#title' => t('Allow Constant to be set for each Bulk Loading Job'),
|
|
|
- '#description' => t('Adds a textbox field to the Create Bulk Loader Form to allow users to set this value.'),
|
|
|
- '#default_value' => ($form_state['values']['constant_exposed']) ? $form_state['values']['constant_exposed'] : $template_field['exposed'],
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['constant']['constant_validate'] = array(
|
|
|
- '#type' => 'checkbox',
|
|
|
- '#title' => t('Ensure value is in table'),
|
|
|
- '#description' => t('Checks the database when a bulk loading job is created to ensure the value entered already exists in the database.'),
|
|
|
- '#default_value' => ($form_state['values']['constant_validate']) ? $form_state['values']['constant_validate'] : $template_field['exposed_validate'],
|
|
|
- );
|
|
|
-
|
|
|
- // Foreign Key / Referrer
|
|
|
- $form['edit_fields']['foreign_key'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => 'Record Referral',
|
|
|
- '#collapsible' => TRUE,
|
|
|
- '#collapsed' => ($field_type == 'foreign key')? FALSE : TRUE,
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['foreign_key']['show_all_records'] = array(
|
|
|
- '#type' => 'checkbox',
|
|
|
- '#title' => 'Refer to any record',
|
|
|
- '#description' => t('By default, the bulk loader will only allow referral to records in a foreign key relationship. To allow referral to any previous record, check this box'),
|
|
|
- '#default_value' => $show_all,
|
|
|
- '#ahah' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_edit_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-add_field',
|
|
|
- 'effect' => 'fade'
|
|
|
- ),
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['foreign_key']['foreign_record'] = array(
|
|
|
- '#type' => 'select',
|
|
|
- '#title' => 'Record to refer to',
|
|
|
- '#descripion' => 'Select the record that this value should refer to. The record needs to already exist.',
|
|
|
- '#options' => $fk_options,
|
|
|
- '#ahah' => array(
|
|
|
- 'callback' => 'tripal_bulk_loader_edit_field_ahah',
|
|
|
- 'wrapper' => 'tripal_bulk_loader_template-add_field',
|
|
|
- 'effect' => 'fade'
|
|
|
- ),
|
|
|
- '#default_value' => ($form_state['values']['foreign_record']) ? $form_state['values']['foreign_record'] : $template_field['foreign key'],
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['foreign_key']['foreign_field'] = array(
|
|
|
- '#type' => 'select',
|
|
|
- '#title' => 'Field to refer to',
|
|
|
- '#descripion' => 'Select the record that this value should refer to. The record needs to already exist.',
|
|
|
- '#options' => $ref_chado_fields,
|
|
|
- '#default_value' => ($form_state['values']['foreign_field']) ? $form_state['values']['foreign_field'] : $template_field['foreign field'],
|
|
|
- );
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $form['edit_fields']['additional'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => 'Additional Options',
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['required'] = array(
|
|
|
- '#type' => 'checkbox',
|
|
|
- '#title' => 'Make this field required',
|
|
|
- '#default_value' => (!empty($form_state['values']['required'])) ? $form_state['values']['required'] : $template_field['required'],
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => 'Transform Data File Value Rules',
|
|
|
- '#collapsible' => TRUE,
|
|
|
- '#collapsed' => (!$template_field['regex']['pattern']) ? TRUE : FALSE,
|
|
|
- );
|
|
|
-
|
|
|
- $transformation_msg = '<p>A transformation rule allows you to transform the original value '
|
|
|
- .'(usually from a user submitted data file) into the form you would like it stored '
|
|
|
- .'in the chado database. Each rule consists of a match pattern (a php regular expression '
|
|
|
- .'which determines which replacement patterns are applied and captures regions of the '
|
|
|
- .'original value) and a replacement pattern (a string which may contain capture references '
|
|
|
- .'that describes what the new value should be). Each rule is applied to the result of the '
|
|
|
- .'previous rule.<p>';
|
|
|
- $form['edit_fields']['additional']['regex_transform']['regex_description'] = array(
|
|
|
- '#type' => 'item',
|
|
|
- '#value' => $transformation_msg,
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['regex-data'] = array(
|
|
|
- '#tree' => TRUE,
|
|
|
- );
|
|
|
-
|
|
|
- if (!is_array($template_field['regex']['pattern'])) {
|
|
|
- $template_field['regex']['pattern'] = array();
|
|
|
- }
|
|
|
- $key_options = array();
|
|
|
- foreach ($template_field['regex']['pattern'] as $k => $v) {
|
|
|
- $key_options[$k] = $k;
|
|
|
- }
|
|
|
- foreach ($template_field['regex']['pattern'] as $index => $pattern) {
|
|
|
- $data_element = array(
|
|
|
- 'pattern' => array(
|
|
|
- '#type' => 'item',
|
|
|
- '#value' => $pattern,
|
|
|
- ),
|
|
|
- 'replace' => array(
|
|
|
- '#type' => 'item',
|
|
|
- '#value' => $template_field['regex']['replace'][$index],
|
|
|
- ),
|
|
|
- 'old_index' => array(
|
|
|
- '#type' => 'hidden',
|
|
|
- '#value' => $index,
|
|
|
- ),
|
|
|
- 'new_index' => array(
|
|
|
- '#type' => 'select',
|
|
|
- '#options' => $key_options,
|
|
|
- '#default_value' => $index,
|
|
|
- ),
|
|
|
- 'id' => array(
|
|
|
- '#type' => 'hidden',
|
|
|
- '#value' => $index,
|
|
|
- ),
|
|
|
- 'submit-delete' => array(
|
|
|
- '#type' => 'submit',
|
|
|
- '#value' => 'Delete Transformation',
|
|
|
- '#name' => $index,
|
|
|
- ),
|
|
|
- );
|
|
|
- $form['edit_fields']['additional']['regex_transform']['regex-data'][$index] = $data_element;
|
|
|
- }
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['submit-reorder_regex'] = array(
|
|
|
- '#type' => 'submit',
|
|
|
- '#value' => 'Save Transformation Rule Order'
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['new_regex'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => 'Add a new Transformation Rule',
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['new_regex']['pattern'] = array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => 'Match Pattern',
|
|
|
- '#description' => 'You can use standard <b>php regular expressions</b> in this field to specify a '
|
|
|
- .'pattern. Only if this pattern matches the value in the data file does the replacement '
|
|
|
- .'pattern get applied to the value. To capture a section of your value for use in the '
|
|
|
- .'replacement patten surround with round brackets. For example, <i>GI:(\d+)</i> will match '
|
|
|
- .' NCBI gi numbers and will capture the numerical digits for use in the replacement pattern. '
|
|
|
- .' To match and capture any value use <i>.*</i>',
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['new_regex']['replace'] = array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => 'Replacement Pattern',
|
|
|
- '#description' => '<p>This pattern should contain the text you want to replace the match pattern '
|
|
|
- .'mentioned above. It can include references of the form <b>\n</b> where n is the number of the '
|
|
|
- .'capture in the match pattern. For example, \1 will be replaced with the text matched in your '
|
|
|
- .'first set of round brackets.</p>',
|
|
|
- );
|
|
|
-
|
|
|
- if ($field_type == 'table field') {
|
|
|
- $tab = '        ';
|
|
|
- $form['edit_fields']['additional']['regex_transform']['new_regex']['replace']['#description'] .= '<p>'
|
|
|
- .'The following references are also available for data file fields: <b><#column:<i>number</i>#></b>. '
|
|
|
- .'This allows you to substitute other data file values into the current field. For example, '
|
|
|
- .'if you had the following line:<br />'
|
|
|
- . $tab . 'SNP' . $tab . '15-Jan-2011' . $tab . '1' . $tab . '54' . $tab . 'Contig34355'
|
|
|
- .'<br /> and your current field is for column #1 and you\'re inserting into the chado field '
|
|
|
- .'feature.uniquename then you might want to add in the data to ensure your uniquename is '
|
|
|
- .'unique. The Match Pattern is (.*) to select all the first column and the Replacement '
|
|
|
- .'Pattern could be \1_<#column:2#> which would insert SNP_15-Jan-2011 into the database.</p>';
|
|
|
- }
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['new_regex']['submit-add_transform'] = array(
|
|
|
- '#type' => 'submit',
|
|
|
- '#value' => 'Add Transformation',
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['test_regex'] = array(
|
|
|
- '#type' => 'fieldset',
|
|
|
- '#title' => 'Test Transformation Rules',
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['test_regex']['test_string'] = array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => 'Test Value',
|
|
|
- '#description' => 'This should be a value that you expect the above transformation rules '
|
|
|
- .'to be applied to.',
|
|
|
- '#default_value' => $form_state['storage']['test_regex_test'],
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['test_regex']['test_result'] = array(
|
|
|
- '#type' => 'textfield',
|
|
|
- '#title' => 'Test Result',
|
|
|
- '#description' => 'This is the value that would be saved to the database after the above transformation '
|
|
|
- .'riles were applied to the Test Value.',
|
|
|
- '#default_value' => $form_state['storage']['test_regex_result'],
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['additional']['regex_transform']['test_regex']['submit-test'] = array(
|
|
|
- '#type' => 'submit',
|
|
|
- '#value' => 'Test Transformation Rules'
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['submit-edit_field'] = array(
|
|
|
- '#type' => 'submit',
|
|
|
- '#value' => 'Save Changes'
|
|
|
- );
|
|
|
-
|
|
|
- $form['edit_fields']['submit-cancel'] = array(
|
|
|
- '#type' => 'submit',
|
|
|
- '#value' => 'Cancel'
|
|
|
- );
|
|
|
-
|
|
|
- return $form;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Implements hook_form_validate().
|
|
|
- *
|
|
|
- * @ingroup tripal_bulk_loader
|
|
|
- */
|
|
|
-function tripal_bulk_loader_edit_template_field_form_validate($form, $form_state) {
|
|
|
-
|
|
|
- // Don't worry about validation when Cancel button is clicked
|
|
|
- if ($form_state['clicked_button']['#value'] == 'Save Changes') {
|
|
|
- $is_unique = tripal_bulk_loader_is_record_name_unique(
|
|
|
- $form_state['values']['record_name'],
|
|
|
- $form_state['values']['template_id'],
|
|
|
- $form_state['storage']['template_array']
|
|
|
- );
|
|
|
- $new_record = ($form_state['values']['field_group'] == 'NEW') ? TRUE : FALSE;
|
|
|
- if ((!$is_unique) AND $new_record) {
|
|
|
- form_set_error('record_name', "New Record Name must be unique. '" . $form_state['values']['record_name'] . "' is not unique.");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Edit Field Form Submit
|
|
|
- *
|
|
|
- * @param $form
|
|
|
- * The form that was submitted
|
|
|
- * @param $form_state
|
|
|
- * The values and storage for the form
|
|
|
- *
|
|
|
- * @ingroup tripal_bulk_loader
|
|
|
- */
|
|
|
-function tripal_bulk_loader_edit_template_field_form_submit($form, &$form_state) {
|
|
|
-
|
|
|
- $op = $form_state['values'][ $form_state['clicked_button']['#name'] ];
|
|
|
-
|
|
|
- //Clear Test
|
|
|
- $form_state['storage']['test_regex_result'] = NULL;
|
|
|
- $form_state['storage']['test_regex_test'] = NULL;
|
|
|
-
|
|
|
- if (!$form_state['ahah_submission']) {
|
|
|
- if ($op == 'Save Changes') {
|
|
|
-
|
|
|
- // If new record
|
|
|
- if (preg_match('/NEW/', $form_state['values']['field_group'])) {
|
|
|
- // add new record
|
|
|
- $record_name = $form_state['values']['record_name'];
|
|
|
- $priority = sizeof($form_state['storage']['template_array']) + 1;
|
|
|
- $old_priority = $form_state['storage']['original_field']['priority'];
|
|
|
- $field_index = $form_state['storage']['original_field']['field_index'];
|
|
|
- $form_state['storage']['record2priority'][$record_name] = $priority;
|
|
|
- $form_state['storage']['template_array'][$priority]['table'] = $form_state['values']['chado_table'];
|
|
|
- $form_state['storage']['template_array'][$priority]['record_id'] = $record_name;
|
|
|
-
|
|
|
- }
|
|
|
- else {
|
|
|
- $priority = $form_state['values']['field_group'];
|
|
|
- $old_priority = $form_state['storage']['original_field']['priority'];
|
|
|
- $field_index = $form_state['storage']['original_field']['field_index'];
|
|
|
- $record_name = $form_state['storage']['record2priority'][$priority];
|
|
|
- }
|
|
|
-
|
|
|
- $field = $form_state['storage']['original_field'];
|
|
|
- if ($form_state['values']['field_type'] == 'table field') {
|
|
|
- $field['type'] = 'table field';
|
|
|
- $field['title'] = $form_state['values']['field_title'];
|
|
|
- $field['field'] = $form_state['values']['chado_field'];
|
|
|
- $field['required'] = $form_state['values']['required'];
|
|
|
- //$field['allowed values'] = empty by default;
|
|
|
- $field['spreadsheet column'] = $form_state['values']['column_number'];
|
|
|
- $field['exposed'] = $form_state['values']['column_exposed'];
|
|
|
- $field['exposed_description'] = $form_state['values']['column_exposed_desc'];
|
|
|
- }
|
|
|
- elseif ($form_state['values']['field_type'] == 'constant') {
|
|
|
- $field['type'] = 'constant';
|
|
|
- $field['title'] = $form_state['values']['field_title'];
|
|
|
- $field['field'] = $form_state['values']['chado_field'];
|
|
|
- $field['required'] = $form_state['values']['required'];
|
|
|
- //$field['allowed values'] = empty by default;
|
|
|
- $field['constant value'] = $form_state['values']['constant_value'];
|
|
|
- $field['exposed_validate'] = $form_state['values']['constant_validate'];
|
|
|
- $field['exposed'] = $form_state['values']['constant_exposed'];
|
|
|
- }
|
|
|
- elseif ($form_state['values']['field_type'] == 'foreign key') {
|
|
|
- $field['type'] = 'foreign key';
|
|
|
- $field['title'] = $form_state['values']['field_title'];
|
|
|
- $field['field'] = $form_state['values']['chado_field'];
|
|
|
- $field['show_all_records'] = $form_state['values']['show_all_records'];
|
|
|
- $field['foreign key'] = $form_state['values']['foreign_record'];
|
|
|
- $field['foreign field'] = $form_state['values']['foreign_field'];
|
|
|
-
|
|
|
- $field['required'] = $form_state['values']['required'];
|
|
|
- }
|
|
|
-
|
|
|
- // Deal with any additional options
|
|
|
-
|
|
|
- // if the record has changed...
|
|
|
- $form_state['storage']['template_array'][$priority]['table'] = $form_state['values']['chado_table'];
|
|
|
- if ($old_priority != $priority) {
|
|
|
- $form_state['storage']['template_array'][$priority]['fields'][] = $field;
|
|
|
- unset($form_state['storage']['template_array'][$old_priority]['fields'][$field_index]);
|
|
|
-
|
|
|
- // if there are no fields left delete the old record
|
|
|
- if (!$form_state['storage']['template_array'][$old_priority]['fields']) {
|
|
|
- unset($form_state['storage']['template_array'][$old_priority]);
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- $form_state['storage']['template_array'][$priority]['fields'][$field_index] = $field;
|
|
|
- }
|
|
|
-
|
|
|
- // Save Template
|
|
|
- $form_state['storage']['template']->template_array = serialize($form_state['storage']['template_array']);
|
|
|
- $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
|
|
|
-
|
|
|
- if ($success) {
|
|
|
- drupal_set_message(t('Successfully Updated Field'));
|
|
|
- drupal_set_message(t('Template Saved.'));
|
|
|
-
|
|
|
- $path = explode('?', $form_state['storage']['referring URL']);
|
|
|
- parse_str($path[1], $query);
|
|
|
- $query['template_id'] = $form_state['storage']['template']->template_id;
|
|
|
- drupal_goto($path[0], $query);
|
|
|
- }
|
|
|
- else {
|
|
|
- drupal_set_message(t('Unable to Save Template!'), 'error');
|
|
|
- watchdog('T_bulk_loader',
|
|
|
- 'Unable to save bulk loader template: %template',
|
|
|
- array('%template' => print_r($form_state['storage']['template'], TRUE)),
|
|
|
- WATCHDOG_ERROR
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- elseif ($op == 'Cancel') {
|
|
|
-
|
|
|
- $path = explode('?', $form_state['storage']['referring URL']);
|
|
|
- parse_str($path[1], $query);
|
|
|
- $query['template_id'] = $form_state['storage']['template']->template_id;
|
|
|
- drupal_goto($path[0], $query);
|
|
|
-
|
|
|
- }
|
|
|
- elseif ($op == 'Add Transformation') {
|
|
|
-
|
|
|
- // Add transformation rule to original field
|
|
|
- $form_state['storage']['original_field']['regex']['pattern'][] = '/' . $form_state['values']['pattern'] . '/';
|
|
|
- $form_state['storage']['original_field']['regex']['replace'][] = $form_state['values']['replace'];
|
|
|
-
|
|
|
- // Add original field back into template
|
|
|
- $priority = $form_state['storage']['original_field']['priority'];
|
|
|
- $field_index = $form_state['storage']['original_field']['field_index'];
|
|
|
- $form_state['storage']['template_array'][$priority]['fields'][$field_index] = $form_state['storage']['original_field'];
|
|
|
-
|
|
|
- }
|
|
|
- elseif ($op == 'Save Transformation Rule Order') {
|
|
|
-
|
|
|
- // Generate new regex array
|
|
|
- $new_regex = array();
|
|
|
- $old_regex = $form_state['storage']['original_field']['regex'];
|
|
|
- foreach ($form_state['values']['regex-data'] as $key => $element) {
|
|
|
- $new_regex['pattern'][ $element['new_index'] ] = $old_regex['pattern'][ $element['old_index'] ];
|
|
|
- $new_regex['replace'][ $element['new_index'] ] = $old_regex['replace'][ $element['old_index'] ];
|
|
|
- }
|
|
|
-
|
|
|
- // sort new regex arrays
|
|
|
- ksort($new_regex['pattern']);
|
|
|
- ksort($new_regex['replace']);
|
|
|
-
|
|
|
- // Add back to original field
|
|
|
- $form_state['storage']['original_field']['regex'] = $new_regex;
|
|
|
- $priority = $form_state['storage']['original_field']['priority'];
|
|
|
- $field_index = $form_state['storage']['original_field']['field_index'];
|
|
|
- $form_state['storage']['template_array'][$priority]['fields'][$field_index] = $form_state['storage']['original_field'];
|
|
|
-
|
|
|
- /**
|
|
|
- // Save Template
|
|
|
- $form_state['storage']['template']->template_array = serialize($form_state['storage']['template_array']);
|
|
|
- $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
|
|
|
-
|
|
|
- if ($success) {
|
|
|
- drupal_set_message(t('Successfully Reordered Transformation Rules'));
|
|
|
- drupal_set_message(t('Template Saved.'));
|
|
|
- }
|
|
|
- else {
|
|
|
- drupal_set_message(t('Unable to Save Template!'), 'error');
|
|
|
- watchdog('T_bulk_loader',
|
|
|
- 'Unable to save bulk loader template: %template',
|
|
|
- array('%template' => print_r($form_state['storage']['template'], TRUE)),
|
|
|
- WATCHDOG_ERROR
|
|
|
- );
|
|
|
- }
|
|
|
- */
|
|
|
- }
|
|
|
- elseif ($op == 'Delete Transformation') {
|
|
|
-
|
|
|
- // Unset regex rule
|
|
|
- $index = $form_state['clicked_button']['#name'];
|
|
|
- unset($form_state['storage']['original_field']['regex']['pattern'][$index]);
|
|
|
- unset($form_state['storage']['original_field']['regex']['replace'][$index]);
|
|
|
-
|
|
|
- $priority = $form_state['storage']['original_field']['priority'];
|
|
|
- $field_index = $form_state['storage']['original_field']['field_index'];
|
|
|
- $form_state['storage']['template_array'][$priority]['fields'][$field_index] = $form_state['storage']['original_field'];
|
|
|
-
|
|
|
- /**
|
|
|
- // Save Template
|
|
|
- $form_state['storage']['template']->template_array = serialize($form_state['storage']['template_array']);
|
|
|
- $success = drupal_write_record('tripal_bulk_loader_template', $form_state['storage']['template'], array('template_id'));
|
|
|
-
|
|
|
- if ($success) {
|
|
|
- drupal_set_message(t('Successfully Reordered Transformation Rules'));
|
|
|
- drupal_set_message(t('Template Saved.'));
|
|
|
- }
|
|
|
- else {
|
|
|
- drupal_set_message(t('Unable to Save Template!'), 'error');
|
|
|
- watchdog('T_bulk_loader',
|
|
|
- 'Unable to save bulk loader template: %template',
|
|
|
- array('%template' => print_r($form_state['storage']['template'], TRUE)),
|
|
|
- WATCHDOG_ERROR
|
|
|
- );
|
|
|
- }
|
|
|
- */
|
|
|
-
|
|
|
- }
|
|
|
- elseif ($op == 'Test Transformation Rules') {
|
|
|
-
|
|
|
- $patterns = $form_state['storage']['original_field']['regex']['pattern'];
|
|
|
- $replaces = $form_state['storage']['original_field']['regex']['replace'];
|
|
|
- $test_string = $form_state['values']['test_string'];
|
|
|
- $form_state['storage']['test_regex_result'] = preg_replace($patterns, $replaces, $test_string);
|
|
|
- $form_state['storage']['test_regex_test'] = $test_string;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Delete Field Form
|
|
|
- *
|
|
|
- * This form is meant to be called from a bulk loader form
|
|
|
- *
|
|
|
- * @param $form_state
|
|
|
- * Contains the values and storage for the form
|
|
|
- * @return
|
|
|
- * A form array to be rendered by drupal_get_form
|
|
|
- *
|
|
|
- * @ingroup tripal_bulk_loader
|
|
|
- */
|
|
|
-function tripal_bulk_loader_delete_template_field_form($form, $form_state) {
|
|
|
- $form['#cache'] = TRUE; // Make sure the form is cached.
|
|
|
-
|
|
|
- // get args from path
|
|
|
- $template_id = (isset($form_state['build_info']['args'][0])) ? $form_state['build_info']['args'][0] : FALSE;
|
|
|
- $form_state['storage']['template_id'] = $template_id;
|
|
|
- $record_id = (isset($form_state['build_info']['args'][1])) ? $form_state['build_info']['args'][1] : FALSE;
|
|
|
- $form_state['storage']['record_id'] = $record_id;
|
|
|
- $field_id = (isset($form_state['build_info']['args'][2])) ? $form_state['build_info']['args'][2] : FALSE;
|
|
|
- $form_state['storage']['field_id'] = $field_id;
|
|
|
-
|
|
|
- // if there is no template supplied don't return rest of form
|
|
|
- if (!$template_id) {
|
|
|
- return $form;
|
|
|
- }
|
|
|
-
|
|
|
- $_GET['record_name'] = (isset($_GET['record_name'])) ? $_GET['record_name'] : '';
|
|
|
- $_GET['field_name'] = (isset($_GET['field_name'])) ? $_GET['field_name'] : '';
|
|
|
- $_GET['chado_table'] = (isset($_GET['chado_table'])) ? $_GET['chado_table'] : '';
|
|
|
- $_GET['chado_field'] = (isset($_GET['chado_field'])) ? $_GET['chado_field'] : '';
|
|
|
- $_GET['data_column'] = (isset($_GET['data_column'])) ? $_GET['data_column'] : '';
|
|
|
- $_GET['constant_value'] = (isset($_GET['constant_value'])) ? $_GET['constant_value'] : '';
|
|
|
- $_GET['foreign_record'] = (isset($_GET['foreign_record'])) ? $_GET['foreign_record'] : '';
|
|
|
-
|
|
|
- $description = '';
|
|
|
- $description .= '<table>';
|
|
|
- $description .= '<tr><th>Record Name</th><th>Field Name</th><th>Chado Table</th><th>Chado Field</th><th>Data Column</th><th>Constant Value</th><th>Foreign Key</th></tr>';
|
|
|
- $description .= '<tr><td>' . $_GET['record_name']
|
|
|
- . '</td><td>' . $_GET['field_name']
|
|
|
- . '</td><td>' . $_GET['chado_table']
|
|
|
- . '</td><td>' . $_GET['chado_field']
|
|
|
- . '</td><td>' . $_GET['data_column']
|
|
|
- . '</td><td>' . $_GET['constant_value']
|
|
|
- . '</td><td>' . $_GET['foreign_record']
|
|
|
- . '</td></tr>';
|
|
|
- $description .= '</table>';
|
|
|
-
|
|
|
- $description .= '<p><strong>Are you sure you want to delete this field?</strong></p>';
|
|
|
- $yes = 'Delete Field';
|
|
|
- $no = 'Cancel';
|
|
|
-
|
|
|
- $form['#attributes']['class'][] = 'confirmation';
|
|
|
- $form['description'] = array('#markup' => $description);
|
|
|
-
|
|
|
- $form['actions'] = array('#type' => 'actions');
|
|
|
- $form['actions']['submit'] = array(
|
|
|
- '#type' => 'submit',
|
|
|
- '#value' => $yes ? $yes : t('Confirm'),
|
|
|
- );
|
|
|
- $form['actions']['cancel'] = array(
|
|
|
- '#type' => 'link',
|
|
|
- '#title' => $no ? $no : t('Cancel'),
|
|
|
- '#href' => 'admin/tripal/loaders/bulk/template/'.$template_id.'/edit',
|
|
|
- );
|
|
|
- // By default, render the form using theme_confirm_form().
|
|
|
- if (!isset($form['#theme'])) {
|
|
|
- $form['#theme'] = 'confirm_form';
|
|
|
- }
|
|
|
-
|
|
|
- return $form;
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * Delete Field Form
|
|
|
- *
|
|
|
- * This form is meant to be called from a bulk loader form
|
|
|
- *
|
|
|
- * @param $form_state
|
|
|
- * Contains the values and storage for the form
|
|
|
- * @return
|
|
|
- * A form array to be rendered by drupal_get_form
|
|
|
- *
|
|
|
- * @ingroup tripal_bulk_loader
|
|
|
- */
|
|
|
-function tripal_bulk_loader_delete_template_field_form_submit($form, &$form_state) {
|
|
|
- $form_state['rebuild'] = FALSE;
|
|
|
- $form_state['redirect'] = 'admin/tripal/loaders/bulk/template/'.$form_state['storage']['template_id'].'/edit';
|
|
|
-
|
|
|
- $sql = "SELECT * FROM {tripal_bulk_loader_template} WHERE template_id=:template";
|
|
|
- $result = db_query($sql, array(':template' => $form_state['storage']['template_id']))->fetchObject();
|
|
|
- $form_state['storage']['template'] = unserialize($result->template_array);
|
|
|
-
|
|
|
- $new_template = tripal_bulk_loader_delete_field(
|
|
|
- $form_state['storage']['record_id'],
|
|
|
- $form_state['storage']['field_id'],
|
|
|
- $form_state['storage']['template']
|
|
|
- );
|
|
|
- if (!empty($new_template)) {
|
|
|
- $form_state['storage']['template'] = $new_template;
|
|
|
- }
|
|
|
- drupal_set_message(t('Deleted Field from Template.'));
|
|
|
-
|
|
|
- $record = array(
|
|
|
- 'template_id' => $form_state['storage']['template_id'],
|
|
|
- 'template_array' => serialize($form_state['storage']['template'])
|
|
|
- );
|
|
|
- drupal_write_record('tripal_bulk_loader_template', $record, array('template_id'));
|
|
|
- drupal_set_message(t('Template Saved.'));
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * @section
|
|
|
- * AHAH Callbacks
|
|
|
- */
|
|
|
-
|
|
|
-/**
|
|
|
- * AHAH Function: Replace $form['add_fields'] in tripal_bulk_loader_add_template_field_form
|
|
|
- *
|
|
|
- * @return
|
|
|
- * JSON Data printed to the screen
|
|
|
- *
|
|
|
- * @ingroup tripal_bulk_loader
|
|
|
- */
|
|
|
-function tripal_bulk_loader_add_field_ahah($form, $form_state) {
|
|
|
- return $form['add_fields'];
|
|
|
-}
|
|
|
-
|
|
|
-/**
|
|
|
- * AHAH Function: Replace $form['edit_fields'] in tripal_bulk_loader_edit_template_field_form
|
|
|
- *
|
|
|
- * @return
|
|
|
- * JSON Data printed to the screen
|
|
|
- *
|
|
|
- * @ingroup tripal_bulk_loader
|
|
|
- */
|
|
|
-function tripal_bulk_loader_edit_field_ahah() {
|
|
|
-
|
|
|
- $form_state = array('storage' => NULL, 'submitted' => FALSE);
|
|
|
- $form_build_id = filter_xss($_POST['form_build_id']);
|
|
|
- $form = form_get_cache($form_build_id, $form_state);
|
|
|
- $args = $form['#parameters'];
|
|
|
- $form_id = array_shift($args);
|
|
|
- $form_state['post'] = $form['#post'] = $_POST;
|
|
|
-
|
|
|
- // Enable the submit/validate handlers to determine whether AHAH-submittted.
|
|
|
- $form_state['ahah_submission'] = TRUE;
|
|
|
-
|
|
|
- $form['#programmed'] = $form['#redirect'] = FALSE;
|
|
|
- drupal_process_form($form_id, $form, $form_state);
|
|
|
- $form = drupal_rebuild_form($form_id, $form_state, $args, $form_build_id);
|
|
|
-
|
|
|
- $form_element = $form['edit_fields'];
|
|
|
- // Remove the wrapper so we don't double it up.
|
|
|
- unset($form_element['#prefix'], $form_element['#suffix']);
|
|
|
-
|
|
|
- $output = theme('status_messages');
|
|
|
- $output .= drupal_render($form_element);
|
|
|
-
|
|
|
- // Final rendering callback.
|
|
|
- print drupal_json(array('status' => TRUE, 'data' => $output));
|
|
|
- exit();
|
|
|
-
|
|
|
-}
|