1*38fa36fbSAndreas Gohr<?php 2*38fa36fbSAndreas Gohr 3*38fa36fbSAndreas Gohrnamespace plugin\struct\meta; 4*38fa36fbSAndreas Gohr 5*38fa36fbSAndreas Gohr/** 6*38fa36fbSAndreas Gohr * Class Value 7*38fa36fbSAndreas Gohr * 8*38fa36fbSAndreas Gohr * Holds the value for a single "cell". That value may be an array for multi value columns 9*38fa36fbSAndreas Gohr * 10*38fa36fbSAndreas Gohr * @package plugin\struct\meta 11*38fa36fbSAndreas Gohr */ 12*38fa36fbSAndreas Gohrclass Value { 13*38fa36fbSAndreas Gohr 14*38fa36fbSAndreas Gohr /** @var Column */ 15*38fa36fbSAndreas Gohr protected $column; 16*38fa36fbSAndreas Gohr 17*38fa36fbSAndreas Gohr /** @var array|int|string */ 18*38fa36fbSAndreas Gohr protected $value; 19*38fa36fbSAndreas Gohr 20*38fa36fbSAndreas Gohr /** 21*38fa36fbSAndreas Gohr * Value constructor. 22*38fa36fbSAndreas Gohr * 23*38fa36fbSAndreas Gohr * @param Column $column 24*38fa36fbSAndreas Gohr * @param array|int|string $value 25*38fa36fbSAndreas Gohr */ 26*38fa36fbSAndreas Gohr public function __construct(Column $column, $value) { 27*38fa36fbSAndreas Gohr if($column->isMulti() && !is_array($value)) { 28*38fa36fbSAndreas Gohr $value = array($value); 29*38fa36fbSAndreas Gohr } 30*38fa36fbSAndreas Gohr $this->value = $value; 31*38fa36fbSAndreas Gohr $this->column = $column; 32*38fa36fbSAndreas Gohr } 33*38fa36fbSAndreas Gohr 34*38fa36fbSAndreas Gohr /** 35*38fa36fbSAndreas Gohr * @return Column 36*38fa36fbSAndreas Gohr */ 37*38fa36fbSAndreas Gohr public function getColumn() { 38*38fa36fbSAndreas Gohr return $this->column; 39*38fa36fbSAndreas Gohr } 40*38fa36fbSAndreas Gohr 41*38fa36fbSAndreas Gohr /** 42*38fa36fbSAndreas Gohr * @return array|int|string 43*38fa36fbSAndreas Gohr */ 44*38fa36fbSAndreas Gohr public function getValue() { 45*38fa36fbSAndreas Gohr return $this->value; 46*38fa36fbSAndreas Gohr } 47*38fa36fbSAndreas Gohr 48*38fa36fbSAndreas Gohr /** 49*38fa36fbSAndreas Gohr * Render the value using the given renderer and mode 50*38fa36fbSAndreas Gohr * 51*38fa36fbSAndreas Gohr * @param \Doku_Renderer $R 52*38fa36fbSAndreas Gohr * @param string $mode 53*38fa36fbSAndreas Gohr */ 54*38fa36fbSAndreas Gohr public function render(\Doku_Renderer $R, $mode) { 55*38fa36fbSAndreas Gohr if($this->column->isMulti()) { 56*38fa36fbSAndreas Gohr $this->column->getType()->renderMultiValue($this->value, $R, $mode); 57*38fa36fbSAndreas Gohr } else { 58*38fa36fbSAndreas Gohr $this->column->getType()->renderValue($this->value, $R, $mode); 59*38fa36fbSAndreas Gohr } 60*38fa36fbSAndreas Gohr } 61*38fa36fbSAndreas Gohr} 62