add docblocks to all files, classes, methods and variables
[bdrem.git] / src / bdrem / Renderer / Console.php
index 195f53d00f6f81a036db839b739172cdc802c96b..61fb67e527f3254dd4bcd6b7b3896efca896d9ad 100644 (file)
@@ -1,29 +1,66 @@
 <?php
+/**
+ * Part of bdrem
+ *
+ * PHP version 5
+ *
+ * @category  Tools
+ * @package   Bdrem
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @link      http://cweiske.de/bdrem.htm
+ */
 namespace bdrem;
 
-class Renderer_Console
+/**
+ * Render events on the terminal as ASCII table
+ *
+ * @category  Tools
+ * @package   Bdrem
+ * @author    Christian Weiske <cweiske@cweiske.de>
+ * @copyright 2014 Christian Weiske
+ * @license   http://www.gnu.org/licenses/agpl.html GNU AGPL v3
+ * @version   Release: @package_version@
+ * @link      http://cweiske.de/bdrem.htm
+ */
+class Renderer_Console extends Renderer
 {
+    /**
+     * HTTP content type
+     * @var string
+     */
+    protected $httpContentType = 'text/plain; charset=utf-8';
+
     /**
      * Use ANSI color codes for output coloring
      *
      * @var boolean
      */
-    public $ansi = true;
+    public $ansi = false;
 
     /**
      * @var \Console_Color2
      */
     protected $cc;
 
+    /**
+     * Render events as console table
+     *
+     * @param array $arEvents Array of events to render
+     *
+     * @return string ASCII table
+     */
     public function render($arEvents)
     {
+        $this->loadConfig();
         if ($this->ansi) {
             $this->cc = new \Console_Color2();
         }
 
         $tbl = new \Console_Table(
             CONSOLE_TABLE_ALIGN_LEFT,
-            array('sect' => '', 'rule' => '-', 'vert' => ''),
+            array('intersection' => '', 'horizontal' => '-', 'vertical' => ''),
             1, null, $this->ansi
         );
         $tbl->setAlign(0, CONSOLE_TABLE_ALIGN_RIGHT);
@@ -57,7 +94,7 @@ class Renderer_Console
                         $event->age,
                         wordwrap($event->title, 30, "\n", true),
                         wordwrap($event->type, 20, "\n", true),
-                        $event->date,
+                        $this->getLocalDate($event->date),
                         strftime('%a', strtotime($event->localDate))
                     ),
                     $colorCode
@@ -67,6 +104,14 @@ class Renderer_Console
         return $tbl->getTable();
     }
 
+    /**
+     * Wrap each string in an array in an ANSI color code
+     *
+     * @param array  $data      Array of strings
+     * @param string $colorCode ANSI color code or name
+     *
+     * @return array Wrapped data
+     */
     protected function ansiWrap($data, $colorCode = null)
     {
         if (!$this->ansi || $colorCode === null) {
@@ -80,5 +125,17 @@ class Renderer_Console
         }
         return $data;
     }
+
+    /**
+     * Load configuration values into the class
+     *
+     * @return void
+     */
+    protected function loadConfig()
+    {
+        if (isset($this->config->ansi)) {
+            $this->ansi = $this->config->ansi;
+        }
+    }
 }
 ?>