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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Sat May 10 18:07:31 2003 UTC (21 years, 4 months ago) by jonen
Branch: MAIN
Changes since 1.4: +16 -22 lines
+ added values needed for 'create/add new' links
- purged depreciated code

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

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