First off. Thanks for a great module!

I'm trying to import some movie reviews into a project I'm working on. The ratings are simple numbers from 1-10. We have chosen to use the fivestar module to handle the ratings on the Drupal side.

As far I can see these fields are not available on the mapping page.

Does Feeds support fivestar or is it on the roadmap?

Comments

Silicon.Valet’s picture

Status: Active » Needs review

Here's the code to create your own feed plugin. This could probably be easily adapted to add the ability to work with feeds dynamically based on installed fivestar fields. With enough interest, I might take that on.

function YOURMODULE_feeds_processor_targets_alter(&$targets, $entity_type, $bundle_name) {
  switch ($bundle_name) {
    case 'BUNDLEOFINTEREST':
      $targets['ANYTHINGYAWANT'] = array(
        'name'        => t('Add fivestar rating'),
        'description' => t('Imports integer as fivestar vote'),
        'callback'    => '_YOURMODULE_BUNDLE_FIELD_fivestar_importer'
      );
      break;
  }
}

function _YOURMODULE_BUNDLE_FIELD_fivestar_importer($source, $entity, $target, $value) {
  $entity->FIELDNAME['und'][0]['rating'] = $value * 10;  // expected value 0-100. Given value 1-10, so we adapt. 
  $entity->FIELDNAME['und'][0]['target'] = NULL;
}
chrisjlee’s picture

@Silicon.valet How does one test something like that without having to import export? Is there documentation out there already?

Apologies, as I'm quite new to this

johnbarclay’s picture

Simpltests are the best way to test such code without running imports. There are a number of examples in feeds/tests and background on simpletests are at: http://drupal.org/simpletest-tutorial-drupal7

Much like views, fields, etc. such code belongs in the fivestar module or a new contrib module, not the feeds module. That is where you should search for any existing work on feeds, though there doesn't appear to be any work done there #1270616: Feeds support

Silicon.Valet’s picture

we create import data subsets and make sure that we have guids set. That way feeds can rollback the import. (assuming you don't have some rule based changes firing)

InTheLyonsDen’s picture

Silicon.Valet et el,

Any breakthroughs on this process? I have about 5k reviews to import and sync with Fivestar w/ Drupal 7. Thanks!

emackn’s picture

Status: Needs review » Closed (fixed)

Can't you run your import skipping over the ratings, then run a custom sql script to import your five start settings. You could also write a custom field mapper for fivestar data. See http://drupal.org/node/622700#mappingapi

robydago’s picture

@InTheLyonsDen

if the imported ratings will only be used for display (no editing at all)
- or -
you can live with ratings being editable on node edit only and as "raw" numbers, and most importantly, having only one value\state (i.e. not being a vote)

than you can do what I did:

- create a standard numeric field (e.g. called "field_rating") that will be used to import the ratings via feeds
- import the feeds
- create a token field with some php code to select the correct stars display according to the numeric rating field value
e.g.

  echo  '<img src="' . '[site:url]' . 'sites/default/icons/' . '[node:field_rating]' . '_star_rating.png">';

- go google for some nice stars icon sets (like this for example) that you'll save in the path shown in the php code above; each "stripe" of stars will be named, in the example above, 0_star_rating.png, 1_star_rating.png, 2_star_rating.png, etc.

Miszel’s picture

I needed to write a feeds mapper for fivestar for my data import project. I made the code available to the community in a separate module: http://drupal.org/project/feeds_voting_mappers