Update phing build script to use composer installation only
[bdrem.git] / src / bdrem / Renderer.php
1 <?php
2 /**
3  * Part of bdrem
4  *
5  * PHP version 5
6  *
7  * @category  Tools
8  * @package   Bdrem
9  * @author    Christian Weiske <cweiske@cweiske.de>
10  * @copyright 2014 Christian Weiske
11  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
12  * @link      http://cweiske.de/bdrem.htm
13  */
14 namespace bdrem;
15
16 /**
17  * Base event renderer
18  *
19  * @category  Tools
20  * @package   Bdrem
21  * @author    Christian Weiske <cweiske@cweiske.de>
22  * @copyright 2014 Christian Weiske
23  * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
24  * @version   Release: @package_version@
25  * @link      http://cweiske.de/bdrem.htm
26  */
27 abstract class Renderer
28 {
29     /**
30      * HTTP content type of output
31      * @var string
32      */
33     protected $httpContentType = null;
34
35     /**
36      * Call the renderer and output the rendering result to shell or browser
37      *
38      * @param array $arEvents Event objects to render
39      *
40      * @return void
41      */
42     public function renderAndOutput($arEvents)
43     {
44         if (PHP_SAPI != 'cli' && $this->httpContentType !== null) {
45             header('Content-type: ' . $this->httpContentType);
46         }
47         echo $this->render($arEvents);
48     }
49
50     /**
51      * Do something when there are no events to render
52      *
53      * @return void
54      */
55     public function handleStopOnEmpty()
56     {
57     }
58
59     /**
60      * Display the events in some way
61      *
62      * @param array $arEvents Events to display
63      *
64      * @return string Event representation
65      */
66     abstract public function render($arEvents);
67
68     /**
69      * Converts the given date string according to the user's locale setting.
70      *
71      * @param string $dateStr Date in format YYYY-MM-DD
72      *
73      * @return string Formatted date
74      */
75     protected function getLocalDate($dateStr)
76     {
77         if ($dateStr[0] != '?') {
78             return strftime('%x', strtotime($dateStr));
79         }
80
81         $dateStr = str_replace('????', '1899', $dateStr);
82         return str_replace(
83             array('1899', '99'),
84             array('????', '??'),
85             strftime('%x', strtotime($dateStr))
86         );
87     }
88 }
89 ?>