/** * @covers Geissler\CSL\Names\Name::__construct * @covers Geissler\CSL\Names\Name::render * @covers Geissler\CSL\Names\Name::apply * @covers Geissler\CSL\Names\Name::formatName * @covers Geissler\CSL\Names\Name::getDisplayAndSortOrder */ public function testRenderFormatted() { $layout = '<name name-as-sort-order="all" sort-separator=" "> <name-part name="family" font-variant="small-caps"/> <name-part name="given" prefix="(" suffix=")"/> </name>'; $data = array(array("family" => "Fontaine", "given" => "Jean de")); $this->initElement($layout); $this->assertEquals('<font style="font-variant:small-caps">Fontaine</font> (Jean de)', $this->object->render($data)); }
/** * Render only the names and return them as an array. * * @param array $data * @return array */ public function renderAsArray($data) { $returns = array(); foreach ($this->variables as $variable) { $data = Container::getData()->getVariable($variable); $options = Container::getContext()->getDisambiguationOptions('Geissler\\CSL\\Names\\Name'); $length = count($data); if (isset($options['etAlUseFirst']) == true) { if ($options['etAlUseFirst'] < $length) { $length = $options['etAlUseFirst']; } } elseif (Container::getContext()->getValue('etAlUseFirst', 'citation') !== '' && Container::getContext()->getValue('etAlUseFirst', 'citation') < $length) { $length = Container::getContext()->getValue('etAlUseFirst', 'citation'); } for ($i = 0; $i < $length; $i++) { $returns[] = $this->name->render(array($data[$i])); } } return $returns; }
/** * Render the element. * * @param string $data * @return string */ public function render($data) { switch ($this->variable) { case 'author': case 'collection-editor': case 'composer': case 'container-author': case 'director': case 'editor': case 'editorial-director': case 'illustrator': case 'interviewer': case 'original-author': case 'recipient': case 'reviewed-author': case 'translator': $name = new Name(new \SimpleXMLElement('<name form="long" name-as-sort-order="all"/>')); return $name->render(Container::getData()->getVariable($this->variable)); break; case 'accessed': case 'container': case 'event-date': case 'issued': case 'original-date': case 'submitted': // 00000000 represent the first date and if existing a second date of a date range $format = new Format(); if ($format->format($this->variable) == true) { $data = $format->getData(); $first = $this->formatDate($data[0]); $second = '00000000'; if (isset($data[1]) == true) { $second = $this->formatDate($data[1]); if ($second < $first) { return $second . $first; } return $first . $second; } return $first . $second; } // put empty dates in bibliographies at the end if (Container::getContext()->getName() == 'bibliography') { return ''; } return '0000000000000000'; break; case 'chapter-number': case 'collection-number': case 'edition': case 'issue': case 'number': case 'number-of-pages': case 'number-of-volumes': case 'volume': return (int) Container::getData()->getVariable($this->variable); break; default: return preg_replace('/(<.*?>)(.*?)(<\\/.*?>)/', '$2', Container::getData()->getVariable($this->variable)); break; } }