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