/** * @param WorkedHours $workedHours * @return WorkedHours * @throws \DibiException */ public function setupWorkedHours(WorkedHours $workedHours) { $values = ['workStart' => $workedHours->workStart->getTime(), 'workEnd' => $workedHours->workEnd->getTime(), 'lunch' => $workedHours->lunch->getTime(), 'otherHours' => $workedHours->otherHours->getTime()]; try { $this->connection->query('LOCK TABLES worked_hours WRITE'); $data = $this->connection->query('SELECT workedHoursID AS id FROM worked_hours WHERE %and', $values)->fetch(); if ($data === false) { $this->connection->query('INSERT INTO [worked_hours]', $values); $id = $this->connection->getInsertId(); } else { $id = $data['id']; } $this->connection->query('UNLOCK TABLES'); if (!$workedHours->isDetached()) { $workedHours->detach(); } $workedHours->makeAlive($this->entityFactory, $this->connection, $this->mapper); $workedHours->attach($id); return $workedHours; } catch (\DibiException $e) { $this->connection->query('UNLOCK TABLES'); Debugger::log($e, Debugger::ERROR); throw $e; } }
/** * @param WorkedHours $workedHours */ private function setWorkedHours(WorkedHours $workedHours) { $workedHours->checkEntityState(); $this->assignEntityToProperty($workedHours, 'workedHours'); }