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_group
 13:  *
 14:  * @author sebastian
 15:  */
 16: class Group extends Format {
 17: 
 18:     function render($data, $mode = NULL) {
 19:         $text = '';
 20:         $text_parts = array();
 21:         $terms = $variables = $have_variables = $element_count = 0;
 22:         foreach ($this->elements as $element) {
 23:             $element_count++;
 24:             if (($element instanceof Text) &&
 25:                     ($element->source == 'term' ||
 26:                     $element->source == 'value' )) {
 27:                 $terms++;
 28:             }
 29:             if (($element instanceof Label))
 30:                 $terms++;
 31:             if ($element->source == 'variable' &&
 32:                     isset($element->variable) &&
 33:                     !empty($data->{$element->variable})
 34:             ) {
 35:                 $variables++;
 36:             }
 37:             $text = $element->render($data, $mode);
 38:             $delimiter = $this->delimiter;
 39:             if (!empty($text)) {
 40:                 if ($delimiter && ($element_count < count($this->elements))) {
 41:                     //check to see if the delimiter is already the last character of the text string
 42:                     //if so, remove it so we don't have two of them when we paste together the group
 43:                     $stext = strip_tags(trim($text));
 44:                     if ((strrpos($stext, $delimiter[0]) + 1) == strlen($stext) && strlen($stext) > 1) {
 45:                         $text = str_replace($stext, '----REPLACE----', $text);
 46:                         $stext = substr($stext, 0, -1);
 47:                         $text = str_replace('----REPLACE----', $stext, $text);
 48:                     }
 49:                 }
 50:                 $text_parts[] = $text;
 51:                 if ($element->source == 'variable' || isset($element->variable))
 52:                     $have_variables++;
 53:                 if ($element->source == 'macro')
 54:                     $have_variables++;
 55:             }
 56:         }
 57:         if (empty($text_parts))
 58:             return;
 59:         if ($variables && !$have_variables)
 60:             return; // there has to be at least one other none empty value before the term is output
 61:         if (count($text_parts) == $terms)
 62:             return; // there has to be at least one other none empty value before the term is output
 63:         $delimiter = $this->delimiter;
 64:         $text = implode($delimiter, $text_parts); // insert the delimiter if supplied.
 65:         return $this->format($text);
 66:     }
 67: 
 68:     /**
 69:       function render($data, $mode = NULL) {
 70:       $text = '';
 71:       $text_parts = array();
 72: 
 73:       $terms = $variables = $have_variables = 0;
 74:       $i = 0;
 75:       foreach ($this->elements as $element) {
 76:       if (($element instanceof Text) &&
 77:       ($element->source == 'term' ||
 78:       $element->source == 'value' )) {
 79:       $terms++;
 80:       }
 81:       if (($element instanceof Label))
 82:       $terms++;
 83:       if ($element->source == 'variable' &&
 84:       isset($element->variable) &&
 85:       !empty($data->{$element->variable})
 86:       ) {
 87:       $variables++;
 88:       }
 89: 
 90:       $text = $element->render($data, $mode);
 91: 
 92: 
 93: 
 94:       if (!empty($text)) {
 95:       if (isset($element->source)) {
 96:       $text_parts[$element->getVar()] = $text;
 97:       } else {
 98:       $text_parts[$i] = $text;
 99:       }
100: 
101:       if ($element->source == 'variable' || isset($element->variable))
102:       $have_variables++;
103:       if ($element->source == 'macro')
104:       $have_variables++;
105:       }
106:       $i++;
107:       }
108: 
109:       if (empty($text_parts))
110:       return;
111:       if ($variables && !$have_variables)
112:       return; // there has to be at least one other none empty value before the term is output
113:       if (count($text_parts) == $terms)
114:       return; // there has to be at least one other none empty value before the term is output
115: 
116:       $delimiter = $this->delimiter;
117: 
118:       //Changes @ 2012-06-23 from Sebastian Böttger
119:       //$text = implode($delimiter, $text_parts); // insert the delimiter if supplied.
120:       //own implode function for surrounding group with a span tag with class
121:       //attribute as identifier
122:       $text = $this->implodeGroup($delimiter, $text_parts);
123:       //End changes
124: 
125:       return $this->format($text);
126:       }
127:      * */
128:     /**
129:      * Function added by Sebastian Böttger <boettger@cs.uni-kassel.de>
130:      * 
131:      * Implodes array $text_parts and uses the $delimiter and surrounds every
132:      * part with a span tag.
133:      * 
134:      * @param string $delimiter
135:      * @param array $text_parts
136:      * @return string 
137:      *
138:       function implodeGroup($delimiter, $text_parts) {
139:       $text = '';
140:       $i = 0;
141:       foreach ($text_parts as $key => $val) {
142:       //if (!is_numeric($key)) {
143:       $text .= '<span class="' . $key . '">' . $val . '</span>';
144:       //} else {
145:       //    $text .= $val;
146:       //}
147:       if ($i < count($text_parts) - 1) {
148:       $text .= $delimiter;
149:       }
150:       }
151:       return $text;
152:       }
153:      */
154: }
155: 
API documentation generated by ApiGen