/** * @param array $row * @return \NetNexus\TimesheetBundle\Entity\Workitem */ protected function workitemFromRow(array $row) { $wi = new Workitem(); $wi->setDay(\DateTime::createFromFormat('Y-m-d', $row[0])); $wi->setStart(\DateTime::createFromFormat('H:i', $row[1])); $wi->setEnd(\DateTime::createFromFormat('H:i', $row[2])); $wi->setQueue($row[3]); $wi->setTicket(str_replace('RT:', '', $row[4])); $wi->setDescription($row[5]); return $wi; }
/** * Lists all Workitem entities. * * @Route("/", name="workitem") * @Method("GET") * @Template() */ public function indexAction() { $em = $this->getDoctrine()->getManager(); /** @var WorkitemRepository $repo */ $repo = $em->getRepository('NetNexusTimesheetBundle:Workitem'); $entities = $repo->findAll(self::DEFAULT_LIMIT); $totalToday = $repo->getDurationByDay(new DateTime()); $totalMonth = $repo->getDurationByMonth(new DateTime()); $totalLastMonth = $repo->getDurationByMonth(new DateTime('last day of last month')); $latestEntity = $repo->findLatest(); if (empty($latestEntity)) { // empty db $createform = $this->createCreateForm(new Workitem())->createView(); return array('entities' => array(), 'totalToday' => 0, 'totalMonth' => 0, 'createform' => $createform); } $entity = new Workitem(); $entity->setDay(new DateTime()); $entity->setQueue($latestEntity->getQueue()); // end time from last entry or rounded current time if no entry for today $st = $entity->getDay()->format("Y-m-d") == $latestEntity->getDay()->format("Y-m-d") ? clone $latestEntity->getEnd() : DateTime::createFromFormat('U', ceil(time() / 300) * 300); $entity->setStart($st); $createform = $this->createCreateForm($entity)->createView(); return compact('entities', 'totalToday', 'totalMonth', 'totalLastMonth', 'createform'); }