Ejemplo n.º 1
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;
 }
Ejemplo n.º 2
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");
 }
Ejemplo n.º 3
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");
 }
Ejemplo n.º 4
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}'");
 }
Ejemplo n.º 5
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");
 }
Ejemplo n.º 6
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");
 }