define_columns( [ 'timecreated', 'user', 'description', 'amount', 'status', 'providertransactionid', 'lasterror', ], ); $this->define_headers([ get_string('report:time', 'paygw_moneta'), get_string('report:user', 'paygw_moneta'), get_string('report:description', 'paygw_moneta'), get_string('report:amount', 'paygw_moneta'), get_string('report:status', 'paygw_moneta'), get_string('report:operation', 'paygw_moneta'), get_string('report:lasterror', 'paygw_moneta'), ]); $this->define_baseurl($baseUrl); $this->sortable(true, 'timecreated', SORT_DESC); $this->no_sorting('description'); $this->no_sorting('lasterror'); $this->collapsible(false); $this->pageable(true); $userFields = \core_user\fields::for_name()->get_sql('u')->selects; $this->set_sql( 't.*' . $userFields, '{' . TransactionRepository::TABLE . '} t JOIN {user} u ON u.id = t.userid', '1 = 1', ); } public function col_timecreated(stdClass $row): string { return userdate((int) $row->timecreated, get_string('strftimedatetimeshort', 'langconfig')); } public function col_user(stdClass $row): string { return html_writer::link(new moodle_url('/user/profile.php', ['id' => $row->userid]), fullname($row)); } public function col_description(stdClass $row): string { $snapshot = json_decode((string) $row->snapshot, true); return s((string) ($snapshot['description'] ?? '')); } public function col_amount(stdClass $row): string { return Money::fromFloat((float) $row->amount)->toDecimal() . ' ' . s(CurrencySymbol::of((string) $row->currency)); } public function col_status(stdClass $row): string { $status = TransactionStatus::tryFrom((string) $row->status); $label = $status === null ? s((string) $row->status) : get_string('status:' . $status->value, 'paygw_moneta'); $class = match ($status) { TransactionStatus::Paid => 'badge bg-success text-white', TransactionStatus::Failed => 'badge bg-danger text-white', TransactionStatus::Canceled => 'badge bg-secondary text-white', default => 'badge bg-info text-white', }; return html_writer::span($label, $class); } public function col_providertransactionid(stdClass $row): string { return s((string) ($row->providertransactionid ?? '')); } public function col_lasterror(stdClass $row): string { return s((string) ($row->lasterror ?? '')); } }