/[cvs]/nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/DataItem.php
ViewVC logotype

Contents of /nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/DataItem.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.3 - (show annotations)
Sun Apr 6 01:40:35 2003 UTC (21 years, 5 months ago) by jonen
Branch: MAIN
Changes since 1.2: +11 -65 lines
+ removed duplicated decode functions

1 <?
2 /*
3 ## -----------------------------------------------------------------------------
4 ## $Id: DataItem.php,v 1.2 2003/04/04 23:58:33 jonen Exp $
5 ## -----------------------------------------------------------------------------
6 ## $Log: DataItem.php,v $
7 ## Revision 1.2 2003/04/04 23:58:33 jonen
8 ## + minor changes
9 ##
10 ## Revision 1.1 2003/04/04 00:32:57 jonen
11 ## + initial commit
12 ##
13 ##
14 ##
15 ## -----------------------------------------------------------------------------
16 */
17
18 class DataItem extends InfoTable {
19
20 /**
21 * holds reference to source object.
22 */
23 var $_datasource = NULL;
24
25 /**
26 * container for arguments needed for e.g. setting the source object.
27 */
28 var $_options = array();
29
30 /**
31 * container for hidden elements.
32 */
33 var $_hidden_elements = array();
34
35 function DataItem($title, $options = array()) {
36 $this->_options = $options;
37
38 $parent = get_parent_class($this);
39 $this->$parent($title, $width="100%", "center");
40
41 // fetch data
42 $this->data_prefetch();
43 }
44
45 function render($indent_level=1, $output_debug=0) {
46 // init data record entries
47 $this->init_elements();
48 // add form container
49 $this->get_form_container();
50
51 $table = html_table( $this->get_width(), 0,
52 $this->get_cellspacing(),
53 $this->get_cellpadding(),
54 $this->get_align());
55 $table->set_class( "infotable" );
56 $table->add( $this->_build_title() );
57
58 $row = $this->_build_header();
59 if ($row != NULL) {
60 $table->add_row( $row );
61 }
62
63 //now go thru the rows of data
64 //and add them
65 foreach( $this->data as $row ) {
66 if ((count($row) == 1) && is_object($row[0]) && (is_a($row[0], "TRtag") ||
67 is_a($row[0], "TDtag"))) {
68 $table->add_row( $row[0] );
69 } else {
70 $tr = new TRtag;
71 $cnt = count( $row );
72 foreach( $row as $index => $data ) {
73 $td = $this->_build_td("", "", $index+1, $cnt );
74 $td->add( $data );
75 $tr->add( $td );
76 }
77 $table->add_row( $tr );
78 }
79 }
80 return $table->render($indent_level, $output_debug);
81 }
82
83 function set_data_source(&$source) {
84 $this->_datasource = &$source;
85 }
86
87 function get_data_source() {
88 $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );
89 $proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']);
90 $source = $proxy->get_adapter();
91 $this->set_data_source( &$source );
92 }
93
94 function _check_datasource($function_name) {
95 if ( !is_object($this->_datasource) ) {
96 user_error("DataList::".$function_name."() - DataListSource object is not set");
97 exit;
98 }
99 }
100
101 function data_prefetch() {
102 $this->get_data_source();
103 $this->_check_datasource("data_prefetch");
104
105 $this->_datasource->do_query();
106 }
107
108 function init_elements() {
109 $result = $this->_datasource->_result;
110 if (is_array($result)) {
111 foreach($result as $key => $value) {
112 if(!$value) { $value = _HTML_SPACE; }
113 // if item is match by expression we will replace it with an link object
114 if($this->_options['decode']) {
115 $utils = php::mkComponent('WebExplorer::utils');
116 $hidden = $this->_hidden_elements;
117 $options = $this->_options['decode_args'];
118 if($utils->decode_item_expr($value, $hidden, $options)) {
119 $this->add_element($key, $utils->decode_item_expr($value, $hidden, $options));
120 }
121 // if item is an Array we will replace it with an selection form object
122 elseif($utils->decode_item_array($value, $hidden, $options) ) {
123 $this->add_element($key, $utils->decode_item_array($value, $hidden, $options));
124 } else {
125 $this->add_element($key, $value);
126 }
127 } else {
128 $this->add_element($key, $value);
129 }
130 }
131 }
132 }
133
134 function add_element($label, $value) {
135 $this->add_row(span_font10bold($label), $value);
136 }
137
138 function add_hidden_element($label, $value) {
139 $this->_hidden_elements[$label] = $value;
140 }
141
142 function get_form_container() {
143 $container = container();
144 // form open
145 $container->add(form_open("item_fv", $_SERVER['PHP_SELF'], 'POST'));
146 //hidden items
147 if(is_array($this->_hidden_elements)) {
148 foreach($this->_hidden_elements as $label => $value) {
149 $container->add(form_hidden($label, $value));
150 }
151 }
152 // submit button
153 $container->add(form_submit('ecdfe', "edit"));
154 // close form
155 $container->add(form_close());
156
157 // add container to InfoTable
158 $this->add_row(_HTML_SPACE, $container);
159 }
160
161
162 }
163
164
165 ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed