Exemplo n.º 1
0
 /**
  * Get the root path to class
  *
  * @return String
  */
 public static function getPath()
 {
     if (!self::$_path) {
         self::$_path = dirname(__FILE__);
     }
     return self::$_path;
 }
Exemplo n.º 2
0
 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();
     $chartPeriod = $this->getChartPeriod();
     if (!($outputFilename = $input->getOption("output-file"))) {
         $outputFilename = 'FetchData-' . $from_date . '-' . $to_date . '.xml';
     }
     $output->writeln('FetchData executed: ' . date('Ymd H:i:s'));
     $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));
     switch ($chartType) {
         case 'singlecolumn':
             $sortedTicketEntries = $this->fetchBillableHoursInPeriod($from_date, $to_date);
             $data = \GeckoChart::makeSingleColumn($sortedTicketEntries, $chartPeriod);
             break;
             // used for displaying budget vs. actual billable hours
         // used for displaying budget vs. actual billable hours
         case 'columnspline':
             $sortedTicketEntries = $this->fetchBillableHoursInPeriod($from_date, $to_date);
             $data = \GeckoChart::makeSingleColumnWithSpline($sortedTicketEntries, $chartPeriod);
             break;
         case 'stackedcolumn':
             $assembledEntries = $this->fetchAllHoursInPeriod($from_date, $to_date);
             $data = \GeckoChart::makeStackedColumn($assembledEntries, $chartPeriod);
             break;
         case 'piechart':
             $assembledEntries = $this->fetchAllHoursInPeriod($from_date, $to_date);
             $chartPeriodTitle = date("M. jS", strtotime($from_date)) . " - " . date("M. jS", strtotime($to_date));
             $data = \GeckoChart::makePieChart($assembledEntries, $chartPeriodTitle);
             break;
         default:
             $output->writeln("FetchData 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("\nFetchData completed -> " . $outputFilename . " updated");
     }
 }
Exemplo n.º 3
0
 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");
 }
Exemplo n.º 4
0
 public function formatHoursInPeriod($sortedTicketEntries, $chartPeriod)
 {
     $dateFormat = \GeckoChart::getChartPeriodAsDateFormat($chartPeriod);
     $formattedTicketEntries = array();
     // sort the ticket entries by date
     foreach ($sortedTicketEntries as $date => $hours) {
         if ($date != "statistics") {
             // update the timestamp unless it's the statistics key
             $date = date($dateFormat, strtotime($date));
         }
         $formattedTicketEntries[$date] = $hours;
     }
     return $formattedTicketEntries;
 }