I am trying to make my own parser and I seem to be having a problem as it pulls the feed and may be mapping correctly but only pulls '1' letter/# for each item
Here is what I have so far - not working but pulls some data
Parser & Mapper
<?php
/**
* Parses PetFinder Feed
*/
class PetFinderParser extends FeedsParser {
/**
* Parses a raw string and populates FeedsImportBatch object from it.
*/
public function parse(FeedsImportBatch $batch, FeedsSource $source) {
// Get the file's content.
$string = $batch->getRaw();
// Parse it...
$result = simplexml_load_string($string);
// this will iterate
$item = array();
foreach ($result->xpath('pets/pet') as $pet) {
$item['guid'] = (string)$pet->id;
$item['animal'] = (string)$pet->animal;
foreach ($pet->xpath('breeds/breed') as $breed) {
$item['breed'][] = (string)$breed->breed;
}
$item['mix'] = (string)$pet->mix;
$item['age'] = (string)$pet->age;
$item['name'] = (string)$pet->name;
$item['shelterId'] = (string)$pet->shelterId;
$item['size'] = (string)$pet->size;
$item['sex'] = (string)$pet->sex;
$item['description'] = (string)$pet->description;
$item['lastUpdate'] = $pet->lastUpdate;
$item['status'] = (string)$pet->status;
foreach ($pet->xpath('options/option') as $opt) {
$item['option'][] = (string)$opt->option;
}
$i = 1;
foreach ($pet->xpath('media/photos/photo') as $photo) {
$item['photos'][$i]['url'] = (string)$photo->photo;
$item['photos'][$i]['id'] = (string)$photo['id'];
$item['photos'][$i]['size'] = (string)$photo['size'];
$i++;
}
}
$batch->setTitle('Pet Finder');
$batch->setItems($item);
/* notes */
}
public function getMappingSources() {
return array(
'guid' => array(
'name' => t('GUID'),
'description' => t('Unique ID.'),
),
'animal' => array(
'name' => t('Type'),
'description' => t('Pet type.'),
),
'breed' => array(
'name' => t('Breed'),//Double check return
'description' => t('Describes pet\'s breeds.'),
),
'mix' => array(
'name' => t('Mix'),//Double check return
'description' => t('Describes whether pet mixxed.'),
),
'age' => array(
'name' => t('Age'),
'description' => t('Pets age.'),
),
'name' => array(
'name' => t('Name'),
'description' => t('Pets name.'),
),
'shelterId' => array(
'name' => t('Shelter'),
'description' => t('Shelter ID number.'),
),
'size' => array(
'name' => t('Size'),
'description' => t('Pets size.'),//Check content
),
'sex' => array(
'name' => t('Sex'),
'description' => t('Pets sex.'),
),
'description' => array(
'name' => t('Description'),
'description' => t('Pets full description.'),
),
'lastUpdate' => array(
'name' => t('Update'),
'description' => t('Pets last update.'),
),
'status' => array(
'name' => t('Adoption Status'),
'description' => t('Pets adption status.'),
),
'option' => array(
'name' => t('Attributes'),
'description' => t('Pet notes.'),
),
'photos' => array(
'name' => t('Photos'),//double check return types
'description' => t('Pet photos.'),
),
);
}
}
?>HOOK
$info['PetFinderParser'] = array(
'name' => 'Pet Finder parser',
'description' => 'Parses custom data from Pet Finder API.',
'handler' => array(
'parent' => 'FeedsParser', // A plugin needs to derive either directly or indirectly from FeedsFetcher, FeedsParser or FeedsProcessor.
'class' => 'PetFinderParser',
'file' => 'PetFinder.inc',
'path' => $path,
//'path' => drupal_get_path('module', 'PetFinder'),
),
);
Comments
Comment #2
stuartgoff commentedhave been moving along and think i got it - thanks to http://drupal.org/node/240993. i have changed status to postponed but can probably be closed.
Comment #3
alex_b commentedGreat! Closing.