public function exportXLSX(Repository $repository, $contentTypeName, $workspace = 'default', $language = 'default', $viewName = 'exchange')
 {
     $repository->selectContentType($contentTypeName);
     // Select view and fallback if necessary
     $contentTypeDefinition = $repository->getContentTypeDefinition();
     $viewDefinition = $contentTypeDefinition->getExchangeViewDefinition($viewName);
     $viewName = $viewDefinition->getName();
     $this->writeln('Connecting repository');
     $this->writeln('');
     $repository->selectWorkspace($workspace);
     $repository->selectLanguage($language);
     $repository->selectView($viewName);
     /** @var Record[] $records */
     $records = $repository->getRecords('', '.id', 1);
     if ($records !== false) {
         // Create new PHPExcel object
         $objPHPExcel = new \PHPExcel();
         // use temp folder for processing of large files
         $cacheMethod = \PHPExcel_CachedObjectStorageFactory::cache_to_phpTemp;
         $cacheSettings = array('memoryCacheSize' => '12MB');
         \PHPExcel_Settings::setCacheStorageMethod($cacheMethod, $cacheSettings);
         // Set document properties
         $objPHPExcel->getProperties()->setCreator("AnyContent CMCK")->setLastModifiedBy("AnyContent CMCK")->setTitle("Full Export from content type " . $contentTypeDefinition->getTitle())->setSubject("AnyContent Export")->setDescription("");
         $worksheet = $objPHPExcel->setActiveSheetIndex(0);
         $worksheet->setTitle('Export');
         $worksheet->setCellValueByColumnAndRow(0, 1, '.id');
         $worksheet->getStyleByColumnAndRow(0, 1)->getFont()->setBold(false)->setItalic(true);
         $worksheet->setCellValueByColumnAndRow(1, 1, '.revision');
         $worksheet->getStyleByColumnAndRow(1, 1)->getFont()->setBold(false)->setItalic(true);
         $row = 1;
         $column = 2;
         foreach ($contentTypeDefinition->getProperties($viewName) as $property) {
             $worksheet->setCellValueByColumnAndRow($column, $row, $property);
             $worksheet->getStyleByColumnAndRow($column, $row)->getFont()->setBold(true);
             $worksheet->getColumnDimensionByColumn($column)->setWidth(20);
             $column++;
         }
         $row++;
         foreach ($records as $record) {
             $this->writeln('Processing record ' . $record->getID() . ' - ' . $record->getName());
             $worksheet->setCellValueByColumnAndRow(0, $row, $record->getID());
             $worksheet->setCellValueByColumnAndRow(1, $row, $record->getRevision());
             $column = 2;
             foreach ($contentTypeDefinition->getProperties($viewName) as $property) {
                 $worksheet->setCellValueByColumnAndRow($column, $row, $record->getProperty($property));
                 $column++;
             }
             $row++;
         }
         $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
         ob_start();
         $objWriter->save('php://output');
         $excelOutput = ob_get_clean();
         return $excelOutput;
     }
     return false;
 }
 public function testRecordCanAccessRepository()
 {
     $repository = new Repository('phpunit', $this->connection);
     $repository->selectContentType('example01');
     $definition = $repository->getContentTypeDefinition();
     $records = [];
     for ($i = 1; $i <= 5; $i++) {
         $record = new Record($definition, 'Test ' . $i);
         $records[] = $record;
     }
     $repository->saveRecords($records);
     $record = $repository->getRecord(1);
     $this->assertInstanceOf('AnyContent\\Client\\Repository', $record->getRepository());
     $records = $repository->getRecords();
     $record = array_shift($records);
     $this->assertInstanceOf('AnyContent\\Client\\Repository', $record->getRepository());
 }
 protected static function getDataTypeDefinition(Application $app, Repository $repository, $dataType, $dataTypeAccessHash)
 {
     /** @var RepositoryManager $repositoryManager */
     $repositoryManager = $app['repos'];
     if ($repository) {
         if ($dataType == 'content') {
             /** @var ContentTypeDefinition $dataTypeDefinition */
             $dataTypeDefinition = $repository->getContentTypeDefinition();
             $app['context']->setCurrentContentType($dataTypeDefinition);
         } else {
             /** @var ConfigTypeDefinition $dataTypeDefinition */
             $dataTypeDefinition = $repositoryManager->getConfigTypeDefinitionByConfigTypeAccessHash($dataTypeAccessHash);
             $app['context']->setCurrentConfigType($dataTypeDefinition);
         }
         return $dataTypeDefinition;
     }
     return false;
 }
 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;
 }