*/ /** * patTemplate modifier Locale * * Load column from database. The value should be the table's primary key * * Parameter: * - table, name of table to load from * - column, which column to display * * @package patTemplate * @package Modifiers * @author gERD Schaufelberger */ class patTemplate_Modifier_Data extends patTemplate_Modifier { /** * shared table object * @var WBDatasource_Table */ static protected $table = array(); /** * modify the value * * @access public * @param string value * @return string modified value */ public function modify($value, $params = array()) { if (!isset($params['table']) || !isset($params['column'])) { return $value; } if ('0' == $value) { return ''; } if (!isset($params['empty'])) { $params['empty'] = ''; } if (empty($params['dbconfig'])) { $params['dbconfig'] = 'config'; } $clause = array(); $table = $params['table']; $id = $value; $opt = array(); if (isset($params['deleted']) && 0 < $params['deleted']) { $opt['deleted'] = 1; } // load table object if (empty(self::$table[$params['dbconfig']])) { $p = array( 'dbconfig' => $params['dbconfig'] ); self::$table[$params['dbconfig']] = WBClass::create('WBDatasource_Table', $p); } // multi column primary $primary = self::$table[$params['dbconfig']]->getIdentifier($table); if (is_array($primary) && 1 < count($primary)) { array_pop($primary); $id = array($id); while (!empty($primary)) { $p = array_pop($primary); if (empty($params[$p])) { array_unshift($id, 0); } else { array_unshift($id, $params[$p]); } } $id = implode('-', $id); } $list = self::$table[$params['dbconfig']]->get($table, $id, null, array(), $opt); if (empty($list)) { return ''; } if (empty($list[0][$params['column']])) { return $params['empty']; } return $list[0][$params['column']]; } }