Make the tag result list scrollable so long tags can be read
[ajatus.git] / plugins / openpsa / hours-to-nabaztag.php
blob36c24c4cd9f6f70a18d03016f6493d31e56a7316
1 <?php
2 require('Services/Nabaztag.php');
3 require('CouchDb/Couch.php');
5 // Argument checks
6 if (count($argv) != 4)
8 die("Usage: php hours-to-nabaztag.php dbname serialno apitoken\n");
10 $nabaztag = new Services_Nabaztag($argv[2], $argv[3]);
12 $couch = new Couch(array('host' => 'localhost', 'port' => 5984));
13 if (!$couch->running())
15 die("Cannot connect to CouchDB in {$couch->host()}:{$coudh->port()}\n");
18 $couchdb = $couch->database($argv[1], $couch);
19 if(!$couchdb->exists())
21 die("CouchDB database {$couchdb->name()} does not exist\n");
24 $total_hours = array();
26 // Construct the view
27 //$view = $couchdb->newView();
28 //$view->function = "function(doc) { return doc; }";
29 //$hour_reports = $view->documents();
31 $everything = $couchdb->view('_all_docs')->documents();
32 foreach ($everything as $object)
34 $document = $couchdb->get($object->id);
35 if ($document->value->_type != 'hour_report')
37 continue;
40 $month = substr($document->value->date->val, 0, 7);
41 $day = substr($document->value->date->val, 0, 10);
42 if (!isset($total_hours[$month]))
44 $total_hours[$month] = array();
45 $total_hours[$month]['all'] = 0;
47 if (!isset($total_hours[$month][$day]))
49 $total_hours[$month][$day] = 0;
52 $total_hours[$month]['all'] += $document->value->hours->val;
53 $total_hours[$month][$day] += $document->value->hours->val;
55 ksort($total_hours);
57 $this_month = date('Y-m');
58 $this_day = date('Y-m-d');
60 try
62 $stat = $nabaztag->say("In Ajatus we have " . round($total_hours[$this_month][$this_day]) . " hours reported today, and " . round($total_hours[$this_month][all]) . " reported this month.");
64 catch (Services_Nabaztag_Exception $e)
66 //echo $e;