| 1 |
jonen |
1.1 |
<? |
| 2 |
|
|
/* |
| 3 |
|
|
## ----------------------------------------------------------------------------- |
| 4 |
udo |
1.7 |
## $Id: DataItem.php,v 1.6 2003/05/13 16:24:30 joko Exp $ |
| 5 |
jonen |
1.1 |
## ----------------------------------------------------------------------------- |
| 6 |
jonen |
1.2 |
## $Log: DataItem.php,v $ |
| 7 |
udo |
1.7 |
## Revision 1.6 2003/05/13 16:24:30 joko |
| 8 |
|
|
## title addendum |
| 9 |
|
|
## MetaBox - header style |
| 10 |
|
|
## |
| 11 |
joko |
1.6 |
## Revision 1.5 2003/05/10 18:07:31 jonen |
| 12 |
|
|
## + added values needed for 'create/add new' links |
| 13 |
|
|
## - purged depreciated code |
| 14 |
|
|
## |
| 15 |
jonen |
1.5 |
## Revision 1.4 2003/04/09 09:53:13 joko |
| 16 |
|
|
## fixes regarding modification of decode-function-behavior |
| 17 |
|
|
## |
| 18 |
joko |
1.4 |
## Revision 1.3 2003/04/06 01:40:35 jonen |
| 19 |
|
|
## + removed duplicated decode functions |
| 20 |
|
|
## |
| 21 |
jonen |
1.3 |
## Revision 1.2 2003/04/04 23:58:33 jonen |
| 22 |
|
|
## + minor changes |
| 23 |
|
|
## |
| 24 |
jonen |
1.2 |
## Revision 1.1 2003/04/04 00:32:57 jonen |
| 25 |
|
|
## + initial commit |
| 26 |
|
|
## |
| 27 |
jonen |
1.1 |
## |
| 28 |
|
|
## |
| 29 |
|
|
## ----------------------------------------------------------------------------- |
| 30 |
|
|
*/ |
| 31 |
|
|
|
| 32 |
|
|
class DataItem extends InfoTable { |
| 33 |
|
|
|
| 34 |
|
|
/** |
| 35 |
|
|
* holds reference to source object. |
| 36 |
|
|
*/ |
| 37 |
|
|
var $_datasource = NULL; |
| 38 |
|
|
|
| 39 |
|
|
/** |
| 40 |
|
|
* container for arguments needed for e.g. setting the source object. |
| 41 |
|
|
*/ |
| 42 |
|
|
var $_options = array(); |
| 43 |
|
|
|
| 44 |
|
|
/** |
| 45 |
|
|
* container for hidden elements. |
| 46 |
|
|
*/ |
| 47 |
|
|
var $_hidden_elements = array(); |
| 48 |
|
|
|
| 49 |
|
|
function DataItem($title, $options = array()) { |
| 50 |
|
|
$this->_options = $options; |
| 51 |
|
|
|
| 52 |
joko |
1.6 |
//print "title: $title<br/>"; |
| 53 |
udo |
1.7 |
//print "options:" . Dumper($options) . "<br>"; |
| 54 |
joko |
1.6 |
|
| 55 |
|
|
$title .= $this->get_title_addendum(); |
| 56 |
|
|
|
| 57 |
udo |
1.7 |
$parent = get_parent_class($this); |
| 58 |
|
|
// debug (WARNNING!!! Sometime an recursive loop happens here |
| 59 |
|
|
// if class $parent is eq current class!!) |
| 60 |
|
|
//print "parent: " . Dumper($parent) . "<br>"; |
| 61 |
|
|
|
| 62 |
jonen |
1.1 |
$this->$parent($title, $width="100%", "center"); |
| 63 |
|
|
|
| 64 |
|
|
// fetch data |
| 65 |
|
|
$this->data_prefetch(); |
| 66 |
|
|
} |
| 67 |
|
|
|
| 68 |
|
|
function render($indent_level=1, $output_debug=0) { |
| 69 |
|
|
// init data record entries |
| 70 |
|
|
$this->init_elements(); |
| 71 |
|
|
// add form container |
| 72 |
|
|
$this->get_form_container(); |
| 73 |
|
|
|
| 74 |
|
|
$table = html_table( $this->get_width(), 0, |
| 75 |
|
|
$this->get_cellspacing(), |
| 76 |
|
|
$this->get_cellpadding(), |
| 77 |
|
|
$this->get_align()); |
| 78 |
|
|
$table->set_class( "infotable" ); |
| 79 |
|
|
$table->add( $this->_build_title() ); |
| 80 |
|
|
|
| 81 |
|
|
$row = $this->_build_header(); |
| 82 |
|
|
if ($row != NULL) { |
| 83 |
|
|
$table->add_row( $row ); |
| 84 |
|
|
} |
| 85 |
|
|
|
| 86 |
|
|
//now go thru the rows of data |
| 87 |
|
|
//and add them |
| 88 |
|
|
foreach( $this->data as $row ) { |
| 89 |
|
|
if ((count($row) == 1) && is_object($row[0]) && (is_a($row[0], "TRtag") || |
| 90 |
|
|
is_a($row[0], "TDtag"))) { |
| 91 |
|
|
$table->add_row( $row[0] ); |
| 92 |
|
|
} else { |
| 93 |
|
|
$tr = new TRtag; |
| 94 |
|
|
$cnt = count( $row ); |
| 95 |
|
|
foreach( $row as $index => $data ) { |
| 96 |
|
|
$td = $this->_build_td("", "", $index+1, $cnt ); |
| 97 |
|
|
$td->add( $data ); |
| 98 |
|
|
$tr->add( $td ); |
| 99 |
|
|
} |
| 100 |
|
|
$table->add_row( $tr ); |
| 101 |
|
|
} |
| 102 |
|
|
} |
| 103 |
|
|
return $table->render($indent_level, $output_debug); |
| 104 |
|
|
} |
| 105 |
|
|
|
| 106 |
|
|
function set_data_source(&$source) { |
| 107 |
|
|
$this->_datasource = &$source; |
| 108 |
|
|
} |
| 109 |
|
|
|
| 110 |
|
|
function get_data_source() { |
| 111 |
udo |
1.7 |
|
| 112 |
jonen |
1.1 |
$initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) ); |
| 113 |
|
|
$proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']); |
| 114 |
|
|
$source = $proxy->get_adapter(); |
| 115 |
|
|
$this->set_data_source( &$source ); |
| 116 |
|
|
} |
| 117 |
|
|
|
| 118 |
|
|
function _check_datasource($function_name) { |
| 119 |
|
|
if ( !is_object($this->_datasource) ) { |
| 120 |
|
|
user_error("DataList::".$function_name."() - DataListSource object is not set"); |
| 121 |
|
|
exit; |
| 122 |
|
|
} |
| 123 |
|
|
} |
| 124 |
|
|
|
| 125 |
|
|
function data_prefetch() { |
| 126 |
|
|
$this->get_data_source(); |
| 127 |
|
|
$this->_check_datasource("data_prefetch"); |
| 128 |
|
|
|
| 129 |
|
|
$this->_datasource->do_query(); |
| 130 |
|
|
} |
| 131 |
|
|
|
| 132 |
|
|
function init_elements() { |
| 133 |
|
|
$result = $this->_datasource->_result; |
| 134 |
|
|
if (is_array($result)) { |
| 135 |
|
|
foreach($result as $key => $value) { |
| 136 |
jonen |
1.5 |
// set empty values to 'html spacer' for render |
| 137 |
|
|
// TODO: integer value '0' is interpretted as non-existing value! Hack this!! |
| 138 |
|
|
if(!$value && !is_array($value)) { $value = _HTML_SPACE; } |
| 139 |
|
|
// if decode options are true, trie to decode values(e.g. for inhiterance) |
| 140 |
jonen |
1.1 |
if($this->_options['decode']) { |
| 141 |
jonen |
1.5 |
$utils = php::mkComponent('WebExplorer::utils'); |
| 142 |
|
|
$hidden = $this->_hidden_elements; |
| 143 |
udo |
1.7 |
$options = $this->_options['decode_args']; |
| 144 |
jonen |
1.5 |
$options[label] = $key; |
| 145 |
|
|
$options[parent_guid] = $this->_options['parent']['guid']; |
| 146 |
|
|
$options[parent_class] = $this->_options['parent']['class']; |
| 147 |
|
|
// if item is matched by a special expression we will replace it with an html-link object |
| 148 |
joko |
1.4 |
$utils->decode_item_expr($value, $hidden, $options); |
| 149 |
jonen |
1.5 |
// if item is an Array we will replace it with an html-link object |
| 150 |
joko |
1.4 |
$utils->decode_item_array($value, $hidden, $options); |
| 151 |
udo |
1.7 |
|
| 152 |
joko |
1.4 |
$this->add_element($key, $value); |
| 153 |
jonen |
1.1 |
} else { |
| 154 |
|
|
$this->add_element($key, $value); |
| 155 |
|
|
} |
| 156 |
|
|
} |
| 157 |
|
|
} |
| 158 |
|
|
} |
| 159 |
|
|
|
| 160 |
|
|
function add_element($label, $value) { |
| 161 |
|
|
$this->add_row(span_font10bold($label), $value); |
| 162 |
|
|
} |
| 163 |
|
|
|
| 164 |
|
|
function add_hidden_element($label, $value) { |
| 165 |
|
|
$this->_hidden_elements[$label] = $value; |
| 166 |
|
|
} |
| 167 |
|
|
|
| 168 |
|
|
function get_form_container() { |
| 169 |
|
|
$container = container(); |
| 170 |
|
|
// form open |
| 171 |
|
|
$container->add(form_open("item_fv", $_SERVER['PHP_SELF'], 'POST')); |
| 172 |
|
|
//hidden items |
| 173 |
|
|
if(is_array($this->_hidden_elements)) { |
| 174 |
|
|
foreach($this->_hidden_elements as $label => $value) { |
| 175 |
|
|
$container->add(form_hidden($label, $value)); |
| 176 |
|
|
} |
| 177 |
|
|
} |
| 178 |
|
|
// submit button |
| 179 |
jonen |
1.2 |
$container->add(form_submit('ecdfe', "edit")); |
| 180 |
jonen |
1.1 |
// close form |
| 181 |
|
|
$container->add(form_close()); |
| 182 |
|
|
|
| 183 |
|
|
// add container to InfoTable |
| 184 |
jonen |
1.2 |
$this->add_row(_HTML_SPACE, $container); |
| 185 |
jonen |
1.1 |
} |
| 186 |
|
|
|
| 187 |
joko |
1.6 |
|
| 188 |
|
|
// Please visit WebExplorer::Module::DataItem - there is a similar chooser at the top!!! |
| 189 |
|
|
// TODO: abstract this out into some reusable, generic component sometimes (SimpleChooser?) |
| 190 |
|
|
// (also take a look at WebExplorer::Module::DataTree) |
| 191 |
|
|
function get_title_addendum() { |
| 192 |
|
|
|
| 193 |
|
|
// MetaBox / Chooser - resolve / display some links which probably have been declared in some other layer |
| 194 |
|
|
//$this->header = html_span(); |
| 195 |
|
|
|
| 196 |
|
|
// Build a header-style MetaBox. |
| 197 |
|
|
// This will get injected into the header of the DataItem. |
| 198 |
|
|
$this->header_box = php::mkComponent('MetaBox', array( |
| 199 |
|
|
box_mode => 'header', |
| 200 |
|
|
caption => $this->_options['caption'], |
| 201 |
|
|
payload => $this->_options['links'], |
| 202 |
|
|
) ); |
| 203 |
|
|
|
| 204 |
|
|
return $this->header_box->render(); |
| 205 |
|
|
|
| 206 |
|
|
} |
| 207 |
jonen |
1.1 |
|
| 208 |
|
|
} |
| 209 |
|
|
|
| 210 |
|
|
|
| 211 |
|
|
?> |