| 1 |
jonen |
1.1 |
<? |
| 2 |
|
|
/* |
| 3 |
|
|
## ----------------------------------------------------------------------------- |
| 4 |
jonen |
1.4 |
## $Id: GenericGUIDataList.php,v 1.3 2003/04/04 21:26:06 joko Exp $ |
| 5 |
jonen |
1.1 |
## ----------------------------------------------------------------------------- |
| 6 |
jonen |
1.2 |
## $Log: GenericGUIDataList.php,v $ |
| 7 |
jonen |
1.4 |
## Revision 1.3 2003/04/04 21:26:06 joko |
| 8 |
|
|
## added comments regarding possible (future) refactoring using the Data::Lift-infrastructure |
| 9 |
|
|
## |
| 10 |
joko |
1.3 |
## Revision 1.2 2003/04/04 00:45:40 jonen |
| 11 |
|
|
## + reworked decode functions |
| 12 |
|
|
## |
| 13 |
jonen |
1.2 |
## Revision 1.1 2003/03/27 01:17:31 jonen |
| 14 |
|
|
## + inital commit (was orginal 'ObjectList.inc) |
| 15 |
|
|
## |
| 16 |
jonen |
1.1 |
## Revision 1.1 2003/03/20 04:17:28 jonen |
| 17 |
|
|
## + initial commit |
| 18 |
|
|
## |
| 19 |
|
|
## Revision 1.2 2003/03/02 04:32:22 cvsmax |
| 20 |
|
|
## + add decode_item functions |
| 21 |
|
|
## |
| 22 |
|
|
## Revision 1.1 2003/03/01 22:57:40 cvsmax |
| 23 |
|
|
## + inital commit |
| 24 |
|
|
## |
| 25 |
|
|
## |
| 26 |
|
|
## ----------------------------------------------------------------------------- |
| 27 |
|
|
*/ |
| 28 |
|
|
|
| 29 |
|
|
/** |
| 30 |
|
|
* Need to make sure we have the DefaultGUIDataList object |
| 31 |
|
|
*/ |
| 32 |
|
|
require_once($phphtmllib."/widgets/data_list/DefaultGUIDataList.inc"); |
| 33 |
|
|
|
| 34 |
|
|
|
| 35 |
|
|
class GenericGUIDataList extends DefaultGUIDataList { |
| 36 |
|
|
|
| 37 |
|
|
/** |
| 38 |
|
|
* Args needed for object list. |
| 39 |
|
|
* Current use: |
| 40 |
|
|
* - use some bits to create locator metadata (see below) |
| 41 |
|
|
* - use all options to propagate to an AdapterProxy (here: GenericDataSource) |
| 42 |
|
|
* as a query to receive a list of objects as response to a rpc-call. |
| 43 |
|
|
* Todo: glossary: ban "*list* of objects" - it's an object *set* !!! (see CPAN's Set::Object) |
| 44 |
|
|
* |
| 45 |
|
|
*/ |
| 46 |
|
|
var $_options = NULL; |
| 47 |
|
|
|
| 48 |
jonen |
1.2 |
/** |
| 49 |
|
|
* Holds a list of hidden elements |
| 50 |
|
|
* |
| 51 |
|
|
*/ |
| 52 |
|
|
var $_hidden_elements = array(); |
| 53 |
|
|
|
| 54 |
jonen |
1.1 |
/** |
| 55 |
|
|
* The constructor is used to pass in some additional |
| 56 |
|
|
* metadata informations as "options". |
| 57 |
|
|
* The "locator metadata hash" isn't passed in here |
| 58 |
|
|
* any more. Handling this one occours one level deeper |
| 59 |
|
|
* inside the "GenericDataSource" Proxy. |
| 60 |
|
|
* |
| 61 |
|
|
* It's still possible to set locator metadata directly by |
| 62 |
|
|
* using the optional key 'locator' inside your options hash. |
| 63 |
|
|
* This can be either a DataSource::Locator instance or a plain |
| 64 |
|
|
* hash. However - it gets merged to the master locator |
| 65 |
|
|
* created by GenericDataSource using 'array_join_merge'. |
| 66 |
|
|
* |
| 67 |
|
|
* @param old: LocatorMetadataHash array - layout: array( type => '', metadata => '', dsn => '' ) |
| 68 |
|
|
* @param old: Query array - layout: array( type => '', metadata => '', dsn => '' ) |
| 69 |
|
|
* |
| 70 |
|
|
* @param new: options array - layout: array( datasource_type => '', [locator => array()] ) |
| 71 |
|
|
* |
| 72 |
|
|
* |
| 73 |
|
|
*/ |
| 74 |
|
|
function GenericGUIDataList($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE, $options = array()) { |
| 75 |
|
|
if ($options) { $this->_options = $options; } |
| 76 |
|
|
$parent = get_parent_class($this); |
| 77 |
|
|
$this->$parent($title, $width = "100%", $default_orderby='', $default_reverseorder=FALSE); |
| 78 |
|
|
} |
| 79 |
|
|
|
| 80 |
|
|
function get_data_source( ) { |
| 81 |
|
|
|
| 82 |
|
|
// finally: create phpHtmlLib source handle (XyzDataListSource) |
| 83 |
|
|
|
| 84 |
|
|
// V1: |
| 85 |
|
|
//$source = new GenericDataSource($this->_locator, $this->_options); |
| 86 |
|
|
//$this->set_data_source( &$source ); |
| 87 |
|
|
|
| 88 |
|
|
/* |
| 89 |
|
|
// V2: |
| 90 |
|
|
loadModule("DataSource::GenericDataSource"); |
| 91 |
|
|
$source = new DataSource_GenericDataSource($this->_locator, $this->_options); |
| 92 |
|
|
$this->set_data_source( &$source ); |
| 93 |
|
|
*/ |
| 94 |
|
|
|
| 95 |
|
|
// V3: |
| 96 |
|
|
/* |
| 97 |
|
|
$proxy = php::mkComponent('DataSource::GenericDataSource', $this->_locator, $this->_options); |
| 98 |
|
|
$source = &$proxy; |
| 99 |
|
|
$this->set_data_source( &$source ); |
| 100 |
|
|
*/ |
| 101 |
|
|
|
| 102 |
|
|
// V4: |
| 103 |
|
|
/* |
| 104 |
|
|
$proxy = php::mkComponent('DataSource::GenericDataSource', array( proxy => '', adapter => ''), $this->_options); |
| 105 |
|
|
$source = &$proxy; |
| 106 |
|
|
$this->set_data_source( &$source ); |
| 107 |
|
|
*/ |
| 108 |
|
|
|
| 109 |
|
|
// V5: |
| 110 |
|
|
//print "options: " . Dumper($this->_options); |
| 111 |
|
|
|
| 112 |
|
|
$initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) ); |
| 113 |
|
|
//print "1st locator: " . Dumper($initial_locator); |
| 114 |
|
|
|
| 115 |
|
|
// OLD |
| 116 |
|
|
//$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options); |
| 117 |
|
|
|
| 118 |
|
|
//print "Test Query:"; |
| 119 |
|
|
//print Dumper($this->_options['query']); |
| 120 |
|
|
$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']); |
| 121 |
|
|
|
| 122 |
|
|
// debug |
| 123 |
|
|
//print "Proxy: " . Dumper($proxy); |
| 124 |
|
|
|
| 125 |
|
|
// V1: |
| 126 |
|
|
//$source = &$proxy; |
| 127 |
|
|
|
| 128 |
|
|
// V2: |
| 129 |
|
|
//$source->make_adapter_transparent(); |
| 130 |
|
|
|
| 131 |
|
|
// V3: |
| 132 |
|
|
$source = $proxy->get_adapter(); |
| 133 |
|
|
|
| 134 |
|
|
// V4: |
| 135 |
|
|
//$source = $this->_datasource; |
| 136 |
|
|
|
| 137 |
|
|
//print "objectlist-source: " . Dumper($source); |
| 138 |
|
|
//exit; |
| 139 |
|
|
|
| 140 |
|
|
$this->set_data_source( &$source ); |
| 141 |
|
|
|
| 142 |
|
|
} |
| 143 |
|
|
|
| 144 |
|
|
function user_setup() { |
| 145 |
|
|
|
| 146 |
|
|
//return; |
| 147 |
|
|
|
| 148 |
|
|
$source = $this->_datasource; |
| 149 |
|
|
//if (!$source) { return; } |
| 150 |
|
|
|
| 151 |
|
|
//print Dumper($source); |
| 152 |
|
|
$headers = $source->get_header(); |
| 153 |
|
|
//print Dumper($headers); |
| 154 |
|
|
|
| 155 |
|
|
$this->set_title( $this->get_title() . ' - ' . $source->get_total_rows() . ' Einträge' ); |
| 156 |
|
|
|
| 157 |
|
|
foreach($headers as $val) { |
| 158 |
|
|
$this->add_header_item($val, "150", $val, SORTABLE, SEARCHABLE); |
| 159 |
|
|
} |
| 160 |
|
|
|
| 161 |
|
|
/* |
| 162 |
|
|
$this->add_header_item("Uid", "200", "uid", SORTABLE, SEARCHABLE); |
| 163 |
|
|
$this->add_header_item("Name", "200", "lastName", SORTABLE, SEARCHABLE, "center"); |
| 164 |
|
|
*/ |
| 165 |
|
|
} |
| 166 |
|
|
|
| 167 |
|
|
|
| 168 |
|
|
/** |
| 169 |
|
|
* This function ensures that the data we place |
| 170 |
|
|
* in a column is aligned according to what the |
| 171 |
|
|
* user wants. |
| 172 |
|
|
* |
| 173 |
|
|
* @param mixed - $obj - the data for the td. |
| 174 |
|
|
* @param string - $col_name - the name of the column header |
| 175 |
|
|
* for this row to render. |
| 176 |
|
|
* @param int - $odd_row - tells us if this cell lives in |
| 177 |
|
|
* an odd # row (for alternating row colors) |
| 178 |
|
|
* @param int - the column # we are working on. |
| 179 |
|
|
* @return TDtag object |
| 180 |
|
|
*/ |
| 181 |
|
|
function wrap_column_item($obj, $col_name) { |
| 182 |
|
|
|
| 183 |
|
|
//make sure its set to something. |
| 184 |
|
|
if ($obj == '') { |
| 185 |
joko |
1.3 |
$obj = " "; |
| 186 |
jonen |
1.1 |
} |
| 187 |
joko |
1.3 |
|
| 188 |
|
|
// decode item / mungle item data? |
| 189 |
|
|
// TODO: use Data::Lift here!!! (like already done in YAA::JobList and YAA::JobDetails) |
| 190 |
|
|
elseif ($this->_options['decode']) { |
| 191 |
|
|
|
| 192 |
|
|
// Proposal using Data::Lift: (see YAA::JobList and YAA::JobDetails) |
| 193 |
|
|
// This class will get shorter and better to maintain! |
| 194 |
|
|
|
| 195 |
|
|
// Picture Data::Lift as a container component handling |
| 196 |
|
|
// *specific* en-/decoding stuff for your very core components. |
| 197 |
|
|
// This way we will have almost all "specific mungling code" at one place. nice thing! |
| 198 |
|
|
|
| 199 |
|
|
/* |
| 200 |
|
|
|
| 201 |
|
|
// 1. expr: string -> object (phpHtmlLib-object: 'html_a'-tag) |
| 202 |
|
|
// returns a phpHtmlLib object of class 'Xyz' containing a http-/html-link |
| 203 |
|
|
// pointing to a View of a different - linked/referenced - object (reference-interpolation) |
| 204 |
|
|
$this->lift1 = php::mkComponent('Data::Lift', $obj, array( metatype => 'expression' ) ); |
| 205 |
|
|
$obj = $this->lift1->to('phpHtmlLib::html_a'); |
| 206 |
|
|
|
| 207 |
|
|
// 2. data: hash -> object (phpHtmlLib-object: 'container'-object containing form) |
| 208 |
|
|
// returns a phpHtmlLib object of class 'Container' containing a html-form made up of |
| 209 |
|
|
// phpHtmlLib form-tags wrapping all attribute-value pairs of the data hash (object-edit) |
| 210 |
|
|
$this->lift2 = php::mkComponent('Data::Lift', $obj, array( metatype => 'item' ) ); |
| 211 |
|
|
$obj = $this->lift2->to('phpHtmlLib::form'); |
| 212 |
|
|
|
| 213 |
|
|
*/ |
| 214 |
|
|
|
| 215 |
jonen |
1.4 |
$utils = php::mkComponent('WebExplorer::utils'); |
| 216 |
|
|
$hidden = $this->_hidden_elements; |
| 217 |
|
|
$options = $this->_options['decode_args']; |
| 218 |
|
|
|
| 219 |
joko |
1.3 |
// 1. if item is match by expression we will replace it with an link object |
| 220 |
jonen |
1.4 |
if ($utils->decode_item_expr($obj, $hidden, $options)) { |
| 221 |
|
|
$obj = $utils->decode_item_expr($obj, $hidden, $options); |
| 222 |
joko |
1.3 |
} |
| 223 |
|
|
|
| 224 |
|
|
// 2. if item is an Array we will replace it with an selection form object |
| 225 |
jonen |
1.4 |
elseif ( $utils->decode_item_array($obj, $hidden, $options) ) { |
| 226 |
|
|
$obj = $utils->decode_item_array($obj, $hidden, $options); |
| 227 |
jonen |
1.1 |
} |
| 228 |
joko |
1.3 |
|
| 229 |
jonen |
1.1 |
} |
| 230 |
joko |
1.3 |
|
| 231 |
jonen |
1.1 |
//make sure we don't put a right border on the last |
| 232 |
|
|
//column we are working on. |
| 233 |
|
|
//$style = "padding-left: 3px;padding-right:3px;border-top: 1px solid #dddddd;"; |
| 234 |
|
|
|
| 235 |
|
|
|
| 236 |
|
|
if ($this->_columns[$col_name]["data_name"] == $this->orderby()) { |
| 237 |
|
|
$style = "background-color: #f4f4f4;"; |
| 238 |
|
|
} else { |
| 239 |
|
|
$style = "background-color: #ffffff;"; |
| 240 |
|
|
} |
| 241 |
|
|
|
| 242 |
|
|
$align = $this->_columns[$col_name]["align"]; |
| 243 |
|
|
$td = new TDtag(array("align" => $align, |
| 244 |
|
|
"style" => $style, |
| 245 |
|
|
"class" => "datalist_data_cell")); |
| 246 |
|
|
|
| 247 |
|
|
if (is_object($obj) && $obj->_tag == "td") { |
| 248 |
|
|
return $obj; |
| 249 |
|
|
} else { |
| 250 |
|
|
$td->add( $obj ); |
| 251 |
|
|
} |
| 252 |
|
|
return $td; |
| 253 |
|
|
} |
| 254 |
|
|
|
| 255 |
jonen |
1.2 |
function add_hidden_element($label, $value) { |
| 256 |
|
|
$this->_hidden_elements[$label] = $value; |
| 257 |
|
|
} |
| 258 |
|
|
|
| 259 |
|
|
|
| 260 |
jonen |
1.1 |
|
| 261 |
|
|
|
| 262 |
|
|
} |
| 263 |
|
|
?> |