public function getUriConfig($configTypeName, DataDimensions $dataDimensions) { if ($this->hasConfigType($configTypeName)) { return $this->getContentArchiveFolder() . '/data/config/' . $configTypeName . '/' . $dataDimensions->getWorkspace() . '/' . $dataDimensions->getLanguage() . '/' . $configTypeName . '.json'; } throw new AnyContentClientException('Unknown config type ' . $configTypeName); }
protected function getOptionsForSelectBox() { if ($this->optionsForSelectBox) { return $this->optionsForSelectBox; } /** @var Repository $repository */ $repository = $this->app['context']->getCurrentRepository(); if ($this->definition->hasRepositoryName()) { /** @var RepositoryManager $repositoryManager */ $repositoryManager = $this->app['repos']; $repository = $repositoryManager->getRepositoryById($this->definition->getRepositoryName()); if (!$repository) { $this->app['context']->addAlertMessage('Could not find repository named ' . $this->definition->getRepositoryName()); } } $options = array(); if ($repository) { if ($repository->selectContentType($this->definition->getContentType())) { $contentTypeDefinition = $repository->getContentTypeDefinition(); $currentDataDimensions = $repository->getCurrentDataDimensions(); $workspace = $this->definition->getWorkspace(); $language = $this->definition->getLanguage(); $referenceDataDimensions = new DataDimensions(); $referenceDataDimensions->setWorkspace($workspace); $referenceDataDimensions->setLanguage($language); $referenceDataDimensions->setViewName($contentTypeDefinition->getListViewDefinition()->getName()); $referenceDataDimensions->setTimeShift($this->definition->getTimeShift()); $repository->setDataDimensions($referenceDataDimensions); $records = []; foreach ($repository->getRecords('', $this->definition->getOrder(), 1, null) as $record) { $records[$record->getId()] = $record->getName(); } /** @var RepositoryManager $repositoryManager */ $repositoryManager = $this->app['repos']; $accessHash = $repositoryManager->getAccessHash($repository, $contentTypeDefinition); $editUrl = '#'; if ($this->value != '') { $editUrl = $this->app->getUrlGenerator()->generate('editRecord', array('contentTypeAccessHash' => $accessHash, 'recordId' => $this->value, 'workspace' => $workspace, 'language' => $language)); } $this->vars['editUrl'] = $editUrl; $editUrlPattern = $this->app->getUrlGenerator()->generate('editRecord', array('contentTypeAccessHash' => $accessHash, 'recordId' => 'recordId', 'workspace' => $workspace, 'language' => $language)); $this->vars['editUrlPattern'] = $editUrlPattern; $repository->setDataDimensions($currentDataDimensions); foreach ($records as $id => $name) { $options[$id] = '#' . $id . ': ' . $name; } } else { $this->app['context']->addAlertMessage('Could not find referenced content type ' . $this->definition->getContentType() . '.'); } } $this->optionsForSelectBox = $options; return $this->optionsForSelectBox; }
public function __construct($id, $name, $formElementDefinition, $app, $value = '') { parent::__construct($id, $name, $formElementDefinition, $app, $value); $this->vars['type'] = $this->definition->getType(); /** @var Repository $repository */ $repository = $app['context']->getCurrentRepository(); if ($this->definition->hasRepositoryName()) { /** @var RepositoryManager $repositoryManager */ $repositoryManager = $this->app['repos']; $repository = $repositoryManager->getRepositoryById($this->definition->getRepositoryName()); if (!$repository) { $this->app['context']->addAlertMessage('Could not find repository named ' . $this->definition->getRepositoryName()); } } $options = array(); if ($repository->selectContentType($this->definition->getContentType())) { $contentTypeDefinition = $repository->getContentTypeDefinition(); $workspace = $this->definition->getWorkspace(); $language = $this->definition->getLanguage(); $timeshift = $this->definition->getTimeShift(); $order = $this->definition->getOrder(); $viewName = $contentTypeDefinition->getListViewDefinition()->getName(); $dataDimensions = new DataDimensions(); $dataDimensions->setWorkspace($workspace); $dataDimensions->setLanguage($language); $dataDimensions->setTimeShift($timeshift); $dataDimensions->setViewName($viewName); $records = $repository->getRecords('', $order, 1, null, $dataDimensions); foreach ($records as $record) { $options[$record->getId()] = '#' . $record->getId() . ' ' . $record->getName(); } } else { $app['context']->addAlertMessage('Could not find referenced content type ' . $this->definition->getContentType() . '.'); } $this->vars['options'] = $options; }
protected function createConfigFromRow($row, $configTypeName, DataDimensions $dataDimensions) { $definition = $this->getConfigTypeDefinition($configTypeName); $config = $this->getRecordFactory()->createConfig($definition, [], $dataDimensions->getViewName(), $dataDimensions->getWorkspace(), $dataDimensions->getLanguage()); $multiViewProperties = json_decode($row['properties'], true); $properties = []; foreach ($definition->getProperties($dataDimensions->getViewName()) as $property) { if (array_key_exists($property, $multiViewProperties)) { $properties[$property] = $multiViewProperties[$property]; } } $config->setProperties($properties); $config->setRevision($row['revision']); $userInfo = new UserInfo($row['lastchange_username'], $row['lastchange_firstname'], $row['lastchange_lastname'], $row['lastchange_timestamp']); $config->setLastChangeUserInfo($userInfo); return $config; }
/** * 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; }
protected function getLastModifedDateForConfigType($configTypeName, DataDimensions $dataDimensions) { $tableName = $this->getConfigTypeTableName(); $sql = 'SELECT MAX(validfrom_timestamp) AS T FROM ' . $tableName . ' WHERE id = ? AND workspace = ? AND language = ? '; $row = $this->getDatabase()->fetchOneSQL($sql, [$configTypeName, $dataDimensions->getWorkspace(), $dataDimensions->getLanguage()]); $t = $row['T']; $t = max($this->getCMDLLastModifiedDate(null, $configTypeName), $t); return $t; }
protected function requestRecords($contentTypeName, DataDimensions $dataDimensions, $filter, $page = 1, $count = null, $order = ['.id']) { $url = 'content/' . $contentTypeName . '/records/' . $dataDimensions->getWorkspace() . '/' . $dataDimensions->getViewName() . '?language=' . $dataDimensions->getLanguage() . '&view=' . $dataDimensions->getViewName() . '×hift=' . $dataDimensions->getTimeShift(); if ($count != null) { $url .= '&page=' . $page . '&limit=' . $count; } if ($filter) { // V1 compatibility $filter = str_replace('*=', '><', (string) $filter); $url .= '&filter=' . urlencode($filter); } // V1 compatibility - multi sort is not possible $map = ['.id' => 'id', '.id-' => 'id', 'position' => 'pos', 'position-' => 'pos-', '.info.creation.timestamp' => 'creation', '.info.creation.timestamp-' => 'creation-', '.info.lastchange.timestamp' => 'change', '.info.lastchange.timestamp-' => 'change-']; if (is_array($order)) { $order = reset($order); if (array_key_exists($order, $map)) { $order = $map[$order]; } } $url .= '&order=' . $order; $response = $this->getClient()->get($url); $json = $response->json(); $records = $this->getRecordFactory()->createRecordsFromJSONRecordsArray($this->getContentTypeDefinition($contentTypeName), $json['records']); return $records; }