/** * @param ServiceManager $serviceManager * @return Form */ public function setServiceManager(ServiceManager $serviceManager) { $this->serviceManager = $serviceManager; $this->entityManager = $serviceManager->get('doctrine.entitymanager.orm_default'); $this->queryBuilder = $this->entityManager->createQueryBuilder(); return $this; }
/** * 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); }
/** * @see \PHPUnit_Framework_TestCase::tearDown() */ protected function tearDown() { $this->entityManager->getConnection()->rollback(); // Shutdown the kernel. $this->kernel->shutdown(); parent::tearDown(); }
public function registraContacto(ContactoDTO $to) { $contacto = new Contacto($to->getId()); $contacto->setNombre($to->getNombre()); $contacto->setApellido($to->getApellido()); $contacto->setTelefono($to->getTelefono()); $contacto->setAsunto($to->getAsunto()); $contacto->setMensaje($to->getMensaje()); $contacto; try { $this->em->persist($contacto); $this->em->flush(); } catch (ORMInvalidArgumentException $exc) { echo '<pre>'; print_r($exc->getTraceAsString()); } catch (\Doctrine\ORM\ORMException $exc) { echo '<pre>'; print_r($exc->getTraceAsString()); echo '<pre>'; print_r($exc->getTrace()); } catch (Exception $e) { echo '<pre>'; print_r($e->getTraceAsString()); } //return $contacto->getIdContact(); }
public function testMetadata() { $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\SoftDeleteable'); $config = $this->softDeleteable->getConfiguration($this->em, $meta->name); $this->assertArrayHasKey('softDeleteable', $config); $this->assertTrue($config['softDeleteable']); $this->assertArrayHasKey('fieldName', $config); $this->assertEquals('deletedAt', $config['fieldName']); }
/** * * @param Doctrine\ORM\EntityManager $em * @param string $entityName * @param OutputInterface $output * @return integer */ private function countSaveEntity($em, $entityName, $output) { $output->write("<info>Counting " . $entityName . "</info> "); $count = $em->createQueryBuilder()->select('count(entity.id)')->from($entityName, 'entity')->getQuery()->getSingleScalarResult(); $output->writeln(" <info> Result : " . $count . "</info>"); $output->writeln("<info>Saving count result to OjsJournalBundle:Sums"); $this->saveSum($em, $entityName, $count); return $count; }
public function delete($id) { try { $modalidade = $this->find_by($id); $this->em->remove($modalidade); } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - modalidade_dao::delete '); } }
public function testCheckInvalidDate() { $token = new UserToken($this->user, 'test', 'qwerty'); $this->em->persist($token); $this->em->flush(); $property = new \ReflectionProperty($token, 'created'); $property->setAccessible(true); $property->setValue($token, new \DateTime('-3 days')); $this->assertFalse($this->service->checkToken($this->user, 'qwerty', 'test')); }
public function testFind() { foreach (array('tic', 'tic tac', 'tac', 'tac toc', 'toc') as $description) { $image = new LocalImage($description); $image->setDescription($description); $this->orm->persist($image); } $this->orm->flush(); $this->assertEquals(2, count($this->service->find('tic'))); }
public function insert(\Entity\Voluntario $voluntario) { try { $this->em->persist($voluntario); $this->em->flush(); return true; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - voluntario_dao::insert '); } return false; }
public function delete($id) { try { $categoria = $this->find_by($id); $this->em->remove($categoria); return true; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - categoria_dao::delete '); } return false; }
public function testTreeMetadata() { $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\ClosureTree'); $config = $this->tree->getConfiguration($this->em, $meta->name); $this->assertArrayHasKey('strategy', $config); $this->assertEquals('closure', $config['strategy']); $this->assertArrayHasKey('closure', $config); $this->assertEquals('Mapping\\Fixture\\ClosureTreeClosure', $config['closure']); $this->assertArrayHasKey('parent', $config); $this->assertEquals('parent', $config['parent']); }
public function insert(\Entity\Avaliador $avaliador) { try { $this->em->persist($avaliador); $this->em->flush(); return true; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - avaliador_dao::insert '); } return false; }
public function insert(\Entity\Ouvinte $ouvinte) { try { $this->em->persist($ouvinte); $this->em->flush(); return true; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - ouvinte_dao::insert '); } return false; }
public function testFindBy() { $result = array(1, 2, 4); $criteria = array('resource' => 'article'); $orderBy = array('created'); $limit = 5; $offset = 1; $this->repository->expects($this->once())->method('findBy')->with($this->equalTo($criteria), $this->equalTo($orderBy), $this->equalTo($limit), $this->equalTo($offset))->will($this->returnValue($result)); $this->em->expects($this->once())->method('getRepository')->with($this->equalTo('Newscoop\\Entity\\AuditEvent'))->will($this->returnValue($this->repository)); $this->assertEquals($result, $this->service->findBy($criteria, $orderBy, $limit, $offset)); }
/** * Add addtional Jobs so we can test record limits and pagers. * * @param Doctrine\ORM\EntityManager $manager * @param Job $job */ protected function duplicateLastJob($manager, $job) { for ($i = 100; $i <= 130; $i++) { $jobClone = clone $job; $jobClone->setCompany(sprintf($job->getCompany(), $i)); $jobClone->setHowToApply(sprintf($job->getHowToApply(), $i)); $jobClone->setToken(sprintf($job->getToken(), $i)); $manager->persist($jobClone); $manager->flush(); } }
private function loadBaseInventory() { foreach (self::$inventoryArray as $inventoryArray) { $item = new Inventory(); $item->setItemDescription($inventoryArray['description']); $item->setItemName($inventoryArray['name']); $item->setPrice($inventoryArray['price']); $item->setQuantityInStock($inventoryArray['quantity']); $this->em->persist($item); } $this->em->flush(); }
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 testSluggableMetadata() { $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Sortable'); $config = $this->sortable->getConfiguration($this->em, $meta->name); $this->assertArrayHasKey('position', $config); $this->assertEquals('position', $config['position']); $this->assertArrayHasKey('groups', $config); $this->assertCount(3, $config['groups']); $this->assertEquals('grouping', $config['groups'][0]); $this->assertEquals('sortable_group', $config['groups'][1]); $this->assertEquals('sortable_groups', $config['groups'][2]); }
public function getCatStatusNewsletter() { $status = new \calavera\customerBundle\Entity\CatNewsletterStatus(); $dql = "select u from \\calavera\\customerBundle\\Entity\\CatNewsletterStatus u where u.status = 'subscribed'"; try { $query = $this->em->createQuery($dql); $status = $query->getOneOrNullResult(); } catch (\Doctrine\ORM\NoResultException $orme) { } catch (\Exception $e) { } return $status; }
public function testLoggableMetadata() { $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Loggable'); $config = $this->loggable->getConfiguration($this->em, $meta->name); $this->assertArrayHasKey('logEntryClass', $config); $this->assertEquals('Gedmo\\Loggable\\Entity\\LogEntry', $config['logEntryClass']); $this->assertArrayHasKey('loggable', $config); $this->assertEquals(true, $config['loggable']); $this->assertArrayHasKey('versioned', $config); $this->assertEquals(2, count($config['versioned'])); $this->assertTrue(in_array('title', $config['versioned'])); $this->assertTrue(in_array('status', $config['versioned'])); }
public function testTranslatableMetadata() { $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Translatable'); $config = $this->translatable->getConfiguration($this->em, $meta->name); $this->assertArrayHasKey('translationClass', $config); $this->assertEquals('Gedmo\\Translatable\\Entity\\Translation', $config['translationClass']); $this->assertArrayHasKey('locale', $config); $this->assertEquals('locale', $config['locale']); $this->assertArrayHasKey('fields', $config); $this->assertCount(2, $config['fields']); $this->assertTrue(in_array('title', $config['fields'])); $this->assertTrue(in_array('content', $config['fields'])); }
public function testTimestampableMetadata() { $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\Timestampable'); $config = $this->timestampable->getConfiguration($this->em, $meta->name); $this->assertArrayHasKey('create', $config); $this->assertEquals('created', $config['create'][0]); $this->assertArrayHasKey('update', $config); $this->assertEquals('updated', $config['update'][0]); $this->assertArrayHasKey('change', $config); $onChange = $config['change'][0]; $this->assertEquals('published', $onChange['field']); $this->assertEquals('status.title', $onChange['trackedField']); $this->assertEquals('Published', $onChange['value']); }
public function delete($id) { try { $curso = $this->find_one_by($id); if ($curso) { $this->em->remove($curso); $this->em->flush(); } return true; } catch (Exception $ex) { $this->CI->log->write_log('error', $ex->getMessage() . ' - curso_dao::delete '); } return false; }
public function testTwoSameManagers() { $em1Article = new \Sluggable\Fixture\Article(); $em1Article->setCode('code'); $em1Article->setTitle('title'); $this->em1->persist($em1Article); $this->em1->flush(); $this->assertEquals('title-code', $em1Article->getSlug()); $user = new \Mapping\Fixture\Yaml\User(); $user->setUsername('user'); $user->setPassword('secret'); $this->em2->persist($user); $this->em2->flush(); $this->assertEquals(1, $user->getId()); }
/** * Get rendition * * @param int $width * @param int $height * @param string $specs * @param string $name * @return Newscoop\Image\Rendition */ private function getRendition($width, $height, $specs, $name) { $rendition = new Rendition($width, $height, $specs, $name); $this->orm->persist($rendition); $this->orm->flush($rendition); return $rendition; }
/** * 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; }
/** * @param ClassMetadata $class * @param array $entityData * @param string $revType */ private function saveRevisionEntityData($class, $entityData, $revType) { $params = array($this->getRevisionId(), $revType); $types = array(\PDO::PARAM_INT, \PDO::PARAM_STR); foreach ($class->fieldNames as $field) { $params[] = $entityData[$field]; $types[] = $class->fieldMappings[$field]['type']; } foreach ($class->associationMappings as $field => $assoc) { if (($assoc['type'] & ClassMetadata::TO_ONE) > 0 && $assoc['isOwningSide']) { $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); if ($entityData[$field] !== null) { $relatedId = $this->uow->getEntityIdentifier($entityData[$field]); } $targetClass = $this->em->getClassMetadata($assoc['targetEntity']); foreach ($assoc['sourceToTargetKeyColumns'] as $sourceColumn => $targetColumn) { if ($entityData[$field] === null) { $params[] = null; $types[] = \PDO::PARAM_STR; } else { $params[] = $relatedId[$targetClass->fieldNames[$targetColumn]]; $types[] = $targetClass->getTypeOfColumn($targetColumn); } } } } $this->conn->executeUpdate($this->getInsertRevisionSQL($class), $params, $types); }
public function flush($remoteOperations = null, $fetchMode = null) { // If $remoteOperations is null, flush() has been called from a server-side method so we don't want to clear the em if ($remoteOperations) { $this->em->clear(); } // Start the transaction $this->em->getConnection()->beginTransaction(); try { // Perform the flush $flushExecutor = new FlushExecutor($this->em, $remoteOperations, $this->deserializationWalker); $changeSets = $flushExecutor->flush(); // Go through the elements in the change sets making the entities Flextrine ready (apart from temporaryUidMap and entityDeletionIdMap which are not entities) if ($fetchMode) { $this->setFetchMode($fetchMode); } foreach ($changeSets as $changeSetType => $changeSet) { if ($changeSetType != "temporaryUidMap" && $changeSetType != "entityDeletionIdMap") { foreach ($changeSet as $oid => $entity) { $changeSet[$oid] = $this->flextrinize($entity); } } } // Commit the transaction $this->em->getConnection()->commit(); // Return the change sets so they can be replicated in Flextrine return $changeSets; } catch (\Exception $e) { $this->em->getConnection()->rollback(); $this->em->close(); throw $e; } }
public function testTreeMetadata() { $meta = $this->em->getClassMetadata('Mapping\\Fixture\\Xml\\NestedTree'); $config = $this->tree->getConfiguration($this->em, $meta->name); $this->assertArrayHasKey('strategy', $config); $this->assertEquals('nested', $config['strategy']); $this->assertArrayHasKey('left', $config); $this->assertEquals('left', $config['left']); $this->assertArrayHasKey('right', $config); $this->assertEquals('right', $config['right']); $this->assertArrayHasKey('level', $config); $this->assertEquals('level', $config['level']); $this->assertArrayHasKey('root', $config); $this->assertEquals('root', $config['root']); $this->assertArrayHasKey('parent', $config); $this->assertEquals('parent', $config['parent']); }