protected function execute(InputInterface $input, OutputInterface $output) { $this->loadConfig($input); $ignore_locked = false; $from_date = $this->getHarvestFromDate("Ymd", "today"); $to_date = $this->getHarvestToDate("Ymd", "today"); $chartType = $this->getChartType(null); $chartPeriod = $this->getChartPeriod(null); if (!($outputFilename = $input->getOption("output-file"))) { $outputFilename = 'FetchEntries-' . $from_date . '-' . $to_date . '.xml'; } $output->writeln('FetchEntries executed: ' . date('Ymd H:i:s')); $output->writeln('Verifying projects in Harvest'); $output->writeln('Output filename: ' . $outputFilename); if ($this->getHarvestExcludeContractors()) { $output->writeln('NOTE: Contractors are excluded from the dataset!'); } $ticketEntries = $this->getEntriesByUsers($from_date, $to_date); $output->writeln(sprintf('Collected %d ticket entries', sizeof($ticketEntries))); if (sizeof($ticketEntries) == 0) { //We have no entries containing ticket ids so bail return; } $sortedEntries = null; foreach ($ticketEntries as $userArray) { foreach ($userArray as $entry) { $notes = strlen($entry->get('notes')) > 0 ? $entry->get('notes') : "..."; $output->writeln(sprintf('%s | %s - %s: "%s" (%s timer @ %s)', self::getUserNameById($entry->get('user-id')), self::getProjectNameById($entry->get('project-id')), self::getTaskNameById($entry->get("task-id")), $notes, $entry->get('hours'), $entry->get('spent-at'))); $sortedEntries[strtotime($entry->get("updated-at"))] = $entry; } } krsort($sortedEntries); // get top 30 $sortedEntries = array_slice($sortedEntries, 0, 30, true); // TODO: Refactor and move to GeckoChart.php // prepare the response! $geckoresponse = new \GeckoResponse(); // format as text foreach ($sortedEntries as $entry) { $notes = strlen($entry->get('notes')) > 0 ? $entry->get('notes') : "[no notes]"; $data['item'][] = array('text' => '<span class="t-size-x18">' . self::getProjectNameById($entry->get('project-id')) . ':</span><br/><span class="t-size-x24">"' . $notes . '"</span><br/><span class="t-size-x18">' . self::getUserNameById($entry->get('user-id')) . ' - ' . self::getTaskNameById($entry->get("task-id")) . ', ' . $entry->get('hours') . ' timer</span>', 'type' => 0); } $response = $geckoresponse->getResponse($data, true); // let's write the response to a file $outputFile = new StreamOutput(fopen('data/' . $outputFilename, 'w', false)); $outputFile->doWrite($response, false); $output->writeln("FetchEntries completed -> " . $outputFilename . " updated"); }
/** * Get the root path to class * * @return String */ public static function getPath() { if (!self::$_path) { self::$_path = dirname(__FILE__); } return self::$_path; }
protected function execute(InputInterface $input, OutputInterface $output) { $this->loadConfig($input); $ignore_locked = false; $from_date = $this->getHarvestFromDate("Ymd", "yesterday"); $to_date = $this->getHarvestToDate("Ymd", "yesterday"); $chartType = $this->getChartType("geekometer"); $chartPeriod = $this->getChartPeriod("day"); /* $updated_since = null; // NULL meeans all projects (and is thereby slow), but it doesnt seem to work correctly if I set the date otherwise // Ahh: http://forum.getharvest.com/forums/api-and-developer-chat/topics/announcement-greater-availability-of-updated_since-filtering-in-api // $updated_since = urlencode($this->getHarvestFromDate($input, "Y-m-d 00:00")); */ if (!($outputFilename = $input->getOption("output-file"))) { $outputFilename = 'FetchBillable-' . $from_date . '-' . $to_date . '.xml'; } //Setup Harvest API access $harvest = $this->getHarvestApi(); $output->writeln('FetchBillable executed: ' . date('Ymd H:i:s')); $output->writeln('Verifying projects in Harvest'); $output->writeln('Output filename: ' . $outputFilename); if ($this->getHarvestExcludeContractors()) { $output->writeln('NOTE: Contractors are excluded from the dataset!'); } $output->writeln(sprintf('Chart type is "%s" and period is "%s"', $chartType, $chartPeriod)); $output->writeln(sprintf("Collecting Harvest entries between %s to %s", $from_date, $to_date)); $sortedTicketEntries = $this->fetchBillableHoursInPeriod($from_date, $to_date); $output->writeln(sprintf('Collected %d ticket entries', sizeof($sortedTicketEntries) - 1)); if (!sizeof($sortedTicketEntries) > 0) { //We have no entries containing ticket ids so bail return; } $output->writeln(sprintf('OutputFormat for Geckoboard: %s', $chartType)); switch ($chartType) { default: case "geekometer": $output->writeln(sprintf('"%s" will show data for the entire period regardless of what is specified', $chartType)); // prepare the response! $geckoresponse = new \GeckoResponse(); $billableHours = $sortedTicketEntries["statistics"]["totalhours"]; $output->writeln(sprintf('Billable hours from %s to %s: %s', $from_date, $to_date, $billableHours)); $data['item'] = round($billableHours); $data['type'] = "standard"; $data['min'][] = array('value' => 0, 'text' => ''); $data['max'][] = array('value' => 75, 'text' => ''); // fetch data $response = $geckoresponse->getResponse($data, true); break; case "line": $output->writeln(sprintf('Billable hours from %s to %s: %s', $from_date, $to_date, $sortedTicketEntries["statistics"]["totalhours"])); // lets strip the statistics data array_pop($sortedTicketEntries); $sortedTicketEntries = \GeckoChart::formatValuesToKeys($sortedTicketEntries, $chartPeriod); $response = \GeckoChart::formatXmlGeckoboardLine($sortedTicketEntries); break; } // let's write the response to a file $outputFile = new StreamOutput(fopen('data/' . $outputFilename, 'w', false)); $outputFile->doWrite($response, false); $output->writeln("FetchBillable completed -> " . $outputFilename . " updated"); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->loadConfig($input); $from_date = $this->getHarvestFromDate("Ymd", "yesterday"); $to_date = $this->getHarvestToDate("Ymd", "yesterday"); $chartType = $this->getChartType("numberstat"); $chartPeriod = $this->getChartPeriod(null); if (!($outputFilename = $input->getOption("output-file"))) { $outputFilename = 'ComparePeriods-' . $from_date . '-' . $to_date . '.xml'; } if ($this->getHarvestExcludeContractors()) { $output->writeln('NOTE: Contractors are excluded from the dataset!'); } $output->writeln('ComparePeriods executed: ' . date('Ymd H:i:s')); $output->writeln('Output filename: ' . $outputFilename); // $output->writeln(sprintf('Chart type is "%s" and period is "%s"',$chartType,$chartPeriod)); $datetime1 = new \DateTime($to_date); $datetime2 = new \DateTime($from_date); $interval = $datetime1->diff($datetime2); /* echo "Datetime1: (to) " . $datetime1->format('Ymd') . "\n"; echo "Datetime2: (from) " . $datetime2->format('Ymd') . "\n"; echo "Diff: ". $interval->format('%R%a days') . "\n"; */ // subtract one day as all days are inclusive $prev_to_date = $datetime2->sub(new \DateInterval('P1D'))->format('Ymd'); $prev_from_date = $datetime2->sub(new \DateInterval($interval->format('P%aD')))->format('Ymd'); /* echo "new to date: " . $prev_to_date . "\n"; echo "new from date: " . $prev_from_date . "\n"; */ switch ($chartType) { case 'numberstat': $output->writeln(sprintf("Collecting Harvest entries between %s to %s", $from_date, $to_date)); $currentPeriodEntries = $this->fetchBillableHoursInPeriod($from_date, $to_date); $output->writeln("\n"); $output->writeln(sprintf("Collecting Harvest entries between %s to %s", $prev_from_date, $prev_to_date)); $prevPeriodEntries = $this->fetchBillableHoursInPeriod($prev_from_date, $prev_to_date); // prepare the response! $geckoresponse = new \GeckoResponse(); $data['type'] = "standard"; $data['item'][] = array('value' => round($currentPeriodEntries["statistics"]["totalhours"], 0), 'text' => 'hours'); $data['item'][] = array('value' => round($prevPeriodEntries["statistics"]["totalhours"], 0), 'text' => ''); $data = $geckoresponse->getResponse($data, true); break; case 'numberstatbudget': $output->writeln(sprintf("Collecting Harvest entries between %s to %s", $from_date, $to_date)); $currentPeriodEntries = $this->fetchBillableHoursInPeriod($from_date, $to_date); // prepare the response! $geckoresponse = new \GeckoResponse(); $data['type'] = "standard"; $data['item'][] = array('value' => round($currentPeriodEntries["statistics"]["totalhours"], 0), 'text' => 'hours'); $data['item'][] = array('value' => round($currentPeriodEntries["statistics"]["totalbudget"], 2), 'text' => ''); $data = $geckoresponse->getResponse($data, true); break; default: $output->writeln("ComparePeriods ChartType not recognized -> " . $chartType . ""); return; break; } // lets write the data to a file if ($data) { $outputFile = new StreamOutput(fopen('data/' . $outputFilename, 'w', false)); $outputFile->doWrite($data, false); $output->writeln("\nComparePeriods completed -> " . $outputFilename . " updated"); } }