createQueryBuilder() public method

public createQueryBuilder ( ) : Doctrine\DBAL\Query\QueryBuilder
return Doctrine\DBAL\Query\QueryBuilder
Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function persist(QuerySet $queries, $entity, EntityManager $em = null)
 {
     $field = $this->mapping['fieldname'];
     $target = $this->mapping['target'];
     $accessor = "get" . $field;
     $taxonomy = (array) $entity->{$accessor}();
     // Fetch existing relations
     $existingQuery = $em->createQueryBuilder()->select('*')->from($target)->where('content_id = ?')->andWhere('contenttype = ?')->andWhere('taxonomytype = ?')->setParameter(0, $entity->id)->setParameter(1, $entity->getContenttype())->setParameter(2, $field);
     $result = $existingQuery->execute()->fetchAll();
     $existing = array_map(function ($el) {
         return $el['slug'];
     }, $result);
     $proposed = $taxonomy;
     $toInsert = array_diff($proposed, $existing);
     $toDelete = array_diff($existing, $proposed);
     foreach ($toInsert as $item) {
         $ins = $em->createQueryBuilder()->insert($target);
         $ins->values(['content_id' => '?', 'contenttype' => '?', 'taxonomytype' => '?', 'slug' => '?', 'name' => '?'])->setParameters([0 => $entity->id, 1 => $entity->getContenttype(), 2 => $field, 3 => $item, 4 => $this->mapping['data']['options'][$item]]);
         $queries->append($ins);
     }
     foreach ($toDelete as $item) {
         $del = $em->createQueryBuilder()->delete($target);
         $del->where('content_id=?')->andWhere('contenttype=?')->andWhere('taxonomytype=?')->andWhere('slug=?')->setParameters([0 => $entity->id, 1 => $entity->getContenttype(), 2 => $field, 3 => $item]);
         $queries->append($del);
     }
 }
Esempio n. 2
0
 public function testCreateQueryBuilder()
 {
     $app = $this->getApp();
     $em = new EntityManager($app['db'], $app['dispatcher'], $app['storage.metadata']);
     $qb = $em->createQueryBuilder();
     $this->assertInstanceOf('Doctrine\\DBAL\\Query\\QueryBuilder', $qb);
 }
Esempio n. 3
0
 public function __construct(array $mapping = [], EntityManager $em = null)
 {
     $this->mapping = $mapping;
     $this->em = $em;
     if ($em) {
         $this->setPlatform($em->createQueryBuilder()->getConnection()->getDatabasePlatform());
     }
 }
Esempio n. 4
0
 /**
  * @inheritdoc
  */
 public function hydrate($data, $entity, EntityManager $em = null)
 {
     $key = $this->mapping['fieldname'];
     $type = $this->getStorageType();
     $val = $data[$key];
     $value = $type->convertToPHPValue($val, $em->createQueryBuilder()->getConnection()->getDatabasePlatform());
     $entity->{$key} = $value;
 }
Esempio n. 5
0
 /**
  * Updates an object into the database.
  *
  * @param object $entity The entity to update.
  *
  * @return bool
  */
 public function update($entity)
 {
     $querySet = new QuerySet();
     $qb = $this->em->createQueryBuilder();
     $qb->update($this->getTableName())->where('id = :id')->setParameter('id', $entity->getId());
     $querySet->append($qb);
     $this->persister->persist($querySet, $entity, $this->em);
     return $querySet->execute();
 }