/** * Save subscription * * @param array $values * @param Newscoop\Entity\Subscription|null $subscription * @return Newscoop\Entity\Subscription */ public function save(array $values, Subscription $subscription = null) { if ($subscription === null) { $subscription = new Subscription(); $this->em->persist($subscription); } if (array_key_exists('user', $values)) { $subscription->setUser(is_numeric($values['user']) ? $this->em->getReference('Newscoop\\Entity\\User', $values['user']) : $values['user']); } if (array_key_exists('publication', $values)) { $subscription->setPublication(is_numeric($values['publication']) ? $this->em->getReference('Newscoop\\Entity\\Publication', $values['publication']) : $values['publication']); } if (array_key_exists('type', $values)) { $subscription->setType($values['type']); } if (array_key_exists('active', $values)) { $subscription->setActive($values['active']); } if (array_key_exists('currency', $values)) { $subscription->setCurrency($values['currency']); } if (array_key_exists('toPay', $values)) { $subscription->setToPay($values['toPay']); } if (array_key_exists('add_sections', $values) && $values['add_sections']) { if (!array_key_exists('publication', $values)) { throw new \InvalidArgumentException("No publication provided for adding sections"); } $publication = is_numeric($values['publication']) ? $this->em->getRepository('Newscoop\\Entity\\Publication')->find($values['publication']) : $values['publication']; $subscription->addSections($values, $publication); } $this->em->flush(); return $subscription; }
/** * Chart od the most frequent contribution types * * @param array $options * @return type */ public function getContributionStatusGraph($options, $criteria = array()) { $options = $this->getMergedOptions($options); $data = $this->em->getRepository('SouphpspBundle:Contribution')->getCountByStatus($criteria); $processedData = $this->parseContributionStatusData($data); return $this->chart->pieChart('Estado das contribuições', $processedData, $options); }
public function init() { $this->doctrine = Zend_Registry::get('doctrine'); $this->em = $this->doctrine->getEntityManager(); $this->_categoria = $this->em->getRepository('\\Models\\Entity\\Categoria'); $this->_fabricante = $this->em->getRepository('\\Models\\Entity\\Fabricante'); $this->_producto = $this->em->getRepository('\\Models\\Entity\\Producto'); }
public function find_one_by($categoria_id) { try { $categoria = $this->em->getRepository(Categoria_dao::REPOSITORY)->findOneBy(array('id_categoria' => $categoria_id)); return $categoria; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - categoria_dao::find_one_by '); } return null; }
public function find_one_by($curso_id) { try { $curso = $this->em->getRepository(Curso_dao::REPOSITORY)->findOneBy(array('idCurso' => $curso_id)); return $curso; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - curso_dao::find_one_by '); } return false; }
public function find_one_by($modalidade_id) { try { $modalidade = $this->em->getRepository(Modalidade_dao::REPOSITORY)->findOneBy($modalidade_id); return $modalidade; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - modalidade_dao::find_one_by '); } return null; }
private static function getParentNode($parentNodeParam) { $parentNode = null; if (!empty($parentNodeParam)) { if (isset($parentNodeParam['pageUid'])) { $parentNode = self::$em->getRepository('BackBee\\NestedNode\\Page')->find($parentNodeParam['pageUid']); } } else { $parentNode = self::$renderer->getCurrentPage(); } return $parentNode; }
public function down(Schema $schema) { $customers = $this->em->getRepository('Group3\\Bundle\\ABundle\\Entity\\Customer')->findAll(); foreach ($customers as $customer) { $this->em->remove($customer); } $inventory = $this->em->getRepository('Group3\\Bundle\\ABundle\\Entity\\Inventory')->findAll(); foreach ($inventory as $item) { $this->em->remove($item); } $this->em->flush(); }
public function setUp() { parent::setUp('Newscoop\\Entity\\User', 'Newscoop\\Entity\\Acl\\Role', 'Newscoop\\Entity\\UserAttribute'); $this->auth = $this->getMockBuilder('Zend_Auth')->disableOriginalConstructor()->getMock(); $this->repository = $this->em->getRepository('Newscoop\\Entity\\User'); $this->service = new UserService($this->em, $this->auth); $this->user = new User(); $this->user->setEmail('*****@*****.**'); $this->user->setUsername('test'); $this->user->setFirstName('Foo'); $this->user->setLastName('Bar'); }
/** * validates users if invited to use the beta site * @param string $email * @param string $token * * @return self */ public function authenticate($email, $token) { $invite = $this->entityManager->getRepository('BugglMainBundle:BetaInvite')->retrieveByEmailAndToken($email, $token); $this->allowed = !is_null($invite); if ($this->allowed) { $name = $this->constants->get('buggl_beta_authenticated'); $this->session->set($name, true); $this->session->set('beta_invite_email', $email); $this->session->set('beta_invite_token', $token); if ($invite->getStatus() == $this->constants->get('BETA_INVITE_PENDING')) { $invite->setStatus($this->constants->get('BETA_INVITE_ACCEPTED')); $this->entityManager->flush(); } } return $this; }
/** * Get the queue entity. * * @param string $name * * @return Queue Entity * * @throws ZendQueue\Exception */ protected function getQueueEntity($name) { $repo = $this->em->getRepository('Heri\\Bundle\\JobQueueBundle\\Entity\\Queue')->findOneBy(['name' => $name]); if (!$repo) { throw new AdapterRuntimeException(sprintf('Queue does not exist: %s', $name)); } return $repo; }
/** * @param Doctrine\ORM\EntityManager $em * @param string $entityName * @param integer $count * @return \Ojs\JournalBundle\Entity\Sums */ private function saveSum($em, $entityName, $count) { $check = $em->getRepository("OjsJournalBundle:Sums")->findOneBy(array('entity' => $entityName)); $sum = $check ? $check : new Sums(); $sum->setEntity($entityName); $sum->setSum($count); $em->persist($sum); $em->flush(); }
/** * Get article specific image caption * * @param int $imageId * @param int $articleNumber * @param int $languageId * * @return string */ public function getArticleImageCaption($imageId, $articleNumber, $languageId) { $query = $this->orm->getRepository('Newscoop\\Image\\ArticleImageCaption')->createQueryBuilder('c')->select('c.caption')->where('c.articleNumber = :article')->andWhere('c.image = :image')->andWhere('c.languageId = :language')->getQuery(); $query->setParameters(array('article' => $articleNumber, 'image' => $imageId, 'language' => $languageId)); try { return $query->getSingleScalarResult(); } catch (NoResultException $e) { } }
public function testNew() { $url = self::$router->generate('support_new'); $crawler = self::$client->request('GET', $url); $faker = Factory::create(); $service = self::$entityManager->getRepository('KoopaAppBundle:Service')->findAll()[0]; $this->assertEquals(self::$client->getResponse()->getStatusCode(), Response::HTTP_OK); $form = $crawler->filter('form[name=koopa_app_support]'); $this->assertTrue($form->count() > 0); $form = $form->form(); $form['koopa_app_support[name]'] = 'Foo Support'; $form['koopa_app_support[service]'] = $service->getId(); $form['koopa_app_support[pack][detail]'] = $faker->text(300); // submit and follow the redirect response self::$client->submit($form); $crawler = self::$client->followRedirect(); $this->assertEquals(self::$client->getResponse()->getStatusCode(), Response::HTTP_OK); $this->assertTrue($crawler->filter('table [data-id]')->count() > 0); }
/** * Update schema if needed * * @return void */ private function updateSchema($articleNumber) { try { $this->orm->getRepository('Newscoop\\Image\\ArticleImage')->findOneBy(array('articleNumber' => (int) $articleNumber)); } catch (\Exception $e) { if ($e->getCode() === '42S22') { $this->orm->getConnection()->exec('ALTER TABLE ArticleImages ADD is_default INT(1) DEFAULT NULL'); } } }
/** * Get rendition by given name * * @param string $name * @return Newscoop\Image\Rendition */ public function getRendition($name) { $renditions = $this->getRenditions(); $rendition = array_key_exists($name, $renditions) ? $renditions[$name] : null; if ($rendition !== null) { $rendition = $this->orm->getRepository('Newscoop\\Image\\Rendition')->find($rendition->getName()); $this->orm->persist($rendition); $this->orm->flush($rendition); } return $rendition; }
public function onKernelRequest(GetResponseEvent $event) { $request = $event->getRequest(); $session = $request->getSession(); $cookie_login = $request->cookies->get('login'); if (!$session->get('id') && $cookie_login) { $cookie_login_info = explode(':', $cookie_login); $user = $this->em->getRepository('ApplicationUserBundle:User')->find($cookie_login_info[0]); if (!($pass = $user->getPass())) { $pass = md5($user->getDate()->format('Y-m-d H:i:s')); } if ($cookie_login_info[1] == $pass) { $session->set('id', $user->getId()); $session->set('name', $user->getShortName()); $session->set('slug', $user->getSlug()); $session->set('admin', $user->getAdmin()); $session->set('moderator', $user->getModerator()); } } }
public function testDelete() { $package = $this->service->save(array('headline' => 'tic')); $this->service->addItem($package, new LocalImage(self::PICTURE_LANDSCAPE)); $this->service->saveArticle(array('id' => 1, 'slideshows' => array(array('id' => $package->getId())))); $this->service->delete($package->getId()); $this->orm->clear(); $this->assertEquals(0, count($this->service->findBy(array()))); $this->assertEquals(0, count($this->orm->getRepository('Newscoop\\Package\\Item')->findAll())); $this->assertEquals(0, count($this->service->findByArticle(1))); }
private static function getLink($linkParam) { $routing = self::$application->getRouting(); $link = ['url' => '', 'title' => 'Visit', 'target' => '_self']; if (isset($linkParam['pageUid']) && !empty($linkParam['pageUid'])) { $page = self::$em->getRepository('BackBee\\NestedNode\\Page')->find($linkParam['pageUid']); if (null !== $page) { $link['url'] = $routing->getUri($page->getUrl()); } } if (empty($link['url']) && isset($linkParam['url'])) { $link['url'] = $linkParam['url']; } if (isset($linkParam['title'])) { $link['title'] = $linkParam['title']; } if (isset($linkParam['target'])) { $link['target'] = $linkParam['target']; } return $link; }
public function indexAction() { $addQuoteForm = new \App\Form\AddQuote(); $this->view->form = $addQuoteForm; $this->checkSearchindex(); try { $data = $this->_em->getRepository("\\App\\Entity\\Quote")->findThemAll(); $this->view->data = $data; } catch (Exception $e) { $this->view->databaseError = true; } }
/** * @depends testIndex * * @param integer $supportId */ public function testNew($supportId) { $url = self::$router->generate('formule_new', ['id' => $supportId]); // find support and show formule create form $crawler = self::$client->request('GET', $url); $support = self::$entityManager->getRepository('KoopaAppBundle:Support')->find($supportId); $form = $crawler->filter('form[name="koopa_app_formule"]'); $this->assertTrue($form->count() > 0); $form = $form->form(); $form['koopa_app_formule[name]'] = 'Foo Formule'; $form['koopa_app_formule[debit]'] = '155'; $form['koopa_app_formule[pricing]'] = '320'; $form['koopa_app_formule[support]'] = $support->getId(); self::$client->submit($form); $crawler = self::$client->followRedirect(); $this->assertEquals(self::$client->getResponse()->getStatusCode(), Response::HTTP_OK); $this->assertRegExp('/Foo Formule/', self::$client->getResponse()->getContent()); $formuleItem = $crawler->filter('table [data-formule-id]')->last(); $this->assertTrue($formuleItem->count() > 0); return $formuleItem->attr('data-formule-id'); }
/** * Perform a query * * @param string $query * @return array */ public function find($query, $criteria = null, $sort = null, $paging = null, &$count = null) { $count = 0; $qb = $this->orm->getRepository('Newscoop\\Image\\LocalImage')->createQueryBuilder('i'); $qb_count = $this->orm->getRepository('Newscoop\\Image\\LocalImage')->createQueryBuilder('i')->select('COUNT(i)'); $tokens_spec = $qb->expr()->orx(); $tokens = explode(' ', trim($query)); foreach ($tokens as $i => $token) { $tokens_spec->add($qb->expr()->like('i.description', $qb->expr()->literal("%{$token}%"))); } if (!empty($tokens_spec)) { $qb->andWhere($tokens_spec); $qb_count->andWhere($tokens_spec); } if (is_array($criteria) && isset($criteria['source']) && is_array($criteria['source']) && !empty($criteria['source'])) { $source_cases = array(); foreach ($criteria['source'] as $one_source) { $source_cases[] = $one_source; } $qb->andwhere('i.source IN (:source)'); $qb->setParameter('source', $source_cases); $qb_count->andwhere('i.source IN (:source)'); $qb_count->setParameter('source', $source_cases); } if (!empty($sort) && is_array($sort)) { foreach ($sort as $sort_column => $sort_dir) { $qb->addOrderBy('i.' . $sort_column, $sort_dir); } } if (!empty($paging) && is_array($paging)) { if (isset($paging['length'])) { $qb->setMaxResults(0 + $paging['length']); } if (isset($paging['offset'])) { $qb->setFirstResult(0 + $paging['offset']); } } $count = 0 + (int) $qb_count->getQuery()->getSingleScalarResult(); return $qb->getQuery()->getResult(); }
/** * Perform a query * * @param string $query * @return array */ public function find($query, $criteria = null, $sort = null, $paging = null, &$count = null, $queryOnly = false) { $qb = $this->orm->getRepository('Newscoop\\Image\\LocalImage')->createQueryBuilder('i'); $andX = $qb->expr()->andX(); if (is_numeric($query)) { $andX->add($qb->expr()->eq('i.user', $query)); } else { $andX->add($qb->expr()->like('i.description', $qb->expr()->literal("%{$query}%"))); } if (!empty($andX)) { $qb->andWhere($andX); } if (is_array($criteria) && isset($criteria['source']) && is_array($criteria['source']) && !empty($criteria['source'])) { $orX = $qb->expr()->orx(); foreach ($criteria['source'] as $oneSource) { $orX->add($qb->expr()->eq('i.source', $qb->expr()->literal($oneSource))); } $qb->andWhere($orX); } if (is_array($criteria) && isset($criteria['user']) && !empty($criteria['user'])) { $andX->add($qb->expr()->eq('i.user', $criteria['user'])); } if (!empty($sort) && is_array($sort)) { foreach ($sort as $sortColumn => $sortDir) { $qb->addOrderBy('i.' . $sortColumn, $sortDir); } } if ($queryOnly) { return $qb->getQuery(); } if (!empty($paging) && is_array($paging)) { if (isset($paging['length'])) { $qb->setMaxResults(0 + $paging['length']); } if (isset($paging['offset'])) { $qb->setFirstResult(0 + $paging['offset']); } } return $qb->getQuery()->getResult(); }
public function testPublishPicture() { $xml = simplexml_load_file(APPLICATION_PATH . '/../tests/fixtures/' . self::PICTURE_XML); $item = NewsItem::createFromXml($xml->itemSet->newsItem); $feed = $this->getMockBuilder('Newscoop\\News\\Feed')->disableOriginalConstructor()->getMock(); $feed->expects($this->once())->method('getRemoteContentSrc')->with($this->equalTo($item->getContentSet()->getRemoteContent('rend:baseImage')))->will($this->returnValue(APPLICATION_PATH . '/../tests/fixtures/picture.jpg')); $item->setFeed($feed); $this->service->publish($item); $this->assertTrue($item->isPublished()); $this->assertInstanceOf('DateTime', $item->getPublished()); $pictures = $this->orm->getRepository('Newscoop\\Entity\\Picture')->findAll(); $this->assertEquals(1, count($pictures)); $picture = $pictures[0]; $this->assertEquals('Alex Blackburn-Smith arrives at Croydon Magistrates Court in southeast London', $picture->getHeadline()); $this->assertEquals('Alex Blackburn-Smith arrives at Croydon Magistrates Court in southeast London December 6, 2011. Blackburn-Smith pleaded guilty to failing to ensure a dog�s welfare, as well as being in possession of a banned pitbull terrier. example/Luke MacGregor (BRITAIN - Tags: CRIME LAW)', $picture->getCaption()); $this->assertEquals('image/jpeg', $picture->getContentType()); $this->assertEquals('LUKE MACGREGOR', $picture->getPhotographer()); $this->assertEquals('newsfeed', $picture->getSource()); $this->assertTrue($picture->isApproved()); $this->assertEquals(date_create('2011-12-06T13:32:23.000Z')->format('Y-m-d H:i'), $picture->getDate()->format('Y-m-d H:i')); $this->assertEquals('LONDON', $picture->getPlace()); }
/** * Get article entity * * @param int $articleNumber * @return Newscoop\Package\Article */ private function getArticle($articleNumber) { try { $article = $this->orm->getRepository('Newscoop\\Package\\Article')->findOneBy(array('id' => $articleNumber)); } catch (\Exception $e) { if ($e->getCode() === '42S02') { $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->orm); try { $schemaTool->createSchema(array($this->orm->getClassMetadata('Newscoop\\Package\\Article'))); } catch (\Exception $e) { } $article = null; } else { throw $e; } } if ($article === null) { $article = new Article($articleNumber); $this->orm->persist($article); $this->orm->flush($article); } return $article; }
/** * @param LoanApplication $application * @param $milestoneId * @param $milestoneGroupId * @return mixed */ public function setLoanMilestone(LoanApplication $application, $milestoneId, $milestoneGroupId) { try { $integrationSite = $this->losConnection->getSite(); //print_r('Site ID: '. $integrationSite->getId() . ' | Milestone ID: '. $milestoneId . ' | Milestone Group ID: ' . $milestoneGroupId); $newMilestone = $this->em->getRepository('SudouxMortgageBundle:LoanMilestone')->findOneMilestoneByLosId($integrationSite, $milestoneId, $milestoneGroupId); //print_r('Milestone Name: ' . $newMilestone->getName()); if (isset($newMilestone)) { // check for a change and send to the $currentMilestone = $application->getMilestone(); if (isset($currentMilestone)) { $sendNotifications = $application->getSite()->getSettings()->getInheritedSendMilestonesNotifications(); $user = $application->getUser(); if ($currentMilestone->getId() != $newMilestone->getId() && $sendNotifications && isset($user)) { if ($user->hasRole('ROLE_MEMBER')) { $email = new Email(); $email->setSubject("Your loan status has been updated"); $email->setMessage(sprintf("Your loan status for %s has been updated to %s.", $application->getPropertyLocation()->getAddress1(), $newMilestone->getName())); $email->setRecipient($user->getEmail()); $email->setSite($application->getSite()); $application->addEmail($email); $emailUtil = $this->container->get('sudoux.cms.message.email_util'); $emailUtil->logAndSend($email); } } } $application->setMilestone($newMilestone); $application->setMilestoneGroup($newMilestone->getMilestoneGroup()); } else { $e = new \Exception("Milestone not found for loan " . $application->getId()); $this->logger->crit($e->getMessage()); } } catch (\Exception $e) { $this->logger->crit($e->getMessage()); } }
public function getUser($login) { return $this->entityManager->getRepository("Model\\User")->findOneBy(array("login" => $login)); }
/** * @param Doctrine\ORM\EntityManager $orm */ public function __construct(\Doctrine\ORM\EntityManager $orm) { $this->orm = $orm; $this->repository = $this->orm->getRepository('Newscoop\\Package\\Package'); }
public function init() { $this->doctrine = Zend_Registry::get('doctrine'); $this->em = $this->doctrine->getEntityManager(); $this->_article = $this->em->getRepository('application\\models\\Article'); }
public function loadOneBy($entityClass, $criteria, $fetchMode) { $this->em->clear(); $this->setFetchMode($fetchMode); return $this->flextrinize($this->em->getRepository($entityClass)->findOneBy((array) $criteria)); }