/**
  * Import Projects
  */
 private function importProjects()
 {
     $this->output->write(sprintf('%-30s', 'Importing projects'));
     $previewProjects = $this->previewService->getProjects();
     $created = 0;
     $updated = 0;
     foreach ($previewProjects as $previewProject) {
         /**
          * @var Project $project
          */
         $project = $this->entityManager->getRepository('ProjectPreviewProjectBundle:Project')->find($previewProject->id);
         if (is_null($project)) {
             $project = new Project();
             $project->setId($previewProject->id);
             $created++;
         } else {
             $updated++;
         }
         $project->setName($previewProject->name);
         $project->setArchived($previewProject->archived);
         $this->entityManager->persist($project);
     }
     $this->output->writeln(sprintf('done (total: % 4d, created: % 4d, updated: % 4d)', $created + $updated, $created, $updated));
     $this->entityManager->flush();
 }
 /**
  * @param Project   $project
  * @param \DateTime $date
  *
  * @return int
  */
 public function getEstimatedTimeForDoneTicketByDate(Project $project, \DateTime $date)
 {
     $estimated = 0;
     foreach ($project->getTickets() as $ticket) {
         if ($ticket->getType() != 'task') {
             continue;
         }
         $status = $this->ticketService->getStateByDate($ticket, $date);
         if (!in_array($status, ['En Revue', 'Fermé'])) {
             continue;
         }
         $estimated += $ticket->getEstimatedTime();
     }
     return $estimated;
 }
 /**
  * @param Project $project
  * @param         $day
  *
  * @return array
  */
 private function getDayGraph(Project $project, $day)
 {
     $graph = [];
     $graph['created'] = 0;
     $graph['closed'] = 0;
     $graph['open'] = 0;
     foreach ($project->getTickets() as $ticket) {
         $created = $this->getTimeStamp($ticket->getCreated());
         $closed = $this->getTimeStamp($ticket->getClosed());
         if ($created == $day) {
             $graph['created']++;
         }
         if ($closed && $closed == $day) {
             $graph['closed']++;
         }
         if ($created <= $day && (!$closed || $closed >= $day)) {
             $graph['open']++;
         }
     }
     return $graph;
 }
 /**
  * @param Project $project
  */
 private function updateProjectTickets(Project $project)
 {
     $this->output->write(sprintf('%-30s', '  - Updating Tickets'));
     $previewTickets = $this->previewService->getTickets($project->getId());
     $zapped = 0;
     $created = 0;
     $updated = 0;
     $missed = 0;
     foreach ($previewTickets as $previewTicket) {
         $ticket = $this->entityManager->getRepository('ProjectPreviewPreviewBundle:Ticket')->find($previewTicket->id);
         if (!is_null($ticket) && $ticket->getUpdated()->getTimestamp() >= $previewTicket->updated && !$this->input->getOption('full-resync')) {
             $zapped++;
             continue;
         }
         if (is_null($ticket)) {
             $ticket = new Ticket();
             $ticket->setId($previewTicket->id);
             $created++;
         } else {
             $updated++;
         }
         $ticket->setProject($project);
         if ($this->updateTicketFromPreview($ticket, $previewTicket)) {
             $this->entityManager->persist($ticket);
             $this->importTicketActivities($ticket);
         } else {
             $missed++;
         }
     }
     $this->entityManager->flush();
     $this->output->writeln(sprintf('done (total: % 4d, created: % 4d, updated: % 4d, zapped: % 4d, missed: % 4d)', $created + $updated + $zapped, $created, $updated, $zapped, $missed));
 }
 /**
  * @param User    $user
  * @param Project $project
  *
  * @return bool
  */
 protected function checkClientRead(User $user, Project $project)
 {
     return in_array($user, $project->getClients()->toArray());
 }