do not ask libravatar for anonymous commits
[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         //workaround for https://pear.php.net/bugs/bug.php?id=19384
24         require_once 'PEAR/Services/Libravatar.php';
25
26         $s = new \Services_Libravatar();
27         return $s->url(
28             $this->committerEmail,
29             array(
30                 'size'    => 32,
31                 'default' => Tools::fullUrl('/phorkie/anonymous.png')
32             )
33         );
34     }
35
36     /**
37      * @return array Array with 7 fields, each has either "r", "g" or "n"
38      *               ("red", "green" or "none")
39      */
40     public function getDots()
41     {
42         $r = $this->getDotNum($this->linesDeleted);
43         $g = $this->getDotNum($this->linesAdded);
44         $sum = $r + $g;
45         if ($sum > 7) {
46             $quot = ceil($sum / 7);
47             $r = int($r / $quot);
48             $g = int($g / $quot);
49         }
50         $string = str_repeat('g', $g) . str_repeat('r', $r) . str_repeat('n', 7 - $g - $r);
51
52         return str_split($string);
53     }
54
55     public function getDotNum($lines)
56     {
57         if ($lines == 0) {
58             return 0;
59         } else if ($lines == 1) {
60             return 1;
61         } else if ($lines == 2) {
62             return 2;
63         } else if ($lines == 3) {
64             return 3;
65         } else if ($lines == 4) {
66             return 4;
67         } else if ($lines < 10) {
68             return 5;
69         } else if ($lines < 50) {
70             return 6;
71         }
72         return 7;
73     }
74 }
75
76 ?>