Open Journal Systems  3.3.0
Variables.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 
10 namespace Seboettg\CiteProc\Util;
11 
12 use InvalidArgumentException;
16 use SimpleXMLElement;
17 use stdClass;
18 
25 class Variables
26 {
27 
28  const NAME_VARIABLES = [
29  'author', // author
30  'collection-editor', // editor of the collection holding the item (e.g. the series editor for a book)
31  'composer', // composer (e.g. of a musical score)
32  'container-author', // author of the container holding the item (e.g. the book author for a book chapter)
33  'director', // director (e.g. of a film)
34  'editor', // editor
35  'editorial-director', // managing editor (“Directeur de la Publication” in French)
36  'illustrator', // illustrator (e.g. of a children’s book)
37  'interviewer', // interviewer (e.g. of an interview)
38  'original-author', //
39  'recipient', // recipient (e.g. of a letter)
40  'reviewed-author' // author of the item reviewed by the current item
41  ];
42 
43  const NUMBER_VARIABLES = [
44  'chapter-number', // chapter number
45  'collection-number', // number identifying the collection holding the item (e.g. the series number for a book)
46  'edition', // (container) edition holding the item (e.g. “3” when citing a chapter in the third
47  // edition of a book)
48  'issue', // (container) issue holding the item (e.g. “5” when citing a journal article from
49  // journal volume 2, issue 5)
50  'number', // number identifying the item (e.g. a report number)
51  'number-of-pages', // total number of pages of the cited item
52  'number-of-volumes', // total number of volumes, usable for citing multi-volume books and such
53  'volume' // (container) volume holding the item (e.g. “2” when citing a chapter from book volume 2)
54  ];
55 
56  const DATE_VARIABLES = [
57  'accessed', // date the item has been accessed
58  'container',
59  'event-date', // date the related event took place
60  'issued', // date the item was issued/published
61  'original-date', // (issue) date of the original version
62  'submitted' // date the item (e.g. a manuscript) has been submitted for publication
63  ];
64 
66  'abstract', //abstract of the item (e.g. the abstract of a journal article)
67  'annote', //reader’s notes about the item content
68  'archive', //archive storing the item
69  'archive-location', //storage location within an archive (e.g. a box and folder number)
70  'archive-place', //geographic location of the archive
71  'authority', //issuing or judicial authority (e.g. “USPTO” for a patent, “Fairfax Circuit Court” for
72  //a legal case)
73  'call-number', //call number (to locate the item in a library)
74  'citation-label', //label identifying the item in in-text citations of label styles (e.g. “Ferr78”). May
75  //be assigned by the CSL processor based on item metadata.
76  'citation-number', //index (starting at 1) of the cited reference in the bibliography (generated by the CSL
77  //processor)
78  'collection-title', //title of the collection holding the item (e.g. the series title for a book)
79  'container-title', //title of the container holding the item (e.g. the book title for a book chapter, the
80  //journal title for a journal article)
81  'container-title-short', //short/abbreviated form of “container-title” (also accessible through the “short” form
82  //of the “container-title” variable)
83  'dimensions', //physical (e.g. size) or temporal (e.g. running time) dimensions of the item
84  'DOI', //Digital Object Identifier (e.g. “10.1128/AEM.02591-07”)
85  'event', //name of the related event (e.g. the conference name when citing a conference paper)
86  'event-place', //geographic location of the related event (e.g. “Amsterdam, the Netherlands”)
87  'first-reference-note-number', //number of a preceding note containing the first reference to the item. Assigned
88  // by the CSL processor. The variable holds no value for non-note-based styles, or when
89  // the item hasn’t been cited in any preceding notes.
90  'genre', //class, type or genre of the item (e.g. “adventure” for an adventure movie,
91  //“PhD dissertation” for a PhD thesis),
92  'ISBN', //International Standard Book Number
93  'ISSN', //International Standard Serial Number
94  'jurisdiction', //geographic scope of relevance (e.g. “US” for a US patent)
95  'keyword', //keyword(s) or tag(s) attached to the item
96  'locator', //a cite-specific pinpointer within the item (e.g. a page number within a book, or a
97  //volume in a multi-volume work). Must be accompanied in the input data by a label
98  //indicating the locator type (see the Locators term list), which determines which term
99  //is rendered by cs:label when the “locator” variable is selected.
100  'medium', //medium description (e.g. “CD”, “DVD”, etc.)
101  'note', //(short) inline note giving additional item details (e.g. a concise summary or commentary)
102  'original-publisher', //original publisher, for items that have been republished by a different publisher
103  'original-publisher-place', //geographic location of the original publisher (e.g. “London, UK”)
104  'original-title', //title of the original version (e.g. “Война и мир”, the untranslated Russian title of
105  // “War and Peace”)
106  'page', //range of pages the item (e.g. a journal article) covers in a container (e.g. a journal
107  // issue)
108  'page-first', //first page of the range of pages the item (e.g. a journal article) covers in a
109  //container (e.g. a journal issue)
110  'PMCID', //PubMed Central reference number
111  'PMID', //PubMed reference number
112  'publisher', //publisher
113  'publisher-place', //geographic location of the publisher
114  'references', //resources related to the procedural history of a legal case
115  'reviewed-title', //title of the item reviewed by the current item
116  'scale', //scale of e.g. a map
117  'section', //container section holding the item (e.g. “politics” for a newspaper article)
118  'source', //from whence the item originates (e.g. a library catalog or database)
119  'status', //(publication) status of the item (e.g. “forthcoming”)
120  'title', //primary title of the item
121  'title-short', //short/abbreviated form of “title” (also accessible through the “short” form of the
122  //“title” variable)
123  'URL', //Uniform Resource Locator (e.g. “http://aem.asm.org/cgi/content/full/74/9/2766”)
124  'version', //version of the item (e.g. “2.0.9” for a software program)
125  'year-suffix', //disambiguating year suffix in author-date styles (e.g. “a” in “Doe, 1999a”)
126 
127 
128  ];
129 
134  public static function isDateVariable($name)
135  {
136  return in_array($name, self::DATE_VARIABLES);
137  }
138 
143  public static function isNumberVariable($name)
144  {
145  return in_array($name, self::NUMBER_VARIABLES);
146  }
147 
152  public static function isNameVariable($name)
153  {
154  return in_array($name, self::NAME_VARIABLES);
155  }
156 
164  public static function nameHash(stdClass $data, $variable)
165  {
166  if (!self::isNameVariable($variable)) {
167  throw new InvalidArgumentException("\"$variable\" is not a valid name variable.");
168  }
169  $parent = null;
170  $names = new Names(
171  new SimpleXMLElement(
172  "<names variable=\"$variable\" delimiter=\"-\">".
173  "<name form=\"long\" sort-separator=\",\" name-as-sort-order=\"all\"/></names>"
174  ),
175  $parent
176  );
177  return $names->render($data);
178  }
179 }
Seboettg\CiteProc\Util\Variables\NUMBER_VARIABLES
const NUMBER_VARIABLES
Definition: Variables.php:43
Seboettg\CiteProc\Util\Variables\isNumberVariable
static isNumberVariable($name)
Definition: Variables.php:143
Seboettg\CiteProc\Util\Variables\STANDARD_VARIABLE
const STANDARD_VARIABLE
Definition: Variables.php:65
Seboettg\CiteProc\Util\Variables\NAME_VARIABLES
const NAME_VARIABLES
Definition: Variables.php:28
Seboettg\CiteProc\Util\Variables\isNameVariable
static isNameVariable($name)
Definition: Variables.php:152
Seboettg\CiteProc\Exception\InvalidStylesheetException
Definition: InvalidStylesheetException.php:10
Seboettg\CiteProc\Rendering\Name\Names
Definition: Names.php:36
Seboettg\CiteProc\Util\Variables\nameHash
static nameHash(stdClass $data, $variable)
Definition: Variables.php:164
Seboettg\CiteProc\Exception\CiteProcException
Definition: CiteProcException.php:20
Seboettg\CiteProc\Util\Variables
Definition: Variables.php:25
Seboettg\CiteProc\Util
Definition: CiteProcHelper.php:10
Seboettg\CiteProc\Util\Variables\DATE_VARIABLES
const DATE_VARIABLES
Definition: Variables.php:56
Seboettg\CiteProc\Util\Variables\isDateVariable
static isDateVariable($name)
Definition: Variables.php:134