Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
91.89% |
34 / 37 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| AdminActivity | |
91.89% |
34 / 37 |
|
0.00% |
0 / 1 |
13.09 | |
0.00% |
0 / 1 |
| renderChange | |
91.89% |
34 / 37 |
|
0.00% |
0 / 1 |
13.09 | |||
| 1 | <?php |
| 2 | |
| 3 | class AdminActivity extends AppModel |
| 4 | { |
| 5 | public $useTable = 'admin_activity'; |
| 6 | public $actsAs = ['Containable']; |
| 7 | |
| 8 | public $belongsTo = [ |
| 9 | 'AdminActivityType' => [ |
| 10 | 'className' => 'AdminActivityType', |
| 11 | 'foreignKey' => 'type', |
| 12 | 'fields' => ['name'] |
| 13 | ] |
| 14 | ]; |
| 15 | |
| 16 | public static function renderChange($adminActivity) |
| 17 | { |
| 18 | switch ($adminActivity['type']) |
| 19 | { |
| 20 | case AdminActivityType::ACCEPT_TAG: return 'Accepted tag ' . $adminActivity['new_value']; |
| 21 | case AdminActivityType::REJECT_TAG: return 'Rejected tag ' . $adminActivity['old_value']; |
| 22 | case AdminActivityType::TSUMEGO_MERGE: |
| 23 | { |
| 24 | $decoded = json_decode($adminActivity['old_value'], true); |
| 25 | if (json_last_error() !== JSON_ERROR_NONE |
| 26 | || !is_array($decoded) |
| 27 | || !isset($decoded['master_sgf'])) |
| 28 | return 'Merged tsumego ' . $adminActivity['old_value']; |
| 29 | |
| 30 | $masterCorrectMoves = SgfBoard::decodePositionString($decoded['master_correct_moves']); |
| 31 | $masterSgf = SgfParser::process($decoded['master_sgf'], $masterCorrectMoves); |
| 32 | $slaveCorrectMoves = SgfBoard::decodePositionString($decoded['slave_correct_moves']); |
| 33 | $slaveSgf = SgfParser::process($decoded['slave_sgf'], $slaveCorrectMoves); |
| 34 | $comparisonResult = BoardComparator::compare( |
| 35 | $masterSgf->stones, |
| 36 | $decoded['master_first_move_color'], |
| 37 | $masterCorrectMoves, |
| 38 | $slaveSgf->stones, |
| 39 | $decoded['slave_first_move_color'], |
| 40 | $slaveCorrectMoves); |
| 41 | |
| 42 | $onMouseOver = 'if (this.querySelector(\'svg\')) return;'; |
| 43 | $onMouseOver .= TsumegoButton::createBoardFromSgf($decoded['master_sgf'], 'this', 'createPreviewBoard'); |
| 44 | $onMouseOver .= TsumegoButton::createBoardFromSgf($decoded['slave_sgf'], 'this', 'createPreviewBoard', $comparisonResult->diff); |
| 45 | $result = 'Merged '; |
| 46 | $result .= '<a style="position: relative;" onmouseover="' . $onMouseOver . '">tsumego<span class="tooltip-box"></span></a>'; |
| 47 | return $result; |
| 48 | } |
| 49 | default: |
| 50 | if (!empty($adminActivity['old_value']) && !empty($adminActivity['new_value'])) |
| 51 | return $adminActivity['readable_type'] . ': ' . h($adminActivity['old_value']) . ' → ' . h($adminActivity['new_value']); |
| 52 | if (!empty($adminActivity['new_value'])) |
| 53 | { |
| 54 | if ($adminActivity['new_value'] === '1') |
| 55 | return $adminActivity['readable_type'] . ' → enabled'; |
| 56 | /** @phpstan-ignore-next-line */ |
| 57 | if ($adminActivity['new_value'] === '0') |
| 58 | return $adminActivity['readable_type'] . ' → disabled'; |
| 59 | return $adminActivity['readable_type'] . ': [Empty] → ' . $adminActivity['new_value']; |
| 60 | } |
| 61 | return $adminActivity['readable_type']; |
| 62 | } |
| 63 | } |
| 64 | } |