Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
ManagementFeedbackDetailLogic
0.00% covered (danger)
0.00%
0 / 31
0.00% covered (danger)
0.00%
0 / 3
72
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 validateImpl
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 1
12
 executeImpl
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3declare(strict_types=1);
4
5namespace PeServer\App\Models\Domain\Page\Management;
6
7use Exception;
8use PeServer\App\Models\AppDatabaseCache;
9use PeServer\App\Models\Dao\Domain\FeedbackDomainDao;
10use PeServer\App\Models\Dao\Entities\FeedbackCommentsEntityDao;
11use PeServer\App\Models\Dao\Entities\FeedbacksEntityDao;
12use PeServer\App\Models\Domain\AppArchiver;
13use PeServer\App\Models\Domain\Page\PageLogicBase;
14use PeServer\Core\Database\IDatabaseContext;
15use PeServer\Core\Http\HttpStatus;
16use PeServer\Core\Mvc\LogicCallMode;
17use PeServer\Core\Mvc\LogicParameter;
18use PeServer\Core\Throws\HttpStatusException;
19use PeServer\Core\Stopwatch;
20
21class ManagementFeedbackDetailLogic extends PageLogicBase
22{
23    public function __construct(LogicParameter $parameter)
24    {
25        parent::__construct($parameter);
26    }
27
28    protected function validateImpl(LogicCallMode $callMode): void
29    {
30        $this->validation('sequence', function ($key, $value) {
31            $hasSequence = $this->validator->isNotEmpty($key, $value);
32
33            if ($hasSequence) {
34                $database = $this->openDatabase();
35                $feedbacksEntityDao = new FeedbacksEntityDao($database);
36
37                $seq = (int)$value;
38                $exists = $feedbacksEntityDao->selectExistsFeedbacksBySequence($seq);
39                if (!$exists) {
40                    //TODO: HttpStatusException
41                    throw new Exception('404');
42                }
43            } else {
44                throw new HttpStatusException(HttpStatus::BadRequest);
45            }
46        });
47    }
48
49    protected function executeImpl(LogicCallMode $callMode): void
50    {
51        $sequence = (int)$this->getRequest('sequence');
52        $this->result['sequence'] = $sequence;
53
54        $database = $this->openDatabase();
55        $feedbackDomainDao = new FeedbackDomainDao($database);
56
57        $detail = $feedbackDomainDao->selectFeedbackDetailBySequence($sequence);
58
59        $this->setValue('detail', $detail);
60
61        if ($callMode === LogicCallMode::Initialize) {
62            $this->setValue('developer-comment', $detail->developerComment);
63            return;
64        }
65
66        $developerComment = (string)$this->getRequest('developer-comment');
67
68        $result = $database->transaction(function (IDatabaseContext $context) use ($sequence, $developerComment) {
69            $feedbackCommentsEntityDao = new FeedbackCommentsEntityDao($context);
70
71            if ($feedbackCommentsEntityDao->selectExistsFeedbackCommentsBySequence($sequence)) {
72                $feedbackCommentsEntityDao->updateFeedbackComments($sequence, $developerComment);
73            } else {
74                $feedbackCommentsEntityDao->insertFeedbackComments($sequence, $developerComment);
75            }
76
77            return true;
78        });
79        if (!$result) {
80            throw new HttpStatusException(HttpStatus::InternalServerError);
81        }
82    }
83}