Open Journal Systems  3.3.0
Substitute.php
1 <?php
2 /*
3  * citeproc-php
4  *
5  * @link http://github.com/seboettg/citeproc-php for the source repository
6  * @copyright Copyright (c) 2016 Sebastian Böttger.
7  * @license https://opensource.org/licenses/MIT
8  */
9 
11 
18 use SimpleXMLElement;
19 use stdClass;
20 
47 class Substitute implements Rendering
48 {
49 
53  private $children;
54 
58  private $parent;
59 
67  public function __construct(SimpleXMLElement $node, Names $parent)
68  {
69  $this->parent = $parent;
70  $this->children = new ArrayList();
71  foreach ($node->children() as $child) {
72 
74  if ($child->getName() === "names") {
75 
77  $names = Factory::create($child, $this);
78 
79  /* A shorthand version of cs:names without child elements, which inherits the attributes values set on
80  the cs:name and cs:et-al child elements of the original cs:names element, may also be used. */
81  if (!$names->hasEtAl()) {
82  // inherit et-al
83  if ($this->parent->hasEtAl()) {
84  $names->setEtAl($this->parent->getEtAl());
85  }
86  }
87  if (!$names->hasName()) {
88  // inherit name
89  if ($this->parent->hasName()) {
90  $names->setName($this->parent->getName());
91  }
92  }
93  // inherit label
94  if (!$names->hasLabel() && $this->parent->hasLabel()) {
95  $names->setLabel($this->parent->getLabel());
96  }
97 
98  $this->children->append($names);
99  } else {
100  $object = Factory::create($child, $this);
101  $this->children->append($object);
102  }
103  }
104  }
105 
111  public function render($data, $citationNumber = null)
112  {
113  $ret = [];
114  if (CiteProc::getContext()->getRenderingState()->getValue() !== RenderingState::SORTING) {
116  }
117 
119  foreach ($this->children as $child) {
120  /* If cs:substitute contains multiple child elements, the first element to return a
121  non-empty result is used for substitution. */
122  $res = $child->render($data, $citationNumber);
123  if (!empty($res)) {
124  $ret[] = $res;
125  break;
126  }
127  }
128  if (CiteProc::getContext()->getRenderingState()->getValue() === RenderingState::SUBSTITUTION) {
130  }
131  return implode("", $ret);
132  }
133 }
Seboettg\CiteProc\Rendering\Name\Substitute\__construct
__construct(SimpleXMLElement $node, Names $parent)
Definition: Substitute.php:73
Seboettg\CiteProc\Rendering\Name\Substitute\render
render($data, $citationNumber=null)
Definition: Substitute.php:117
Seboettg\CiteProc\RenderingState\SORTING
const SORTING
Definition: RenderingState.php:31
Seboettg\CiteProc\Exception\InvalidStylesheetException
Definition: InvalidStylesheetException.php:10
Seboettg\CiteProc\Rendering\Name\Substitute
Definition: Substitute.php:47
Seboettg\CiteProc\Rendering\Name
Definition: EtAl.php:10
Seboettg\CiteProc\CiteProc
Definition: CiteProc.php:32
Seboettg\CiteProc\Rendering\Name\Names
Definition: Names.php:36
Seboettg\CiteProc\RenderingState
Definition: RenderingState.php:27
Seboettg\CiteProc\CiteProc\getContext
static getContext()
Definition: CiteProc.php:45
Seboettg\CiteProc\RenderingState\SUBSTITUTION
const SUBSTITUTION
Definition: RenderingState.php:33
Seboettg\CiteProc\Rendering\Rendering
Definition: Rendering.php:22
Seboettg\Collection\ArrayList
Definition: ArrayList.php:20
Seboettg\CiteProc\Util\Factory
Definition: Util/Factory.php:21
Seboettg\CiteProc\Util\Factory\create
static create($node, $param=null)
Definition: Util/Factory.php:55
Seboettg\CiteProc\RenderingState\RENDERING
const RENDERING
Definition: RenderingState.php:29