1<?php 2namespace dokuwiki\plugin\struct\types; 3 4use dokuwiki\plugin\struct\meta\QueryBuilder; 5use dokuwiki\plugin\struct\meta\QueryBuilderWhere; 6 7class Text extends AbstractMultiBaseType { 8 9 protected $config = array( 10 'prefix' => '', 11 'postfix' => '', 12 ); 13 14 /** 15 * Output the stored data 16 * 17 * @param string|int $value the value stored in the database 18 * @param \Doku_Renderer $R the renderer currently used to render the data 19 * @param string $mode The mode the output is rendered in (eg. XHTML) 20 * @return bool true if $mode could be satisfied 21 */ 22 public function renderValue($value, \Doku_Renderer $R, $mode) { 23 $R->cdata($this->config['prefix'] . $value . $this->config['postfix']); 24 return true; 25 } 26 27 /** 28 * Comparisons are done against the full string (including prefix/postfix) 29 * 30 * @param QueryBuilderWhere $add 31 * @param string $tablealias 32 * @param string $colname 33 * @param string $comp 34 * @param string|string[] $value 35 * @param string $op 36 */ 37 public function filter(QueryBuilderWhere $add, $tablealias, $colname, $comp, $value, $op) { 38 $add = $add->where($op); // open a subgroup 39 $add->where('AND', "$tablealias.$colname != ''"); // make sure the field isn't empty 40 $op = 'AND'; 41 42 /** @var QueryBuilderWhere $add Where additionional queries are added to */ 43 if(is_array($value)) { 44 $add = $add->where($op); // sub where group 45 $op = 'OR'; 46 } 47 $QB = $add->getQB(); 48 foreach((array) $value as $item) { 49 $column = "$tablealias.$colname"; 50 51 if($this->config['prefix']) { 52 $pl = $QB->addValue($this->config['prefix']); 53 $column = "$pl || $column"; 54 } 55 if($this->config['postfix']) { 56 $pl = $QB->addValue($this->config['postfix']); 57 $column = "$column || $pl"; 58 } 59 60 $pl = $QB->addValue($item); 61 $add->where($op, "$column $comp $pl"); 62 } 63 } 64 65} 66