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