Exemplo n.º 1
0
 /**
  * Render the names.
  *
  * @param string|array $data
  * @return string
  */
 public function render($data)
 {
     $returns = array();
     $compare = array();
     $lastSubstitute = Container::getContext()->getSubstitute()->getVariable();
     foreach ($this->variables as $variable) {
         // don't render if variable is already used as substitute value
         if ($lastSubstitute === $variable) {
             return '';
         }
         $names = Container::getData()->getVariable($variable);
         $content = $this->name->render($names);
         // et-al
         if (isset($this->etAl) == true && Container::getContext()->getValue('etAlMin', Container::getContext()->getName()) !== null && Container::getContext()->getValue('etAlMin', Container::getContext()->getName()) <= count($names)) {
             $content = $this->etAl->render($content);
         }
         if ($content !== '') {
             $compare[$variable] = $content;
         }
         // use substitute
         if ($content == '' && isset($this->substitute) == true) {
             $content = $this->substitute->render('');
             if (Container::getContext()->getSubstitute()->getVariable() !== '') {
                 $variable = Container::getContext()->getSubstitute()->getVariable();
             }
         }
         if ($content !== '' && isset($this->label) == true && Container::getContext()->in('sort') == false) {
             $this->label->setVariable($variable);
             if ($this->labelBeforeName == false) {
                 $content .= $this->label->render($content);
             } else {
                 $content = $this->label->render($content) . $content;
             }
         }
         if ($content !== '') {
             $returns[] = $content;
         }
     }
     // The one exception: when the selection consists of "editor" and "translator", and when the contents
     // of these two name variables is identical, then the contents of only one name variable is rendered.
     if (in_array('editor', $this->variables) == true && in_array('translator', $this->variables) == true && isset($compare['editor']) == true && $compare['editor'] == $compare['translator']) {
         $editorTrans = $compare['translator'];
         if (isset($this->label) == true) {
             $plural = 'singular';
             if (count(Container::getData()->getVariable('editor')) > 1 || count(Container::getData()->getVariable('translator')) > 1) {
                 $plural = 'multiple';
             }
             $this->label->setVariable('editortranslator')->setPlural($plural);
             $editorTrans .= $this->label->render('');
         }
         $returns = array($editorTrans);
     }
     $return = implode($this->delimiter, $returns);
     // no formatting while author-only is set for actual cite
     if (Container::getCitationItem() == false || Container::getCitationItem()->get('author-only') == 0 || Container::getCitationItem()->get('author-only') === null) {
         $return = $this->formatting->render($return);
     }
     $return = $this->display->render($return);
     return $this->affix->render($return);
 }
Exemplo n.º 2
0
    /**
     * @covers Geissler\CSL\Rendering\Label::__construct
     * @covers Geissler\CSL\Rendering\Label::setVariable
     * @covers Geissler\CSL\Rendering\Label::render
     * @covers Geissler\CSL\Rendering\Label::hasAccessEmptyVariable
     */
    public function testRenderNot1()
    {
        $layout = '<label plural="contextual" strip-periods="true" />';
        $json = '[
    {
        "editor": [
            {
                "family": "Doe",
                "given": "John",
                "static-ordering": false
            }
        ],
        "id": "ITEM-1",
        "type": "book"
    }
]';
        $this->initElement($layout, $json);
        $this->assertInstanceOf($this->class, $this->object->setVariable('author'));
        $this->assertEquals('', $this->object->render(''));
        $this->assertTrue($this->object->hasAccessEmptyVariable());
    }