Skip to content
Snippets Groups Projects
Commit 7ce2c5f8 authored by Alex Barth's avatar Alex Barth
Browse files

Start work on mapper.

parent 726811d8
No related branches found
No related tags found
No related merge requests found
......@@ -159,10 +159,31 @@ function feeds_ui_build_edit_form_submit($form, &$form_state) {
*/
function feeds_ui_build_mapping_form(&$form_state, $feed) {
$form = array();
$form['submit'] = array(
'#type' => 'submit',
'#value' => t('Save'),
);
// Build a mapping form for each processor configured.
$sources = $feed->parser->getMappingSources();
foreach ($feed->processors as $class => $processor) {
$mappings = $processor->getMappings();
$targets = $processor->getMappingTargets();
$form['processors'][$class] = array(
'#type' => 'fieldset',
'#title' => $class, // @todo: human readable title.
);
$form['processors'][$class]['#mappings'] = $mappings;
$form['processors'][$class]['#targets'] = $targets;
$form['processors'][$class]['sources'] = array(
'#type' => 'select',
'#options' => array('' => t('Select a source')) + drupal_map_assoc($sources),
);
$form['processors'][$class]['targets'] = array(
'#type' => 'select',
'#options' => array('' => t('Select a target')) + drupal_map_assoc(array_keys($targets)),
);
$form['processors'][$class]['add'] = array(
'#type' => 'submit',
'#value' => t('Add'),
);
}
return $form;
}
......@@ -218,4 +239,45 @@ function feeds_ui_build_delete_form(&$form_state, $feed) {
*/
function feeds_ui_build_delete_form_submit($form, &$form_state) {
feeds_delete($form['#feed']->getId());
}
/**
* Theme function for feeds_ui_build_mapping_form().
*/
function theme_feeds_ui_build_mapping_form($form) {
$output = '';
$header = array(
t('Source'),
t('Target'),
t('Unique'),
t('Remove'),
);
foreach (element_children($form['processors']) as $processor) {
$rows = array();
if (is_array($form['processors'][$processor]['#mappings'])) {
foreach ($form['processors'][$processor]['#mappings'] as $mapping) {
$rows[] = array(
// @todo.
);
}
}
if (!count($rows)) {
$rows[] = array(
array(
'colspan' => 4,
'data' => t('No mappings defined.'),
),
);
}
$rows[] = array(
drupal_render($form['processors'][$processor]['sources']),
drupal_render($form['processors'][$processor]['targets']),
'',
drupal_render($form['processors'][$processor]['add']),
);
$form['processors'][$processor]['#value'] = theme('table', $header, $rows);
}
$output .= drupal_render($form);
return $output;
}
\ No newline at end of file
......@@ -91,6 +91,18 @@ function feeds_ui_menu() {
return $items;
}
/**
* Implementation of hook_theme().
*/
function feeds_ui_theme() {
return array(
'feeds_ui_build_mapping_form' => array(
'arguments' => array('form'),
'file' => 'feeds_ui.admin.inc',
),
);
}
/**
* Title callback.
*/
......
......@@ -397,9 +397,33 @@ class FeedsProcessor extends FeedsConfigurable {
* Declare possible mapping targets.
*
* @return
* An array of mapping targets.
* An array of mapping targets. Keys are paths to targets
* separated by ->, values are TRUE if target can be unique,
* FALSE otherwise.
*/
public function getMappingTargets() {
return NULL;
// @todo: invoke hook_feeds_mapper() here.
return array();
}
/**
* Get mappings.
*/
public function getMappings() {
return $this->config->mappings;
}
/**
* Execute mapping on an item.
*/
public function map($item) {
// @todo.
}
/**
* Determine whether a given item is unique.
*/
public function unique($item) {
// @todo.
}
}
\ No newline at end of file
......@@ -5,25 +5,23 @@ class FeedsNodeProcessor extends FeedsProcessor {
function process($feed) {
foreach ($feed->items as $item) {
if (feeds_unique('FeedsNodeProcessor', $item)) {
$node = feeds_map('FeedsNodeProcessor', $item);
if ($this->unique($item)) {
$node = $this->map($item);
node_save($node);
}
}
}
/**
* Return available mapping targets.
*/
function getMappingTargets() {
$config = $this->getConfiguration();
$default = array('title', 'body', 'status');
$default += module_invoke('feedapi_mapper', 'list', 'FeedsNodeProcessor', $config->content_type);
return $default;
}
function map() {
}
function unique() {
return array(
'title' => FALSE,
'body' => FALSE,
'status' => FALSE,
'url' => TRUE,
'guid' => TRUE,
);
}
}
\ No newline at end of file
<?php
// $Id$
/**
* Class definition for Common Syndication Parser.
*
* Parses RSS and Atom feeds.
*/
class FeedsSyndicationParser extends FeedsParser {
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment