1ac8cc5cce40788a526446f40578ecf9b51112cd
[phorkie.git] / src / phorkie / Repository / Commit.php
1 <?php
2 namespace phorkie;
3
4
5 class Repository_Commit
6 {
7     public $hash;
8     public $committerName;
9     public $committerEmail;
10     public $committerTime;
11
12     public $linesAdded;
13     public $linesDeleted;
14     public $filesChanged;
15
16
17     public function getIconUrl()
18     {
19         if ($this->committerEmail == 'anonymous@phorkie') {
20             return '/phorkie/anonymous.png';
21         }
22
23         $s = new \Services_Libravatar();
24         return $s->url(
25             $this->committerEmail,
26             array(
27                 'size'    => 32,
28                 'default' => Tools::fullUrl('/phorkie/anonymous.png')
29             )
30         );
31     }
32
33     /**
34      * @return array Array with 7 fields, each has either "r", "g" or "n"
35      *               ("red", "green" or "none")
36      */
37     public function getDots()
38     {
39         $r = $this->getDotNum($this->linesDeleted);
40         $g = $this->getDotNum($this->linesAdded);
41         $sum = $r + $g;
42         if ($sum > 7) {
43             $quot = ceil($sum / 7);
44             $r = intval($r / $quot);
45             $g = intval($g / $quot);
46         }
47         $string = str_repeat('g', $g)
48             . str_repeat('r', $r)
49             . str_repeat('n', 7 - $g - $r);
50
51         return str_split($string);
52     }
53
54     public function getDotNum($lines)
55     {
56         if ($lines == 0) {
57             return 0;
58         } else if ($lines == 1) {
59             return 1;
60         } else if ($lines == 2) {
61             return 2;
62         } else if ($lines == 3) {
63             return 3;
64         } else if ($lines == 4) {
65             return 4;
66         } else if ($lines < 10) {
67             return 5;
68         } else if ($lines < 50) {
69             return 6;
70         }
71         return 7;
72     }
73 }
74
75 ?>