/[drupal]/contributions/modules/feedapi_mapper/feedapi_mapper.admin.inc
ViewVC logotype

Diff of /contributions/modules/feedapi_mapper/feedapi_mapper.admin.inc

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1.2.12, Tue Sep 29 18:47:12 2009 UTC revision 1.1.2.13, Tue Sep 29 20:35:18 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: feedapi_mapper.admin.inc,v 1.1.2.11 2009/09/28 16:53:44 alexb Exp $  // $Id: feedapi_mapper.admin.inc,v 1.1.2.12 2009/09/29 18:47:12 alexb Exp $
3  /**  /**
4   * @file   * @file
5   * Administration-related functions for FeedAPI Mapper   * Administration-related functions for FeedAPI Mapper
# Line 23  function theme_feedapi_mapper_descriptio Line 23  function theme_feedapi_mapper_descriptio
23  }  }
24    
25  /**  /**
26   * Theming function for showing the current mapping.   * Theming function for feedapi_mapper_form().
27   */   */
28  function theme_feedapi_mapper_form($form) {  function theme_feedapi_mapper_form($form) {
29    $output = '';    $output = '';
30    _feedapi_mapper_load_mappers();  
31    $type_url_str = str_replace('_', '-', $form['#node']->type);    // Build and render table.
   if (isset($form['#node']->nid)) {  
     $delete_path = 'node/' . $form['#node']->nid .'/map/delete/';  
     $toggle_unique_path = 'feedapi-mapper/' . $form['#node']->nid .'/unique/';  
   }  
   else {  
     $delete_path = 'admin/content/node-type/'. $type_url_str .'/map/delete/';  
     $toggle_unique_path = 'feedapi-mapper/'. $type_url_str .'/unique/';  
   }  
32    if (isset($form['#mapping']['mapping'])) {    if (isset($form['#mapping']['mapping'])) {
     $active_processors = _feedapi_mapper_get_active_processors($form['#node']->type);  
33      foreach ($form['#mapping']['mapping'] as $feed_path => $node_path) {      foreach ($form['#mapping']['mapping'] as $feed_path => $node_path) {
       $target = unserialize($node_path);  
       if (function_exists($target[0] .'_feedapi_mapper')) {  
         $unique_supported = FALSE;  
         foreach ($active_processors as $processor) {  
           $unique_supported = ($unique_supported | call_user_func($target[0] .'_feedapi_mapper', 'unique supported', $form['#node'], $processor, NULL, $target[1]));  
         }  
         if ($unique_supported == TRUE) {  
           $unique = $form['#mapping']['unique'][$feed_path] ? t('Yes') : t('No');  
           $unique = l($unique, $toggle_unique_path . base64_encode($feed_path) .'/'. drupal_get_token($feed_path));  
         }  
         else {  
           $unique = t('N/A');  
         }  
       }  
34        $rows[] = array(        $rows[] = array(
         // @todo: Set proper messages.  
35          isset($form['#feed_map'][$feed_path]) ? $form['#feed_map'][$feed_path] : '',          isset($form['#feed_map'][$feed_path]) ? $form['#feed_map'][$feed_path] : '',
36          isset($form['#field_map'][$node_path]) ? $form['#field_map'][$node_path] : t('<em>Error: missing target.</em>'),          isset($form['#field_map'][$node_path]) ? $form['#field_map'][$node_path] : '',
37                $unique,                isset($form['#unique_map'][$node_path]) ? $form['#unique_map'][$node_path] : '',
38          l(t('Delete'), $delete_path . base64_encode($feed_path)),          l(t('Delete'), $delete_path . base64_encode($feed_path)),
39        );        );
40      }      }
41    }    }
   
42    $rows[] = array(    $rows[] = array(
43      drupal_render($form['source']),      drupal_render($form['source']),
44      drupal_render($form['target']),      drupal_render($form['target']),
# Line 73  function theme_feedapi_mapper_form($form Line 48  function theme_feedapi_mapper_form($form
48    
49    $form['mapping']['table']['#value'] = theme('table', array(t('Source'), t('Target'), t('Unique')), $rows);    $form['mapping']['table']['#value'] = theme('table', array(t('Source'), t('Target'), t('Unique')), $rows);
50    
51      // Render rest of form.
52    $output .= drupal_render($form);    $output .= drupal_render($form);
53    
54    return $output;    return $output;
# Line 273  function feedapi_mapper_form($form_state Line 249  function feedapi_mapper_form($form_state
249    }    }
250    $form['#mapping'] = $mapping;    $form['#mapping'] = $mapping;
251    
252      // Create the toggle unique path, we will need this later.
253      $type_url_str = str_replace('_', '-', $feed_node->type);
254      if (isset($feed_node->nid)) {
255        $delete_path = 'node/' . $form['#node']->nid .'/map/delete/';
256        $toggle_unique_path = 'feedapi-mapper/' . $form['#node']->nid .'/unique/';
257      }
258      else {
259        $delete_path = 'admin/content/node-type/'. $type_url_str .'/map/delete/';
260        $toggle_unique_path = 'feedapi-mapper/'. $type_url_str .'/unique/';
261      }
262    
263      // Retrieve an array of targets that support "Unique" settings.
264      $unique_supporters = array();
265      $active_processors = _feedapi_mapper_get_active_processors($form['#node']->type);
266      foreach ($field_map as $node_path => $name) {
267        $target = unserialize($node_path);
268        $supported = FALSE;
269        // @todo: avoid this hack.
270        foreach ($active_processors as $processor) {
271          $supported = ($unique_supported | call_user_func($target[0] .'_feedapi_mapper', 'unique supported', $feed_node, $processor, NULL, $target[1]));
272        }
273        if ($supported) {
274          $unique_supporters[$node_path] = $name;
275        }
276      }
277    
278      // Gather the "Unique" status of existing mappings.
279      $form['#unique_map'] = array();
280      foreach ($mapping['mapping'] as $feed_path => $node_path) {
281        $target = unserialize($node_path);
282        if (function_exists($target[0] .'_feedapi_mapper')) {
283          if (!empty($unique_supporters[$node_path])) {
284            $unique = $form['#mapping']['unique'][$feed_path] ? t('Yes') : t('No');
285            $unique = l($unique, $toggle_unique_path . base64_encode($feed_path) .'/'. drupal_get_token($feed_path));
286          }
287          else {
288            $unique = t('N/A');
289          }
290          $form['#unique_map'][$node_path] = $unique;
291        }
292      }
293    
294      // Show the user a warning if there is no mapping is defined unique.
295      if (!count(array_filter($form['#mapping']['unique_elements']))) {
296        drupal_set_message(t('In order to avoid duplicates, it is recommended to define at least one mapping where Unique is set to "Yes".'));
297        $supporters = implode(', ', $unique_supporters);
298        drupal_set_message(t('Targets that support "Unique" setting: !supporters.', array('!supporters' => $supporters)));
299      }
300    
301    // Scope settings: if there is is a node we are on and there is no mapping at all,    // Scope settings: if there is is a node we are on and there is no mapping at all,
302    // we are operating on the content-type defaults. If not it's per-node.    // we are operating on the content-type defaults. If not it's per-node.
303    if ($feed_node->nid && _feedapi_mapper_scope($feed_node->nid)) {    if ($feed_node->nid && _feedapi_mapper_scope($feed_node->nid)) {

Legend:
Removed from v.1.1.2.12  
changed lines
  Added in v.1.1.2.13

  ViewVC Help
Powered by ViewVC 1.1.2