Example #1
0
 /**
  * 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();
 }
Example #2
0
    /**
     * @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());
    }
Example #3
0
 /**
  * As "partial-each", but substitution is limited to the first name of the name variable.
  *
  * @param array $bibliography
  * @return array
  */
 private function partialFirst($bibliography)
 {
     $previous = $this->names->renderAsArray('');
     $length = count($bibliography);
     for ($i = 1; $i < $length; $i++) {
         Container::getData()->next();
         $names = $this->names->renderAsArray('');
         if (isset($names[0]) == true && in_array($names[0], $previous) == true) {
             $bibliography[$i] = preg_replace('/' . preg_quote($names[0], '/') . '/', $this->value, $bibliography[$i]);
         }
         $previous = $names;
     }
     return $bibliography;
 }