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