eZ\Publish\Core\Persistence\Legacy\Content\Type\Mapper::extractTypesFromRows PHP Method

extractTypesFromRows() public method

Extracts types and related data from the given $rows.
public extractTypesFromRows ( array $rows ) : array(Type)
$rows array
return array(Type)
    public function extractTypesFromRows(array $rows)
    {
        $types = array();
        $fields = array();
        foreach ($rows as $row) {
            $typeId = (int) $row['ezcontentclass_id'];
            if (!isset($types[$typeId])) {
                $types[$typeId] = $this->extractTypeFromRow($row);
            }
            $fieldId = (int) $row['ezcontentclass_attribute_id'];
            if ($fieldId && !isset($fields[$fieldId])) {
                $types[$typeId]->fieldDefinitions[] = $fields[$fieldId] = $this->extractFieldFromRow($row);
            }
            $groupId = (int) $row['ezcontentclass_classgroup_group_id'];
            if (!in_array($groupId, $types[$typeId]->groupIds)) {
                $types[$typeId]->groupIds[] = $groupId;
            }
        }
        // Re-index $types to avoid people relying on ID keys
        return array_values($types);
    }

Usage Example

 /**
  * Loads a single Type from $rows
  *
  * @param array $rows
  * @param mixed $typeIdentifier
  * @param int $status
  *
  * @return \eZ\Publish\SPI\Persistence\Content\Type
  */
 protected function loadFromRows(array $rows, $typeIdentifier, $status)
 {
     $types = $this->mapper->extractTypesFromRows($rows);
     if (count($types) !== 1) {
         throw new Exception\TypeNotFound($typeIdentifier, $status);
     }
     return $types[0];
 }