From cd989f9c3aff968e19a3aeabc4eb9085787a6673 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:43:12 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- library/Director/Web/Table/BasketSnapshotTable.php | 125 +++++++++++++++++++++ 1 file changed, 125 insertions(+) create mode 100644 library/Director/Web/Table/BasketSnapshotTable.php (limited to 'library/Director/Web/Table/BasketSnapshotTable.php') diff --git a/library/Director/Web/Table/BasketSnapshotTable.php b/library/Director/Web/Table/BasketSnapshotTable.php new file mode 100644 index 0000000..08f808a --- /dev/null +++ b/library/Director/Web/Table/BasketSnapshotTable.php @@ -0,0 +1,125 @@ +basket = $basket; + $this->searchColumns = []; + + return $this; + } + + public function renderRow($row) + { + $this->splitByDay($row->ts_create_seconds); + $link = $this->linkToSnapshot($this->renderSummary($row->summary), $row); + + if ($this->basket === null) { + $columns = [ + [ + new Link( + Html::tag('strong', $row->basket_name), + 'director/basket', + ['name' => $row->basket_name] + ), + Html::tag('br'), + $link, + ], + DateFormatter::formatTime($row->ts_create / 1000), + ]; + } else { + $columns = [ + $link, + DateFormatter::formatTime($row->ts_create / 1000), + ]; + } + return $this::row($columns); + } + + protected function renderSummary($summary) + { + $summary = Json::decode($summary); + if ($summary === null) { + return '-'; + } + $result = []; + if (! is_object($summary) && ! is_array($summary)) { + throw new RuntimeException(sprintf( + 'Got invalid basket summary: %s ', + var_export($summary, 1) + )); + } + + foreach ($summary as $type => $count) { + $result[] = sprintf( + '%dx %s', + $count, + $type + ); + } + + if (empty($result)) { + return '-'; + } + + return implode(', ', $result); + } + + protected function linkToSnapshot($caption, $row) + { + return new Link($caption, 'director/basket/snapshot', [ + 'checksum' => bin2hex($this->wantBinaryValue($row->content_checksum)), + 'ts' => $row->ts_create, + 'name' => $row->basket_name, + ]); + } + + public function prepareQuery() + { + $query = $this->db()->select()->from([ + 'b' => 'director_basket' + ], [ + 'b.uuid', + 'b.basket_name', + 'bs.ts_create', + 'ts_create_seconds' => '(bs.ts_create / 1000)', + 'bs.content_checksum', + 'bc.summary', + ])->join( + ['bs' => 'director_basket_snapshot'], + 'bs.basket_uuid = b.uuid', + [] + )->join( + ['bc' => 'director_basket_content'], + 'bc.checksum = bs.content_checksum', + [] + )->order('bs.ts_create DESC'); + + if ($this->basket !== null) { + $query->where('b.uuid = ?', $this->quoteBinary($this->basket->get('uuid'))); + } + + return $query; + } +} -- cgit v1.2.3