Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
TagConnectionsEdit
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
3 / 3
4
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 populateTags
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 renderJs
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3class TagConnectionsEdit
4{
5    public $tsumegoID;
6    public $tags = [];
7    public $problemSolved;
8    public $isTimeMode;
9
10    public function __construct($tsumegoID, $problemSolved)
11    {
12        $this->tsumegoID = $tsumegoID;
13        $this->problemSolved = $problemSolved;
14        $this->isTimeMode = Auth::isInTimeMode();
15        $this->populateTags();
16    }
17
18    private function populateTags()
19    {
20        $this->tags = Util::query("
21SELECT
22    tag.name AS name,
23    tag.popular AS isPopular,
24    tag.id AS id,
25    tag_connection.id IS NOT NULL AS isAdded,
26    COALESCE(tag_connection.approved, 0) AS isApproved,
27    COALESCE(tag_connection.user_id = ?, 0) AS isMine,
28    tag.hint AS isHint
29FROM tag
30LEFT JOIN tag_connection ON tag_connection.tag_id = tag.id AND tag_connection.tsumego_id = ?
31ORDER BY name", [Auth::getUserID(), $this->tsumegoID]);
32    }
33
34    public function renderJs()
35    {
36        $constructorParams = [];
37        $constructorParams[] = 'tsumegoID:' . $this->tsumegoID;
38        $constructorParams[] = 'isAdmin:' . Util::boolString(Auth::isAdmin());
39        $constructorParams[] = 'problemSolved:' . Util::boolString($this->problemSolved);
40        $constructorParams[] = 'isTimeMode:' . Util::boolString($this->isTimeMode);
41
42        $tags = [];
43        foreach ($this->tags as $tag)
44            $tags [] = '{' . implode(', ', array_map(fn($k, $v) => $k . ': ' . var_export($v, true), array_keys($tag), $tag)) . '}' . PHP_EOL;
45        $constructorParams[] = 'tags: [' . implode(", ", $tags) . ']';
46
47        echo "var tagConnectionsEdit = new TagConnectionsEdit({" . implode(", ", $constructorParams) . "});" . PHP_EOL;
48    }
49}