You are here

class csl_number in Bibliography Module 7

Same name and namespace in other branches
  1. 6.2 modules/CiteProc/CSL.inc \csl_number
  2. 7.2 modules/CiteProc/CSL.inc \csl_number

Hierarchy

Expanded class hierarchy of csl_number

File

modules/CiteProc/CSL.inc, line 1335
CiteProc-PHP.

View source
class csl_number extends csl_format {

  /**
   *
   */
  public function render($data, $mode = NULL) {
    $var = $this->variable;
    if (!$var || empty($data->{$var})) {
      return;
    }

    // $form = $this->form;.
    switch ($this->form) {
      case 'ordinal':
        $text = $this
          ->ordinal($data->{$var});
        break;
      case 'long-ordinal':
        $text = $this
          ->long_ordinal($data->{$var});
        break;
      case 'roman':
        $text = $this
          ->roman($data->{$var});
        break;
      case 'numeric':
      default:
        $text = $data->{$var};
        break;
    }
    return $this
      ->format($text);
  }

  /**
   *
   */
  public function ordinal($num) {
    if ($num / 10 % 10 == 1) {
      $num .= $this->citeproc
        ->get_locale('term', 'ordinal-04');
    }
    elseif ($num % 10 == 1) {
      $num .= $this->citeproc
        ->get_locale('term', 'ordinal-01');
    }
    elseif ($num % 10 == 2) {
      $num .= $this->citeproc
        ->get_locale('term', 'ordinal-02');
    }
    elseif ($num % 10 == 3) {
      $num .= $this->citeproc
        ->get_locale('term', 'ordinal-03');
    }
    else {
      $num .= $this->citeproc
        ->get_locale('term', 'ordinal-04');
    }
    return $num;
  }

  /**
   *
   */
  public function long_ordinal($num) {
    $num = sprintf("%02d", $num);
    $ret = $this->citeproc
      ->get_locale('term', 'long-ordinal-' . $num);
    if (!$ret) {
      return $this
        ->ordinal($num);
    }
    return $ret;
  }

  /**
   *
   */
  public function roman($num) {
    $ret = "";
    if ($num < 6000) {
      $ROMAN_NUMERALS = array(
        array(
          "",
          "i",
          "ii",
          "iii",
          "iv",
          "v",
          "vi",
          "vii",
          "viii",
          "ix",
        ),
        array(
          "",
          "x",
          "xx",
          "xxx",
          "xl",
          "l",
          "lx",
          "lxx",
          "lxxx",
          "xc",
        ),
        array(
          "",
          "c",
          "cc",
          "ccc",
          "cd",
          "d",
          "dc",
          "dcc",
          "dccc",
          "cm",
        ),
        array(
          "",
          "m",
          "mm",
          "mmm",
          "mmmm",
          "mmmmm",
        ),
      );
      $numstr = strrev($num);
      $len = strlen($numstr);
      for ($pos = 0; $pos < $len; $pos++) {
        $n = $numstr[$pos];
        $ret = $ROMAN_NUMERALS[$pos][$n] . $ret;
      }
    }
    return $ret;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
csl_collection::$elements protected property
csl_collection::add_element public function
csl_element::$attributes protected property
csl_element::$citeproc protected property
csl_element::get_attributes public function
csl_element::get_hier_attributes public function
csl_element::init public function 5
csl_element::name public function
csl_element::set_attributes public function
csl_element::__get public function
csl_element::__isset public function
csl_element::__set public function
csl_element::__unset public function
csl_format::$format protected property 1
csl_format::$no_op protected property
csl_format::format public function Overrides csl_collection::format 1
csl_format::init_formatting public function 5
csl_format::__construct public function Overrides csl_element::__construct 2
csl_number::long_ordinal public function
csl_number::ordinal public function
csl_number::render public function Overrides csl_rendering_element::render
csl_number::roman public function