/** * select a fixed number of records from database * @param $order_by_field string order records by this db_field_name * @param $page int the page number to select * @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 ListTableDescription (order_by_field=" . $order_by_field . ", page=" . $page . ")"); # get list_state from session $this->_user->get_list_state($this->table_name); # set filter to select only listst for which current user has at least view permission $filter_str_sql = "(" . LISTTABLEDESCRIPTION_TITLE_FIELD_NAME . " IN (SELECT DISTINCT " . USERLISTTABLEPERMISSIONS_LISTTABLE_TITLE_FIELD_NAME; $filter_str_sql .= " FROM " . USERLISTTABLEPERMISSIONS_TABLE_NAME . " WHERE " . USERLISTTABLEPERMISSIONS_USER_NAME_FIELD_NAME; $filter_str_sql .= "='" . $this->_user->get_name() . "' AND " . USERLISTTABLEPERMISSIONS_CAN_VIEW_LIST_FIELD_NAME . "=1))"; # store list_state to session $this->_list_state->set_filter_str_sql($filter_str_sql); $this->_user->set_list_state(); $records = parent::select($order_by_field, $page, $db_field_names); if (count($records) == 0) { return array(); } $new_records = array(); foreach ($records as $record) { # convert value if (array_key_exists(LISTTABLEDESCRIPTION_DEFINITION_FIELD_NAME, $record) == TRUE) { $record[LISTTABLEDESCRIPTION_DEFINITION_FIELD_NAME] = (array) $this->_json->decode($record[LISTTABLEDESCRIPTION_DEFINITION_FIELD_NAME]); } array_push($new_records, $record); } $this->_log->trace("selected ListTableDescription"); return $new_records; }
/** * select a fixed number of records (a page) from database * @todo reset order_ascending when user orders on new field * @param $order_by_field string order records by this fieldname * @param $page int the page number to select * @return array array containing the records (each ListTableItem is an array) */ function select($order_by_field, $page) { $records_with_notes = array(); $this->_log->trace("selecting ListTable (order_by_field=" . $order_by_field . ", page=" . $page . ")"); # get list_state from session $this->_user->get_list_state($this->table_name); # get field names of note fields $note_fields_array = array(); foreach ($this->db_field_names as $db_field_name) { if ($this->fields[$db_field_name][1] == FIELD_TYPE_DEFINITION_NOTES_FIELD) { array_push($note_fields_array, $db_field_name); } } # set filter $filter_str = $this->_list_state->get_filter_str(); $filter_str_sql = $this->_list_state->get_filter_str_sql(); if (strlen($filter_str) > 0 && strlen($filter_str_sql) == 0) { $search_fields = array(); # select text fields foreach ($this->db_field_names as $db_field_name) { $field_type = $this->fields[$db_field_name][1]; if (stristr($field_type, "TEXT") || $field_type == FIELD_TYPE_DEFINITION_SELECTION) { array_push($search_fields, $db_field_name); } } # create value conditions if (count($search_fields) > 0) { $filter_str_sql = "("; $num_of_search_fields = count($search_fields); for ($counter = 0; $counter < $num_of_search_fields; $counter++) { $filter_str_sql .= $search_fields[$counter] . " LIKE '%" . $filter_str . "%'"; if ($counter < $num_of_search_fields - 1) { $filter_str_sql .= " OR "; } } $filter_str_sql .= ")"; } # create subquery for note fields if (count($note_fields_array) > 0) { $filter_str_sql = "(" . $filter_str_sql . " OR (" . DB_ID_FIELD_NAME . " IN (SELECT DISTINCT " . LISTTABLENOTE_RECORD_ID_FIELD_NAME; $filter_str_sql .= " FROM " . $this->_list_table_note->get_table_name() . " WHERE " . LISTTABLENOTE_NOTE_FIELD_NAME; $filter_str_sql .= " LIKE '%" . $filter_str . "%')))"; } # store list_state to session $this->_list_state->set_filter_str_sql($filter_str_sql); $this->_user->set_list_state(); } # call parent select() $records = parent::select($order_by_field, $page, $this->db_field_names); if (count($records) != 0) { # get notes foreach ($records as $record) { foreach ($note_fields_array as $note_field) { if ((int) $record[$note_field] > 0) { $result = $this->_list_table_note->select($record[DB_ID_FIELD_NAME], $note_field); if (count($result) == 0 || count($result) != $record[$note_field]) { $this->_log->warn("unexpected number of notes found (id=" . $record[DB_ID_FIELD_NAME] . ", expected=" . $record[$note_field] . ", found=" . count($result) . ")"); $record[$note_field] = $result; } else { $record[$note_field] = $result; } } else { if ($record[$note_field] != "") { $record[$note_field] = array(); } } } array_push($records_with_notes, $record); } } else { return $records; } $this->_log->trace("selected ListTable"); return $records_with_notes; }