public function BiblioStyleCiteProc::map in Bibliography Module 7.3
Map the fields from the Biblio entity to the ones known by CiteProc.
1 call to BiblioStyleCiteProc::map()
- BiblioStyleCiteProc::render in plugins/
biblio_style/ citeproc/ BiblioStyleCiteProc.class.php - Render the Biblio according to the style plugin.
File
- plugins/
biblio_style/ citeproc/ BiblioStyleCiteProc.class.php, line 54 - Chicago biblio style.
Class
- BiblioStyleCiteProc
- @file Chicago biblio style.
Code
public function map() {
$mappedBiblio = new stdClass();
// Add the biblio type.
$mappedBiblio->type = str_replace('_', '-', $this->biblio->type);
$mapping = $this
->getMapping();
$wrapper = entity_metadata_wrapper('biblio', $this->biblio);
// Text variables.
foreach ($mapping['biblio']['text'] as $key => $field_name) {
if (!isset($wrapper->{$field_name})) {
continue;
}
$mappedBiblio->{$key} = $wrapper->{$field_name}
->value();
}
// Date variables.
foreach ($mapping['biblio']['date'] as $key => $field_name) {
if (!isset($wrapper->{$field_name})) {
continue;
}
$date = array();
// @todo: Add "In press".
if (strtolower($wrapper->biblio_status
->value()) == 'in press') {
// CiteProc currently doesn't support the literal key. So this is
// actually ignored, however, this is the "right" way.
$mappedBiblio->{$key}->literal = 'In press';
// This hack is just to make sure the In Press is added.
// @todo: Check localization.
$mappedBiblio->{$key}->{'date-parts'}[] = array(
'In press',
);
continue;
}
// Check if the field is date field, or text.
$field = field_info_field($field_name);
if ($field['type'] == 'datestamp') {
// Get the date granularity from the field settings.
$timestamp = $wrapper->{$field_name}
->value();
$date_info = array(
'year' => 'Y',
'month' => 'm',
'day' => 'd',
);
foreach ($date_info as $granularity => $format) {
if (empty($field['settings']['granularity'][$granularity])) {
continue;
}
$date[] = date($format, $timestamp);
}
}
else {
// Textfield, so grab the value as literal.
$date = array(
$wrapper->{$field_name}
->value(),
);
}
$mappedBiblio->{$key}->{'date-parts'}[] = $date;
}
// Add contributors.
if (isset($wrapper->contributor_field_collection) && ($wrapper_contributors = $wrapper->contributor_field_collection)) {
foreach ($wrapper_contributors as $wrapper_contributor) {
if (!($type = strtolower($wrapper_contributor->biblio_contributor_role
->label()))) {
$type = 'author';
}
$mapped_contributor = new stdClass();
$contributor_wrapper = $wrapper_contributor->biblio_contributor;
if (!$wrapper_contributor->biblio_contributor
->value()) {
// No contributors.
continue;
}
// Map the contributor data.
foreach ($mapping['contributor']['text'] as $key => $field_name) {
if (!isset($contributor_wrapper->{$field_name})) {
continue;
}
$mapped_contributor->{$key} = $contributor_wrapper->{$field_name}
->value();
}
if ($mapped_contributor) {
$mappedBiblio->{$type}[] = $mapped_contributor;
}
}
}
return $mappedBiblio;
}