/** * select a fixed number of records from database * @todo filter sql settings also includes note fields. note fields should not be known in this file. * @param $order_by_field string order records by this db_field_name * @param $page int the page number to select * @param $db_field_names array array containing db_field_names to select for each record * @return array array containing the records (each records is an array) */ function select($order_by_field, $page, $db_field_names = array()) { $this->_log->trace("selecting UserDatabaseTable (order_by_field=" . $order_by_field . ", page=" . $page . ", db_field_names=" . count($db_field_names) . ")"); # get lines per page from session $lines_per_page = $this->_user->get_lines_per_page(); # get list_state from session $this->_user->get_list_state($this->table_name); # get previous field order $prev_order_by_field = $this->_list_state->get_order_by_field(); if (strlen($order_by_field) == 0) { # no order_by_field had been given if (strlen($this->_list_state->get_order_by_field()) > 0) { # order by previously given field $order_by_field = $prev_order_by_field; } else { # no field to order by has been given previously # order by first field that has a non empty field_name of this UserDatabaseTable foreach ($this->db_field_names as $db_field_name) { if (strlen($this->fields[$db_field_name][0]) > 0 && $this->fields[$db_field_name][3] != COLUMN_NO_SHOW) { # set different db_field_names for automatic creator and modifier fields if ($this->fields[$db_field_name][1] == FIELD_TYPE_DEFINITION_AUTO_CREATED) { $order_by_field = DB_TS_CREATED_FIELD_NAME; } else { if ($this->fields[$db_field_name][1] == FIELD_TYPE_DEFINITION_AUTO_MODIFIED) { $order_by_field = DB_TS_MODIFIED_FIELD_NAME; } else { $order_by_field = $db_field_name; } } break; } } $this->_list_state->set_order_by_field($order_by_field); $this->_list_state->set_order_ascending(1); } } else { # order by field has been provided # set order by field attribute value and reverse order $this->_list_state->set_order_by_field($order_by_field); # only change sort order when user sorts by same field as previous time if ($order_by_field == $prev_order_by_field) { if ($this->_list_state->get_order_ascending()) { $this->_list_state->set_order_ascending(0); } else { $this->_list_state->set_order_ascending(1); } } else { $this->_list_state->set_order_ascending(1); } } $order_ascending = $this->_list_state->get_order_ascending(); $archived = $this->_list_state->get_archived(); $filter_str_sql = $this->_list_state->get_filter_str_sql(); if ($page == DATABASETABLE_UNKWOWN_PAGE) { $page = $this->_list_state->get_current_page(); } # call parent select() $rows = parent::select($order_by_field, $order_ascending, $archived, $filter_str_sql, $page, $lines_per_page, $db_field_names); # replace decimal marks $replaced_rows = array(); if (count($this->db_field_names_decimal_marks_to_replace) > 0) { foreach ($rows as $row) { array_push($replaced_rows, $this->_replace_decimal_marks($row, FALSE)); } $rows = $replaced_rows; } if ($page != DATABASETABLE_ALL_PAGES) { $this->_list_state->set_current_page($page); } if (count($rows) > 0) { $this->_list_state->set_total_records($rows[0][DB_TOTAL_RECORDS]); $this->_list_state->set_total_pages($rows[0][DB_TOTAL_PAGES]); $this->_list_state->set_current_page($rows[0][DB_CURRENT_PAGE]); } else { $this->_list_state->set_total_records(0); $this->_list_state->set_total_pages(0); $this->_list_state->set_current_page(0); } # store list_state to session $this->_user->set_list_state(); $this->_log->trace("selected UserDatabaseTable"); return $rows; }
/** * select all attachments for a specific field of a specific ListTable record * @param $record_id int unique identifier of a ListTable record * @return array array containing attachments (one ListTableAttachment is an array) */ function select($record_id) { $this->_log->trace("selecting ListTableAttachments (record_id={$record_id})"); # get lines per page from session # todo: remove this line because of DATABASETABLE_ALL_PAGES $lines_per_page = $this->_user->get_lines_per_page(); # set filter string SQL $filter_str_sql = LISTTABLEATTACHMENT_RECORD_ID_FIELD_NAME . "='" . $record_id . "'"; $records = parent::select("", 0, LISTSTATE_SELECT_BOTH_ARCHIVED, $filter_str_sql, DATABASETABLE_ALL_PAGES, $lines_per_page); if (count($records) == 0) { return array(); } $this->_log->trace("selected ListTableAttachments"); return $records; }