Make the tag result list scrollable so long tags can be read
[ajatus.git] / plugins / openpsa / export-hours.php
blob9957b3d482e70435329c22cf1595d60a860b0cd4
1 <?php
2 require('CouchDb/Couch.php');
3 $couch = new Couch(array('host' => 'localhost', 'port' => 5984));
4 if (!$couch->running())
6 die("Cannot connect to CouchDB in {$couch->host()}:{$coudh->port()}\n");
9 $couchdb = $couch->database('ajatus_db_content', $couch);
10 if(!$couchdb->exists())
12 die("CouchDB database {$couchdb->name()} does not exist\n");
15 $hours = array();
16 $total_hours = array();
18 // Construct the view
19 $view = $couchdb->newView();
20 $view->function = "function(doc) { if (doc.value._type == 'hour_report') { map(null, doc); }}";
21 $results = $view->documents();
23 //$everything = $couchdb->view('_all_docs')->documents();
24 foreach ($results as $result)
26 $document = $result->value;
27 $creator = $document->value->metadata->creator->val;
28 if (!isset($hours[$creator]))
30 $hours[$creator] = array();
33 $month = substr($document->value->date->val, 0, 7);
34 if (!isset($hours[$creator][$month]))
36 $hours[$creator][$month] = array();
38 if (!isset($total_hours[$month]))
40 $total_hours[$month] = array();
41 $total_hours[$month]['all'] = 0;
43 if (!isset($total_hours[$month][$creator]))
45 $total_hours[$month][$creator] = 0;
48 $hours[$creator][$month][] = array
50 'date' => $document->value->date->val,
51 'hours' => $document->value->hours->val,
52 'description' => $document->value->description->val,
55 $total_hours[$month]['all'] += $document->value->hours->val;
56 $total_hours[$month][$creator] += $document->value->hours->val;
58 ksort($total_hours);
60 foreach ($total_hours as $month => $type)
62 echo "{$month}\n-------\n";
63 foreach ($type as $reporter => $hours_sum)
65 echo "{$reporter}: {$hours_sum}h\n";
67 echo "\n";