public function append_column_headings_to_shtr(Database_SortableHeadingTR $shtr) { $dn = $this->get_display_node(); $cses = $dn->getElementsByTagName('columns'); if ($cses->length == 1) { $cse = $cses->item(0); $ces = $cse->getElementsByTagName('column'); for ($i = 0; $i < $ces->length; $i++) { $ce = $ces->item($i); $sortable = TRUE; if ($ce->hasAttribute('sortable')) { if ($ce->getAttribute('sortable') == 'no') { $sortable = FALSE; } } if ($sortable) { $shtr->append_sortable_field_name($ce->getAttribute('name')); } else { $shtr->append_nonsortable_field_name($ce->getAttribute('name')); } } return $shtr; } throw new Exception('Unable to append columns to sortable heading TR!'); }
/** * Renders the HTML table that contains the data and the * links to other pages to do stuff to individual items. */ protected function render_data_table() { /* * The table. */ $rows_html_table = new HTMLTags_Table(); $rows_html_table->set_attribute_str('class', 'table_pages'); /* * ---------------------------------------- * The caption for the HTML table displaying the products. * ---------------------------------------- */ $caption_str = $this->get_data_table_caption_content(); $rows_html_table->append_tag_to_content(new HTMLTags_Caption($caption_str)); /* * ---------------------------------------- * The heading row of the HTML table that displays the products. * ---------------------------------------- */ $thead = new HTMLTags_THead(); $sort_href = $this->get_current_base_url(); $sort_href->set_get_variable('limit', $this->get_current_limit()); $sort_href->set_get_variable('offset', $this->get_current_offset()); $heading_row = new Database_SortableHeadingTR($sort_href, $this->get_current_direction()); $fields = $this->get_data_table_fields(); #print_r($fields); foreach ($fields as $field) { if (isset($field['sortable']) && strtolower($field['sortable']) == 'no') { $heading_row->append_nonsortable_field_name($field['col_name'], isset($field['title']) ? $field['title'] : NULL); } else { $heading_row->append_sortable_field_name($field['col_name'], isset($field['title']) ? $field['title'] : NULL); } } foreach ($this->get_data_table_action_ths() as $action_th) { $heading_row->append_tag_to_content($action_th); } $thead->append_tag_to_content($heading_row); $rows_html_table->append_tag_to_content($thead); /* * ---------------------------------------- * Fetch the rows from the database table. * ---------------------------------------- */ $tbody = new HTMLTags_TBody(); $rows = $this->get_matching_rows(); /* * Display some of the contents of the table. */ foreach ($rows as $row) { $data_tr = $this->get_data_html_table_tr($row); $tbody->append_tag_to_content($data_tr); } $rows_html_table->append_tag_to_content($tbody); echo $rows_html_table->get_as_string(); }
public function __construct(HTMLTags_URL $url, Database_Table $table, $order_by, $direction, $offset, $limit, $limit_str, $rows_html_table_caption, $lpnd_class, $data_table_class, $fields, $actions) { parent::__construct(); $table_renderer = $table->get_renderer(); /* * ---------------------------------------- * Check the inputs. * ---------------------------------------- */ /* * ---------------------------------------- * Create the content. * ---------------------------------------- */ $limit_previous_next_div = new HTMLTags_Div(); $limit_previous_next_div->set_attribute_str('class', $lpnd_class); /* * To allow the user to set the number of extras to show at a time. */ $limit_action = clone $url; $limit_action->delete_all_get_variables(); $limit_form = new Database_LimitForm($limit_action, $limit, $limit_str); $get_vars = $url->get_get_variables(); foreach (array_keys($get_vars) as $key) { $limit_form->add_hidden_input($key, $get_vars[$key]); } $limit_form->add_hidden_input('order_by', $order_by); $limit_form->add_hidden_input('direction', $direction); $limit_form->add_hidden_input('offset', $offset); $limit_previous_next_div->append_tag_to_content($limit_form); $previous_next_url = clone $url; $previous_next_url->set_get_variable('order_by', $order_by); $previous_next_url->set_get_variable('direction', $direction); $row_count = $table->count_all_rows(); $previous_next_ul = new Database_PreviousNextUL($previous_next_url, $offset, $limit, $row_count); $limit_previous_next_div->append_tag_to_content($previous_next_ul); $this->append_tag_to_content($limit_previous_next_div); # ------------------------------------------------------------------ /* * The table. */ $rows_html_table = new HTMLTags_Table(); $rows_html_table->set_attribute_str('class', $data_table_class); /* * The caption. */ $caption = new HTMLTags_Caption($rows_html_table_caption); $rows_html_table->append_tag_to_content($caption); /* * The Heading Row. */ $sort_href = clone $url; $sort_href->set_get_variable('limit', $limit); $heading_row = new Database_SortableHeadingTR($sort_href, $direction); //if (isset($fields_str)) { // $fields = array(); // // foreach (explode(' ', $fields_str) as $field_name) { // $fields[] = $table->get_field($field_name); // } //} else { // $fields = $table->get_fields(); //} foreach ($fields as $field) { if ($field['sortable']) { $heading_row->append_sortable_field_name($field['name']); } else { $heading_row->append_nonsortable_field_name($field['name']); } } foreach ($actions as $action) { $heading_row->append_tag_to_content($action['th']); } $rows_html_table->append_tag_to_content($heading_row); # ------------------------------------------------------------------ /* * Display the contents of the table. */ $rows = $table->get_all_rows($order_by, $direction, $offset, $limit); foreach ($rows as $row) { $row_renderer = $row->get_renderer(); $data_tr = new HTMLTags_TR(); foreach ($fields as $field) { $field_td = self::get_html_table_cell_for_field($field, $row_renderer); $data_tr->append_tag_to_content($field_td); } //foreach ( // $row_renderer->get_action_tds( // $actions_str, // $url // ) // as // $action_td //) { // $data_tr->append_tag_to_content($action_td); //} foreach ($actions as $action) { $action_td = self::get_html_table_cell_for_field($action, $row_renderer); $data_tr->append_tag_to_content($action_td); } $rows_html_table->append_tag_to_content($data_tr); } # ------------------------------------------------------------------ $this->append_tag_to_content($rows_html_table); $this->append_tag_to_content($limit_previous_next_div); }