/** * @param $slug * @return null|Administration * @throws EntityNotFoundException */ public function getAdministrationBySlug($slug) { $administration = $this->entityManager->getRepository('HomefinanceBundle:Administration')->findOneBy(array('slug' => $slug)); if (!$administration) { throw new EntityNotFoundException(); } return $administration; }
public function getSaldo(BankAccount $bankAccount) { $repo = $this->entityManager->getRepository('HomefinanceBundle:Transaction'); $transactions = $repo->findBy(array('administration' => $bankAccount->getAdministration(), 'bank_account' => $bankAccount)); $total = (double) $bankAccount->getStartingBalance(); foreach ($transactions as $t) { $total = $total + $t->getAmount(); } return $total; }
public function findUserByToken($token) { $user_repo = $this->entityManager->getRepository('HomefinanceBundle:User'); $user = $user_repo->findOneBy(array('confirmationToken' => $token)); if ($user && $user->isTokenValid()) { return $user; } throw new EntityNotFoundException(); }
public function allLeafCategories(Administration $administration = null) { if (!$administration) { $administration = $this->getCurrentAdministration(); } if (!$administration) { return array(); } $repo = $this->entityManager->getRepository('HomefinanceBundle:Category'); $categories = $repo->getChildrenByAdministration($administration); foreach ($categories as $i => $category) { if (count($category->getChildren())) { unset($categories[$i]); } } $categories = $this->sortCategoriesAlphabetically($categories); return $categories; }
public function getNextUnprocessedTransaction(Administration $administration, Transaction $transaction = null) { $repo = $this->entityManager->getRepository('HomefinanceBundle:Transaction'); $transactions = $repo->findUnprocessedByAdministration($administration); $found = false; if ($transaction != null) { foreach ($transactions as $t) { if ($found) { return $t; } if ($t->getId() == $transaction->getId()) { $found = true; } } } if (count($transactions)) { return reset($transactions); } return null; }
public function loadOrCreateTags($tags, Administration $administration = null) { if (!$administration) { $administration = $this->getCurrentAdministration(); } if (!$administration) { return array(); } $repo = $this->entityManager->getRepository('HomefinanceBundle:Tag'); $values = array(); foreach ($tags as $tag) { $t = $repo->findOneByNameAndAdministration($administration, $tag); if (!$t) { $t = new Tag(); $t->setAdministration($administration); $t->setName($tag); $this->entityManager->persist($t); } $values[] = $t; } return $values; }
/** * Return the specific Section for an Exception Event * * @param $id * @param $name * * @return object|Section */ private function getExceptionSection($id, $name) { // TODO Use a tagging system with internal tags. ie: _section_404 $sectionRepository = $this->entityManager->getRepository('UnifikSystemBundle:Section'); $sectionRepository->setCurrentAppName('frontend'); $sectionRepository->setLocale($this->defaultLocale); $section = $sectionRepository->find($id); // Doesn't exist, create the Section if (!$section) { $section = new Section(); $section->setCurrentLocale($this->defaultLocale); $section->setApp($this->entityManager->getRepository('UnifikSystemBundle:App')->find(2)); $section->setId($id); $section->setName($this->translator->trans($name, array(), 'messages', $this->defaultLocale)); $section->setActive(true); $this->entityManager->persist($section); // Force ID $metadata = $this->entityManager->getClassMetaData(get_class($section)); $metadata->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_NONE); $this->entityManager->flush(); } return $section; }