Overview

Namespaces

  • academicpuma
    • citeproc

Classes

  • Bibliography
  • Choose
  • Citation
  • CiteProc
  • Collection
  • CSLUtils
  • Date
  • DatePart
  • Element
  • EtAl
  • Factory
  • Format
  • Group
  • Info
  • Label
  • Layout
  • Locale
  • Macro
  • Macros
  • Mapper
  • Name
  • Names
  • Number
  • Option
  • Options
  • PElse
  • PElseIf
  • PIf
  • RenderingElement
  • Sort
  • Style
  • Substitute
  • Terms
  • Text
  • Overview
  • Namespace
  • Class
 1: <?php
 2: 
 3: /*
 4:  * To change this license header, choose License Headers in Project Properties.
 5:  * To change this template file, choose Tools | Templates
 6:  * and open the template in the editor.
 7:  */
 8: 
 9: namespace academicpuma\citeproc;
10: 
11: /**
12:  * Description of csl_number
13:  *
14:  * @author sebastian
15:  */
16: 
17: class Number extends Format {
18: 
19:     function render($data, $mode = NULL) {
20:         $var = $this->variable;
21: 
22:         if (!$var || empty($data->$var))
23:             return;
24: 
25:         //   $form = $this->form;
26: 
27:         switch ($this->form) {
28:             case 'ordinal':
29:                 $text = $this->ordinal($data->$var);
30:                 break;
31:             case 'long-ordinal':
32:                 $text = $this->long_ordinal($data->$var);
33:                 break;
34:             case 'roman':
35:                 $text = $this->roman($data->$var);
36:                 break;
37:             case 'numeric':
38:             default:
39:                 $text = $data->$var;
40:                 break;
41:         }
42:         return $this->format($text);
43:     }
44: 
45:     function ordinal($num) {
46:         if (($num / 10) % 10 == 1) {
47:             $num .= $this->citeproc->get_locale('term', 'ordinal-04');
48:         } elseif ($num % 10 == 1) {
49:             $num .= $this->citeproc->get_locale('term', 'ordinal-01');
50:         } elseif ($num % 10 == 2) {
51:             $num .= $this->citeproc->get_locale('term', 'ordinal-02');
52:         } elseif ($num % 10 == 3) {
53:             $num .= $this->citeproc->get_locale('term', 'ordinal-03');
54:         } else {
55:             $num .= $this->citeproc->get_locale('term', 'ordinal-04');
56:         }
57:         return $num;
58:     }
59: 
60:     function long_ordinal($num) {
61:         $num = sprintf("%02d", $num);
62:         $ret = $this->citeproc->get_locale('term', 'long-ordinal-' . $num);
63:         if (!$ret) {
64:             return $this->ordinal($num);
65:         }
66:         return $ret;
67:     }
68: 
69:     function roman($num) {
70:         $ret = "";
71:         if ($num < 6000) {
72:             $ROMAN_NUMERALS = array(
73:                 array("", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix"),
74:                 array("", "x", "xx", "xxx", "xl", "l", "lx", "lxx", "lxxx", "xc"),
75:                 array("", "c", "cc", "ccc", "cd", "d", "dc", "dcc", "dccc", "cm"),
76:                 array("", "m", "mm", "mmm", "mmmm", "mmmmm")
77:             );
78:             $numstr = strrev($num);
79:             $len = strlen($numstr);
80:             for ($pos = 0; $pos < $len; $pos++) {
81:                 $n = $numstr[$pos];
82:                 $ret = $ROMAN_NUMERALS[$pos][$n] . $ret;
83:             }
84:         }
85: 
86:         return $ret;
87:     }
88: 
89: }
API documentation generated by ApiGen