コード例 #1
0
 /**
  * @param WorkedHours $workedHours
  * @return WorkedHours
  * @throws \Doctrine\DBAL\DBALException
  * @throws \Exception
  */
 public function setupWorkedHoursEntity(WorkedHours $workedHours)
 {
     $values = $workedHours->toArray(true);
     /* In order to NOT auto increment workedHours ID counter in DB by
                INSERTs that actually wont happen (e.g. safePersist()) and
                because Doctrine2 does NOT support locking of entire tables,
                we have to use native SQL(MySQL) query.
     
                DUAL is "dummy" table - there is no need to reference any table
                (more info in MySQL SELECT documentation)
             */
     $this->em->getConnection()->executeQuery('INSERT INTO worked_hours (work_start, work_end, lunch, other_hours)
          SELECT :workStart, :workEnd, :lunch, :otherHours FROM DUAL
          WHERE NOT EXISTS(
                SELECT work_start, work_end, lunch, other_hours
                FROM worked_hours
                WHERE work_start = :workStart AND work_end = :workEnd AND
                      lunch = :lunch AND other_hours = :otherHours)
          LIMIT 1', $values);
     $result = $this->em->createQuery('SELECT wh FROM ' . WorkedHours::class . ' wh
          WHERE wh.workStart = :workStart AND wh.workEnd = :workEnd AND
                wh.lunch = :lunch AND wh.otherHours = :otherHours')->setParameters($values)->getOneOrNullResult();
     return $result;
 }
コード例 #2
0
 /**
  * @return bool
  */
 public function areWorkedHoursWithoutLunchZero()
 {
     $workedHours = $this->workedHours->getWorkEnd()->subTime($this->workedHours->getWorkStart());
     return $workedHours->compare('00:00:00') === 0 ? true : false;
 }