TrickHistory::getHistory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\History;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Gedmo\Loggable\Entity\LogEntry;
7
8
class TrickHistory
9
{
10
11
    /**
12
     * @var EntityManagerInterface
13
     */
14
    private $em;
15
16
    private $repo;
17
18
    public function __construct(EntityManagerInterface $em)
19
    {
20
        $this->em = $em;
21
        $this->repo = $this->em->getRepository('Gedmo\Loggable\Entity\LogEntry');
22
    }
23
24
    /**
25
     * @param $id
26
     * @return LogEntry[]
27
     * Get the modification history of a trick
28
     */
29
    public function getHistory($id)
30
    {
31
        $trick = $this->em->find('App\Entity\Trick', $id);
32
        $logs = $this->repo->getLogEntries($trick);
33
34
        return $logs;
35
    }
36
37
    /**
38
     * @param $id
39
     * @param $version
40
     * Revert a trick to a history checkpoint.
41
     */
42
    public function revertToHistory($id, $version){
43
        $trick = $this->em->find('App\Entity\Trick', $id);
44
        $this->repo->revert($trick, $version);
45
        $this->em->persist($trick);
46
        $this->em->flush();
47
    }
48
49
50
51
52
}