So in my base template, I have: {% render "EcsCrmBundle:Module:checkClock" %}
Then I created the ModuleController.php...
<?php namespace Ecs\CrmBundle\Controller; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Ecs\CrmBundle\Entity\TimeClock; class ModuleController extends Controller { public function checkClockAction() { $em = $this->getDoctrine()->getEntityManager(); $user = $this->get('security.context')->getToken()->getUser(); $today = time(); $start = date('Y-m-d 00:00:00'); $entities = $em->getRepository('EcsCrmBundle:TimeClock'); $query = $entities->createQueryBuilder('tc') ->select('tc.in1, tc.out1, tc.in2, tc.out2, tc.in3, tc.out3') ->where('tc.noteBy = :user') ->andWhere('tc.daydate >= :start') ->setParameter('user', $user->getid()) ->setParameter('start', $start) ->setMaxResults('1') ->getQuery(); $entities = $query->getSingleResult(); if (empty($entities)) { $ents = "clocked_out"; $this->get('session')->set('clockedin', 'clocked_out'); } else { for ($i=1; $i <= 3; $i++) { if ($entities["in$i"] != NULL) { $ents = "clocked_in"; if ($i == 1) { $this->get('session')->set('nextclock', "out$i"); } else { $x = $i+1; $this->get('session')->set('nextClock', "out$x"); } if ($entities["out$i"] != NULL) { $ents = "clocked_out"; $x = $i+1; $this->get('session')->set('nextclock', "in$x"); } if ($entities["out3"] != NULL) { $ents = "day_done"; } } } } return $this->render('EcsCrmBundle:Module:topclock.html.twig', array( 'cstat' => $ents, )); } }
The problem is, if there is nothing in the database for the specific day for the specific user yet.. i keep getting:
I know it has something to do with the fact that is no 'result' from the database... but isn't that what i've accomplished by having the if (empty($entities)) {
?? I have no clue to fix it... any help appreciated...