public addFromReferences ( array $ids, integer $grouping ) | ||
$ids | array | |
$grouping | integer |
public function hydrate($data, $entity) { $key = $this->mapping['fieldname']; $vals = array_filter(explode(',', $data[$key])); $values = []; foreach ($vals as $fieldKey) { $split = explode('_', $fieldKey); $values[$split[0]][$split[1]][] = $split[2]; } $collection = new RepeatingFieldCollection($this->em, $this->mapping); $collection->setName($key); if (isset($values[$key]) && count($values[$key])) { foreach ($values[$key] as $group => $refs) { $collection->addFromReferences($refs, $group); } } $this->set($entity, $collection); }
public function hydrate($data, $entity) { $key = $this->mapping['fieldname']; if ($this->isJson($data[$key])) { $originalMapping[$key]['fields'] = $this->mapping['fields']; $originalMapping[$key]['type'] = 'repeater'; $mapping = $this->em->getMapper()->getRepeaterMapping($originalMapping); $decoded = json_decode($data[$key], true); $collection = new RepeatingFieldCollection($this->em, $mapping); $collection->setName($key); if (isset($decoded) && count($decoded)) { foreach ($decoded as $group => $repdata) { $collection->addFromArray($repdata, $group); } } $this->set($entity, $collection); return; } $vals = array_filter(explode(',', $data[$key])); $values = []; foreach ($vals as $fieldKey) { $split = explode('_', $fieldKey); $id = array_pop($split); $group = array_pop($split); $field = join('_', $split); $values[$field][$group][] = $id; } $collection = new RepeatingFieldCollection($this->em, $this->mapping); $collection->setName($key); if (isset($values[$key]) && count($values[$key])) { foreach ($values[$key] as $group => $refs) { $collection->addFromReferences($refs, $group); } } $this->set($entity, $collection); }
public function getRepeaters($content) { $ids = util::array_pluck($content, 'id'); if (empty($ids)) { return; } // Get the contenttype from first $content $contenttypeslug = $content[util::array_first_key($content)]->contenttype['slug']; $contenttype = $this->getContentType($contenttypeslug); $repo = $this->app['storage']->getRepository('Bolt\\Storage\\Entity\\FieldValue'); foreach ($ids as $id) { foreach ($contenttype['fields'] as $fieldkey => $field) { if ($field['type'] == 'repeater') { $collection = new RepeatingFieldCollection($this->app['storage'], $field); $existingFields = $repo->getExistingFields($id, $contenttypeslug, $fieldkey) ?: []; foreach ($existingFields as $group => $ids) { $collection->addFromReferences($ids, $group); } $content[$id]->setValue($fieldkey, $collection); } } } }