Exemple #1
0
 /**
  * @inheritdoc
  */
 public function load(QueryBuilder $query, ClassMetadata $metadata)
 {
     $field = $this->mapping['fieldname'];
     $target = $this->mapping['target'];
     $boltname = $metadata->getBoltName();
     $query->addSelect($this->getPlatformGroupConcat("{$field}.to_id", $field, $query))->leftJoin('content', $target, $field, "content.id = {$field}.from_id AND {$field}.from_contenttype='{$boltname}' AND {$field}.to_contenttype='{$field}'")->addGroupBy("content.id");
 }
Exemple #2
0
 /**
  * Initializes a new Repository.
  *
  * @param EntityManager  $em            The EntityManager to use.
  * @param ClassMetadata  $classMetadata The class descriptor.
  * @param Hydrator|null  $hydrator
  * @param Persister|null $persister
  * @param Loader|null    $loader
  */
 public function __construct($em, ClassMetadata $classMetadata, $hydrator = null, $persister = null, $loader = null)
 {
     $this->em = $em;
     $this->_class = $classMetadata;
     $this->entityName = $classMetadata->getName();
     $this->setHydrator($hydrator ?: new Hydrator($classMetadata));
     $this->setPersister($persister ?: new Persister($classMetadata));
     $this->setLoader($loader ?: new Loader());
 }
Exemple #3
0
 /**
  * @param QueryInterface $query
  * @param ClassMetadata  $metadata
  *
  * @return QueryInterface
  */
 public function query(QueryInterface $query, ClassMetadata $metadata)
 {
     foreach ($metadata->getFieldMappings() as $field) {
         /** @var FieldTypeInterface $fieldtype */
         $fieldtype = new $field['fieldtype']($field);
         $fieldtype->query($query, $metadata);
     }
     return $query;
 }
Exemple #4
0
 /**
  * @param QueryBuilder  $qb
  * @param ClassMetadata $metadata
  *
  * @return QueryBuilder
  */
 public function load(QueryBuilder $qb, ClassMetadata $metadata)
 {
     foreach ($metadata->getFieldMappings() as $field) {
         /** @var FieldTypeInterface $fieldtype */
         $fieldtype = new $field['fieldtype']($field);
         $fieldtype->load($qb, $metadata);
     }
     return $qb;
 }
Exemple #5
0
 /**
  * @inheritdoc
  */
 public function load(QueryBuilder $query, ClassMetadata $metadata)
 {
     $field = $this->mapping['fieldname'];
     $boltname = $metadata->getBoltName();
     if ($this->mapping['data']['has_sortorder']) {
         $order = "{$field}.sortorder";
     } else {
         $order = "{$field}.id";
     }
     $query->addSelect($this->getPlatformGroupConcat("{$field}.slug", $order, $field, $query))->leftJoin('content', 'bolt_taxonomy', $field, "content.id = {$field}.content_id AND {$field}.contenttype='{$boltname}' AND {$field}.taxonomytype='{$field}'")->addGroupBy("content.id");
 }
Exemple #6
0
 /**
  * For repeating fields, the load method adds extra joins and selects to the query that
  * fetches the related records from the field and field value tables in the same query as the content fetch.
  *
  * @param QueryBuilder  $query
  * @param ClassMetadata $metadata
  *
  * @return void
  */
 public function load(QueryBuilder $query, ClassMetadata $metadata)
 {
     $field = $this->mapping['fieldname'];
     $boltname = $metadata->getBoltName();
     $from = $query->getQueryPart('from');
     if (isset($from[0]['alias'])) {
         $alias = $from[0]['alias'];
     } else {
         $alias = $from[0]['table'];
     }
     $query->addSelect($this->getPlatformGroupConcat('fields', $query))->leftJoin($alias, $this->mapping['tables']['field_value'], 'f', "f.content_id = {$alias}.id AND f.contenttype='{$boltname}' AND f.name='{$field}'");
 }
Exemple #7
0
 /**
  * For relations, the load method adds an extra ->addSelect() and ->leftJoin() to the query that
  * fetches the related records from the join table in the same query as the content fetch.
  *
  * IDs are returned comma-separated which the ->hydrate() method can then turn into pointers
  * to the related entities.
  *
  * @param QueryBuilder  $query
  * @param ClassMetadata $metadata
  */
 public function load(QueryBuilder $query, ClassMetadata $metadata)
 {
     $field = $this->mapping['fieldname'];
     $target = $this->mapping['target'];
     $boltname = $metadata->getBoltName();
     $from = $query->getQueryPart('from');
     if (isset($from[0]['alias'])) {
         $alias = $from[0]['alias'];
     } else {
         $alias = $from[0]['table'];
     }
     $query->addSelect($this->getPlatformGroupConcat("{$field}.to_id", $field, $query))->leftJoin($alias, $target, $field, "{$alias}.id = {$field}.from_id AND {$field}.from_contenttype='{$boltname}' AND {$field}.to_contenttype='{$field}'")->addGroupBy("{$alias}.id");
 }
Exemple #8
0
 /**
  * @param array         $source data
  * @param QueryBuilder  $qb
  * @param EntityManager $em
  *
  * @return mixed Entity
  */
 public function hydrate(array $source, QueryBuilder $qb, EntityManager $em = null)
 {
     $classname = $this->handler;
     $entity = new $classname();
     $entity->setContenttype($this->metadata->getBoltName());
     foreach ($this->metadata->getFieldMappings() as $key => $mapping) {
         // First step is to allow each Bolt field to transform the data.
         /** @var FieldTypeInterface $field */
         $field = new $mapping['fieldtype']($mapping);
         $field->hydrate($source, $entity, $em);
     }
     return $entity;
 }
Exemple #9
0
 protected function buildMetadata($entity, $rawData = null)
 {
     $template = $this->chooser->record($entity, $rawData);
     $metadata = new ClassMetadata(get_class($entity));
     if (isset($this->mapping['config'][$template])) {
         $mappings = $this->em->getMapper()->loadMetadataForFields($this->mapping['config'][$template]['fields']);
         $metadata->setFieldMappings((array) $mappings);
     }
     return $metadata;
 }
Exemple #10
0
 /**
  * For the taxonomy field the load event modifies the query to fetch taxonomies related
  * to a content record from the join table.
  *
  * It does this via an additional ->addSelect() and ->leftJoin() call on the QueryBuilder
  * which includes then includes the taxonomies in the same query as the content fetch.
  *
  * @param QueryBuilder  $query
  * @param ClassMetadata $metadata
  */
 public function load(QueryBuilder $query, ClassMetadata $metadata)
 {
     $field = $this->mapping['fieldname'];
     $target = $this->mapping['target'];
     $boltname = $metadata->getBoltName();
     if ($this->mapping['data']['has_sortorder']) {
         $order = "{$field}.sortorder";
         $query->addSelect("{$field}.sortorder as " . $field . '_sortorder');
     } else {
         $order = "{$field}.id";
     }
     $from = $query->getQueryPart('from');
     if (isset($from[0]['alias'])) {
         $alias = $from[0]['alias'];
     } else {
         $alias = $from[0]['table'];
     }
     $query->addSelect($this->getPlatformGroupConcat("{$field}.slug", $order, $field . '_slugs', $query))->addSelect($this->getPlatformGroupConcat("{$field}.name", $order, $field, $query))->leftJoin($alias, $target, $field, "{$alias}.id = {$field}.content_id AND {$field}.contenttype='{$boltname}' AND {$field}.taxonomytype='{$field}'")->addGroupBy("{$alias}.id");
 }
Exemple #11
0
 /**
  * {@inheritdoc}
  */
 public function loadMetadataForClass($className, ClassMetadata $metadata = null)
 {
     if (null === $metadata) {
         $fullClassName = $this->resolveClassName($className);
         $metadata = new BoltClassMetadata($fullClassName, $this->namingStrategy);
     }
     if (!$this->initialized) {
         $this->initialize();
     }
     if (array_key_exists($className, $this->metadata)) {
         $data = $this->metadata[$className];
         $metadata->setTableName($data['table']);
         $metadata->setIdentifier($data['identifier']);
         $metadata->setFieldMappings($data['fields']);
         $metadata->setBoltName($data['boltname']);
         return $metadata;
     } else {
         throw new \Exception("Attempted to load mapping data for unmapped class {$className}");
     }
 }
Exemple #12
0
 /**
  * Initializes a new Repository.
  *
  * @param EntityManager $em            The EntityManager to use.
  * @param ClassMetadata $classMetadata The class descriptor.
  */
 public function __construct($em, ClassMetadata $classMetadata)
 {
     $this->em = $em;
     $this->_class = $classMetadata;
     $this->entityName = $classMetadata->getName();
 }