/** * @param string $id * @return BaseEntity * @throws EntityNotFoundException */ public function get($id) { $entity = $this->dao->find($id); if ($entity === null) { throw new EntityNotFoundException("Entity ID: " . $id . " not found"); } return $entity; }
/** * @param int $id */ public function handleCheck($id) { $this->session->close(); $this->redrawControl('check'); $this->template->last = $newerThan = $this->commentDao->find($id); for ($x = 0; $x < 100; $x++) { if ($this->countNewComments($newerThan)) { $this->template->new = $this->getNewComments($newerThan); $this->template->last = end($this->template->new); $this->redrawControl('new'); break; } sleep(1); } }
public function getSportGroup($id, $useCache = true) { if ($id === null) { throw new Exceptions\NullPointerException("Arument id was null", 0); } if (!is_numeric($id)) { throw new Exceptions\InvalidArgumentException("Argument id has to be type of numeric, {$id} given", 1); } try { if (!$useCache) { return $this->groupDao->find($id); } $cache = $this->getEntityCache(); $data = $cache->load($id); if (empty($data)) { $data = $this->groupDao->find($id); $opt = [Cache::TAGS => [$this->getEntityClassName(), $id]]; $cache->save($id, $data, $opt); } } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } return $data; }
public function updateSeasonApplication(SeasonApplication $app) { if ($app === null) { throw new Exceptions\NullPointerException("Argument SeasonApplication cannot be null", 0); } try { $this->entityManager->beginTransaction(); $appDb = $this->seasonApplicationDao->find($app->getId(), false); if ($appDb !== null) { $app->setEnrolledTime($appDb->getEnrolledTime()); $appDb->fromArray($app->toArray()); $this->applicationSeasonTypeHandle($appDb); $this->applicationPaymentTypeHandle($appDb); $this->applicationGroupTypeHandle($appDb); $this->applicationOwnerTypeHandle($appDb); $this->applicationEditorTypeHandle($appDb); $appDb->setUpdated(new DateTime()); $this->entityManager->merge($appDb); $this->entityManager->flush(); } $this->entityManager->commit(); $this->invalidateEntityCache($appDb); $this->onUpdate(clone $appDb); } catch (DuplicateEntryException $ex) { $this->logWarning($ex); throw new Exceptions\DuplicateEntryException($ex->getMessage(), Exceptions\DuplicateEntryException::SEASON_APPLICATION, $ex->getPrevious()); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function updateSeason(Season $s) { if ($s === null) { throw new Exceptions\NullPointerException("Argument Season cannot be null"); } try { $this->entityManager->beginTransaction(); $seasonDb = $this->seasonDao->find($s->getId(), false); if ($seasonDb !== null) { if ($s->getCurrent()) { $this->setAllSeasonsAsInactive(); } $seasonDb->fromArray($s->toArray()); $this->seasonEditorTypeHandle($seasonDb); $this->entityManager->merge($seasonDb); $this->entityManager->flush(); } $this->entityManager->commit(); $this->invalidateEntityCache($seasonDb); $this->onUpdate($s); } catch (DuplicateEntryException $ex) { $this->logWarning($ex); throw new Exceptions\DuplicateEntryException($ex->getMessage(), Exceptions\DuplicateEntryException::SEASON_LABEL, $ex->getPrevious()); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function updateRule(AclRule $arule) { if ($arule === null) { throw new Exceptions\NullPointerException("Argument AclRule cannot be null"); } try { $this->entityManager->beginTransaction(); $dbRule = $this->aclRuleDao->find($arule->getId()); if ($dbRule !== null) { $dbRule->fromArray($arule->toArray()); $this->roleTypeHandle($dbRule); $this->entityManager->merge($dbRule); $this->entityManager->flush(); } $this->entityManager->commit(); $this->invalidateEntityCache($dbRule); $this->onUpdate($dbRule); } catch (DuplicateEntryException $e) { $this->entityManager->rollback(); $this->logWarning($e); throw new Exceptions\DuplicateEntryException($e->getMessage(), $e->getCode(), $e->getPrevious()); } catch (\Exception $e) { $this->entityManager->rollback(); $this->logError($e); throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious()); } }
public function deleteComment($c, ICommentable $e) { try { $wpDb = $this->pageDao->find($e->getId()); if ($wpDb !== null) { $coll = $wpDb->getComments(); $id = $this->getMixId($c); $comment = $coll->filter(function ($e) use($id) { return $e->getId() == $id; })->first(); $index = $coll->indexOf($comment); if (!is_numeric($index)) { return; } $coll->remove($index); $this->entityManager->merge($wpDb); $this->entityManager->flush($wpDb); $this->commentService->deleteComment($id); $this->invalidateEntityCache($wpDb); } } catch (Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function updatePosition(Position $p) { if ($p === null) { throw new Exceptions\NullPointerException("Argument Position cannot be null"); } try { $this->entityManager->beginTransaction(); $pDb = $this->positionDao->find($p->getId()); if ($pDb !== null) { $pDb->fromArray($p->toArray()); $this->posGroupTypeHandle($pDb); $this->posOwnerTypeHandle($pDb); $this->posRoleTypeHandle($pDb); $this->entityManager->merge($pDb); $this->entityManager->flush(); } $this->entityManager->commit(); $this->onUpdate($pDb); $this->invalidateEntityCache($pDb); } catch (DuplicateEntryException $e) { $this->entityManager->rollback(); $this->logError($e); throw new Exceptions\DuplicateEntryException($e->getMessage(), $e->getCode(), $e->getPrevious()); } }
public function deleteComment($id) { if (!is_numeric($id)) { throw new Exceptions\InvalidArgumentException("Argument id has to be type of numeric"); } try { $cDb = $this->commentDao->find($id); if ($cDb !== null) { $this->commentDao->delete($cDb); $this->invalidateEntityCache($cDb); $this->onDelete($cDb); } } catch (\Exception $ex) { throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function changeWebProfile(User $u) { try { $wp = $u->getWebProfile(); $user = $this->userDao->find($u->getId()); if ($wp->getPicture() instanceof \Nette\Http\FileUpload && $wp->getPicture()->isOk()) { $oldImgId = $wp->provideOldImgId(); $this->imageService->removeResource($oldImgId); $identifier = $this->imageService->storeNetteFile($wp->getPicture()); $wp->setPicture($identifier); } $this->entityManager->flush(); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
private function markAs($id, User $user, $as) { try { $db = $this->paymentDao->find($id); if ($db !== null) { $db->setStatus($as); $db->setEditor($user); $this->paymentEditorTypeHandle($db); $this->entityManager->merge($db); $this->entityManager->flush(); $this->invalidateEntityCache($db); } } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function getSeasonTax($id) { if (!is_numeric($id)) { throw new Exceptions\InvalidArgumentException("Argument id has to be type of numeric", 1); } try { $cache = $this->getEntityCache(); $data = $cache->load($id); if ($data === null) { $data = $this->seasonTaxDao->find($id); $opt = [Cache::TAGS => [$this->getEntityClassName(), $id]]; $cache->save($id, $data, $opt); } } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } return $data; }
public function updateSportType(SportType $type) { if ($type === null) { throw new Exceptions\NullPointerException("Argument SportType cannot be null"); } try { $dbType = $this->sportTypeDao->find($type->getId()); if ($dbType !== null) { $dbType->fromArray($type->toArray()); $this->entityManager->merge($dbType); $this->entityManager->flush(); $this->invalidateEntityCache($dbType); $this->onUpdate(clone $dbType); } } catch (DuplicateEntryException $ex) { $this->logWarning($ex->getMessage()); throw new Exceptions\DuplicateEntryException($ex); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function updateEntry(MotivationEntry $e) { try { $db = $this->entryDao->find($e->getId()); if ($db !== null) { $db->fromArray($e->toArray()); $db->setUpdated(new DateTime()); $this->entryEditorTypeHandle($db); $this->entryOwnerTypeHandle($db); $this->entrySeasonTypeHandle($db); $this->entityManager->merge($db); $this->entityManager->flush(); $this->invalidateEntityCache($db); $this->onUpdate($db); } } catch (DuplicateEntryException $ex) { $this->logWarning($ex->getMessage()); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
public function updateRole(Role $r) { if ($r === null) { throw new Exceptions\NullPointerException("Argument Role cannot be null"); } try { $dbRole = $this->roleDao->find($r->getId()); if ($dbRole !== null) { $dbRole->fromArray($r->toArray()); $dbRole->setParents($this->roleParentsCollSetup($r)); //$dbRole->setAdded(new \Nette\Utils\DateTime()); // this might cause hierarchy problems $this->entityManager->merge($dbRole); $this->entityManager->flush(); $this->invalidateEntityCache($dbRole); $this->onUpdate(clone $dbRole); } } catch (DuplicateEntryException $e) { throw new Exceptions\DuplicateEntryException($e->getMessage(), $e->getCode(), $e->getPrevious()); } catch (\Exception $e) { $this->logError($e); throw new Exceptions\DataErrorException($e->getMessage(), $e->getCode(), $e->getPrevious()); } }
public function updatePartner(Partner $p) { try { $db = $this->partnerDao->find($p->getId()); if ($db !== null) { $this->partnerPictureHandle($p, $db); $db->fromArray($p->toArray()); $db->setUpdated(new DateTime()); $this->editorTypeHandle($db); $this->referrerTypeHandle($db); $this->entityManager->merge($db); $this->entityManager->flush(); $this->invalidateEntityCache($db); $this->onUpdate($db); } } catch (\Kdyby\Doctrine\DuplicateEntryException $ex) { $this->logWarning($ex); throw new Exceptions\DuplicateEntryException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } catch (\Exception $ex) { $this->logError($ex->getMessage()); throw new Exceptions\DataErrorException($ex->getMessage(), $ex->getCode(), $ex->getPrevious()); } }
/** * @param FileEntityInterface $entity * @param FileUpload $file * * @return FileEntityInterface */ public function upload(FileEntityInterface $entity, FileUpload $file) { $checksum = sha1_file($file->getTemporaryFile()); $pairs = $this->storageDao->findPairs([], 'checksum', [], 'id'); if (in_array($checksum, $pairs)) { $id = array_search($checksum, $pairs); $e = $this->storageDao->find($id); ++$e->joints; return $e; } else { $e = $entity; $y = date('Y'); $m = date('m'); $data = $this->getFileData($file); $file->move($this->uploadDir . '/' . $y . '/' . $m . '/' . $data->name . '.' . $data->extension); $e->name = $data->name; $e->extension = $data->extension; $e->year = $y; $e->month = $m; $e->checksum = $checksum; $e->joints = 1; return $e; } }
/** * @param int $id * @return Entities\BaseEntity */ public function getById($id) { return $this->dao->find($id); }
/** * @param $albumId * @return Album */ public function get($albumId) { return $this->albumDao->find($albumId); }
/** * @param $id * @return null|User */ public function findUserById($id) { return $this->userDao->find($id); }
/** * @param int $userId * @return User */ public function get($userId) { return $this->userDao->find($userId); }
/** @return \Rixxi\User\IUser|null */ public function getSignedUser() { if ($this->securityUser->isLoggedIn()) { return $this->repository->find($this->securityUser->getIdentity()->getId()); } }
/** * @param EntityDao $dao */ public function load(EntityDao $dao) { $this->entity = $dao->find($this->id); $this->loaded = TRUE; }
/** * @param $id * @return Brabijan\SeoComponents\Entity\Route|object */ public function findRouteById($id) { return $this->routeDao->find($id); }