/** * Disambiguate citations by the name properties. * * @param array $citations */ private function disambiguateByName($citations) { $identical = array(); $last = false; $lastNames = false; foreach ($citations as $id => $citation) { Container::getData()->moveToId($id); $actualNames = $this->names->render(''); if ($last === false) { $identical = array(); $lastNames = $actualNames; $last = $citation; $identical[] = array('id' => $id, 'citation' => $citation, 'position' => $this->getSortedPosition($id), 'names' => $actualNames); } elseif ($last == $citation || $lastNames == $actualNames) { $identical[] = array('id' => $id, 'citation' => $citation, 'position' => $this->getSortedPosition($id), 'names' => $actualNames); } else { if (count($identical) > 1) { $this->disambiguateIdentical($identical); } $last = $citation; $lastNames = $actualNames; $identical = array(); $identical[] = array('id' => $id, 'citation' => $citation, 'position' => $this->getSortedPosition($id), 'names' => $actualNames); } } if (count($identical) > 1) { $this->disambiguateIdentical($identical); } Container::getContext()->leave(); }
/** * @covers Geissler\CSL\Names\Names::__construct * @covers Geissler\CSL\Names\Names::render * @covers Geissler\CSL\Names\Names::hasAccessEmptyVariable */ public function testRenderEditorAndTranslator1() { $layout = '<names variable="editor translator" delimiter="; "> <label prefix=" (" suffix=")"/> </names>'; $json = '[ { "editor": [ { "family": "Doe", "given": "John", "static-ordering": false } ], "translator": [ { "family": "Johnson", "given": "John", "static-ordering": false } ], "title": "His Anonymous Life", "type": "book" } ]'; $this->initElement($layout, $json); $this->assertEquals('John Doe (editor); John Johnson (translator)', $this->object->render('')); $this->assertFalse($this->object->hasAccessEmptyVariable()); }
/** * Requires a complete match like "complete-all", but now the value of subsequent-author-substitute * substitutes for each rendered name. * * @param array $bibliography * @return array */ private function completeEach($bibliography) { $delimiter = '(' . preg_quote($this->names->getDelimiter(), '/') . '|\\.|;|,)'; $previous = preg_quote($this->names->render(''), '/'); $length = count($bibliography); for ($i = 1; $i < $length; $i++) { if (preg_match('/^' . $previous . $delimiter . '/', $bibliography[$i]) == 1) { $names = $this->names->renderAsArray(''); $values = array_fill(0, count($names), $this->value); $value = str_replace($names, $values, $previous); $bibliography[$i] = preg_replace('/^' . $previous . '/', $value, $bibliography[$i]); Container::getData()->next(); } else { Container::getData()->next(); $previous = preg_quote($this->names->render(''), '/'); } } return $bibliography; }