Part of #35: show paste owner
[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         $hh = new HtmlHelper();
20         return $hh->getIconUrl($this->committerEmail);
21     }
22
23     /**
24      * @return array Array with 7 fields, each has either "r", "g" or "n"
25      *               ("red", "green" or "none")
26      */
27     public function getDots()
28     {
29         $r = $this->getDotNum($this->linesDeleted);
30         $g = $this->getDotNum($this->linesAdded);
31         $sum = $r + $g;
32         if ($sum > 7) {
33             $quot = ceil($sum / 7);
34             $r = intval($r / $quot);
35             $g = intval($g / $quot);
36         }
37         $string = str_repeat('g', $g)
38             . str_repeat('r', $r)
39             . str_repeat('n', 7 - $g - $r);
40
41         return str_split($string);
42     }
43
44     public function getDotNum($lines)
45     {
46         if ($lines == 0) {
47             return 0;
48         } else if ($lines == 1) {
49             return 1;
50         } else if ($lines == 2) {
51             return 2;
52         } else if ($lines == 3) {
53             return 3;
54         } else if ($lines == 4) {
55             return 4;
56         } else if ($lines < 10) {
57             return 5;
58         } else if ($lines < 50) {
59             return 6;
60         }
61         return 7;
62     }
63 }
64
65 ?>