';
if ($form['source']['#default_value']) {
require_once(drupal_get_path('module', 'feeds_oai_pmh') . '/feeds_oai_pmh.inc');
$result = feeds_oai_pmh_identify($form['source']['#default_value']);
if ($result['status'] == 0) {
$source_config = array_merge($source_config, $result['repository']);
}
elseif (isset($result['repository'])) {
$sets_options = feeds_oai_pmh_sets_options($result['repository']['sets']);
}
else {
$sets_options = feeds_oai_pmh_sets_options(array());
}
}
$form['set'] = array(
'#type' => 'select',
'#title' => t('Set to fetch'),
//Patch : https://drupal.org/files/issues/feeds_oai_pmh-1208926-6-D7.patch
//'#default_value' => isset($source_config['set']) ? $source_config['set'] : NULL,
//'#options' => isset($sets_options) ? $sets_options : array(),
'#default_value' => isset($source_config['set']) ? $source_config['set'] : 0,
'#options' => isset($sets_options) ? $sets_options : array(0 => 'all sets'),
'#suffix' => '',
'#validated' => TRUE,
'#ajax' => array(
'callback' => 'feeds_oai_pmh_ajax_callback',
'wrapper' => 'ahah-element', // ID of div element to update.
'method' => 'replace',
'effect' => 'fade',
'event' => 'change',
),
);
if (isset($source_config['source']) && isset($source_config['set'])) {
$msg = feeds_oai_pmh_current_status_msg($source_config['source'], $source_config['set']);
if ($msg) {
$form['status'] = array(
'#value' => '
' . $msg . '
',
);
}
}
$form['use_dates'] = array(
'#type' => 'checkbox',
'#title' => 'Limit fetch by record creation date',
'#default_value' => isset($source_config['use_dates']) ? $source_config['use_dates'] : NULL,
);
$form['dates'] = array(
'#type' => 'fieldset',
'#title' => t('Record creation dates to fetch'),
// Form element IDs are edit-feeds-[feeds-object]-[form-element-id]
'#states' => array(
'visible' => array(
'#edit-feeds-feedsoaihttpfetcher-use-dates' => array('checked' => TRUE),
),
),
);
if (isset($source_config['earliest_timestamp']) && $source_config['earliest_timestamp'] > 0) {
$date = format_date($source_config['earliest_timestamp'], 'custom', 'M d, Y');
$form['dates']['#description'] = t('Note: earliest record reported by repository is @date',
array('@date' => $date));
}
$form['dates']['from'] = array(
'#type' => 'date',
'#title' => t('Starting date'),
'#default_value' => isset($source_config['dates']['from']) ? $source_config['dates']['from'] : NULL,
);
$form['dates']['to'] = array(
'#type' => 'date',
'#title' => t('Ending date'),
'#default_value' => isset($source_config['dates']['to']) ? $source_config['dates']['to'] : NULL,
);
$form['restart'] = array(
'#type' => 'checkbox',
'#title' => t('Reset import for this repository/set to above settings'),
'#description' => t('This forces any imports that are currently underway
for the chosen repository/set to start over from the beginning.
Normally, all imports that have already begun will only try to fetch
new items until this option is checked, or if the "Delete items"
option is used.'),
'#suffix' => '
',
);
return $form;
}
/**
* Override parent::sourceFormValidate().
*/
public function sourceFormValidate(&$values) {
require_once(drupal_get_path('module', 'feeds_oai_pmh') . '/feeds_oai_pmh.inc');
$result = feeds_oai_pmh_identify($values['source']);
if ($result['status'] != 0) {
return;
}
// TODO: Check that start date <= repository's reported earliest_timestamp
// Check that start date <= end date
if ($values['use_dates']) {
$from_timestamp = $this->dateFieldToTimestamp($values['dates']['from']);
$until_timestamp = $this->dateFieldToTimestamp($values['dates']['to']);
if ($from_timestamp > $until_timestamp) {
form_set_error('feeds][source', t('The ending date must be later than the starting date'));
}
}
// Check for restart option.
if ($values['restart']) {
variable_del('feeds_oai:resumptionToken:' . $values['set'] . ':' . $values['source']);
variable_del('feeds_oai:from:' . $values['set'] . ':' . $values['source']);
unset($values['restart']);
drupal_set_message(t('Import for this repository/set has been reset, ignoring any previous imports.'));
}
}
protected function dateFieldToTimestamp($field_value) {
return mktime(NULL, NULL, NULL,
$field_value['month'], $field_value['day'],
$field_value['year']);
}
}