public function createRecordFromCMDL($cmdl, $properties = [], $viewName = "default", $workspace = "default", $language = "default")
 {
     $contentTypeDefinition = Parser::parseCMDLString($cmdl);
     /** @var Record $record */
     $record = new Record($contentTypeDefinition, '', $viewName, $workspace, $language);
     $revision = isset($jsonRecord['revision']) ? $jsonRecord['revision'] : 0;
     $record->setRevision($revision);
     if ($this->getOption('validateProperties') == true) {
         foreach ($properties as $property => $value) {
             $record->setProperty($property, $value);
         }
     } else {
         $record->setProperties($properties);
     }
     return $record;
 }
 /**
  * remove protected properties and execute @name annotation
  *
  * @param Record $record
  */
 protected function finalizeRecord(Record $record, DataDimensions $dataDimensions)
 {
     // Apply @name annotation
     if ($record->getDataTypeDefinition()->hasNamingPattern()) {
         $record->setName(Util::applyNamingPattern($record->getProperties(), $record->getDataTypeDefinition()->getNamingPattern()));
     }
     // remove protected properties
     $properties = $record->getProperties();
     foreach ($record->getDataTypeDefinition()->getProtectedProperties($dataDimensions->getViewName()) as $property) {
         unset($properties[$property]);
     }
     $record->setProperties($properties);
     return $record;
 }
 public function importXLSX(Repository $repository, $contentTypeName, $filename, $workspace = 'default', $language = 'default', $viewName = 'exchange')
 {
     $this->count = 0;
     $this->records = null;
     $this->stash = array();
     $this->error = false;
     $repository->selectContentType($contentTypeName);
     // Select view and fallback if necessary
     $contentTypeDefinition = $repository->getContentTypeDefinition();
     $viewDefinition = $contentTypeDefinition->getExchangeViewDefinition($viewName);
     $viewName = $viewDefinition->getName();
     $repository->selectWorkspace($workspace);
     $repository->selectLanguage($language);
     $repository->selectView($viewName);
     $objPHPExcel = \PHPExcel_IOFactory::load($filename);
     if ($objPHPExcel) {
         if ($this->isTruncateRecords()) {
             $this->deleteEffectiveRecords($repository, $workspace, $viewName, $language);
         }
         $objWorksheet = $objPHPExcel->getActiveSheet();
         $highestRow = $objWorksheet->getHighestRow();
         // e.g. 10
         $highestColumn = $objWorksheet->getHighestColumn();
         // e.g 'F'
         $highestColumnIndex = \PHPExcel_Cell::columnIndexFromString($highestColumn);
         // e.g. 5
         $idColumnIndex = null;
         $propertiesColumnIndices = array();
         for ($i = 0; $i <= $highestColumnIndex; $i++) {
             $value = trim($objWorksheet->getCellByColumnAndRow($i, 1)->getValue());
             if ($value != '') {
                 if (substr($value, 0, 1) == '.') {
                     if ($value == '.id') {
                         $idColumnIndex = $i;
                     }
                 } else {
                     $value = Util::generateValidIdentifier($value);
                     if ($contentTypeDefinition->hasProperty($value, $viewName)) {
                         $this->writeln('Detected valid property ' . $value);
                         $propertiesColumnIndices[$value] = $i;
                     }
                 }
             }
         }
         $this->writeln('');
         if (count($propertiesColumnIndices) != 0) {
             for ($row = 2; $row <= $highestRow; ++$row) {
                 $id = null;
                 if ($idColumnIndex !== null) {
                     if (!$this->isGenerateNewIDs()) {
                         $id = $objWorksheet->getCellByColumnAndRow($idColumnIndex, $row)->getValue();
                     }
                 }
                 $properties = array();
                 foreach ($propertiesColumnIndices as $property => $col) {
                     $value = $objWorksheet->getCellByColumnAndRow($col, $row)->getValue();
                     $properties[$property] = $value;
                 }
                 $record = new Record($contentTypeDefinition, 'Imported Record', $viewName, $workspace, $language);
                 $record->setProperties($properties);
                 $record->setID($id);
                 $msg = $this->stashRecord($repository, $record, $workspace, $viewName, $language);
                 $this->writeln($msg);
             }
             $this->writeln('');
             $this->writeln('Found ' . $this->count . ' records to import');
             $this->writeln('');
             if ($this->count != 0) {
                 $this->writeln('Starting bulk import');
                 $this->writeln('');
                 $this->saveRecords($repository);
                 $this->writeln('');
                 $this->writeln('');
             }
         } else {
             $this->writeln('Excel does not contain matching property columns.');
         }
     } else {
         $this->writeln('Error parsing Excel file.');
         $this->error = true;
     }
     return !$this->error;
 }