05c988b5be0210570a56e99b96acf5f4631a9507
[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) . str_repeat('r', $r) . str_repeat('n', 7 - $g - $r);
48
49         return str_split($string);
50     }
51
52     public function getDotNum($lines)
53     {
54         if ($lines == 0) {
55             return 0;
56         } else if ($lines == 1) {
57             return 1;
58         } else if ($lines == 2) {
59             return 2;
60         } else if ($lines == 3) {
61             return 3;
62         } else if ($lines == 4) {
63             return 4;
64         } else if ($lines < 10) {
65             return 5;
66         } else if ($lines < 50) {
67             return 6;
68         }
69         return 7;
70     }
71 }
72
73 ?>