public static function sortRecords(Application $app, Request $request, $contentTypeAccessHash)
 {
     $vars = array();
     /** @var Repository $repository */
     $repository = $app['repos']->getRepositoryByContentTypeAccessHash($contentTypeAccessHash);
     $app['context']->setCurrentRepository($repository);
     $vars['repository'] = $repository;
     $repositoryAccessHash = $app['repos']->getRepositoryAccessHash($repository);
     $vars['links']['repository'] = $app['url_generator']->generate('indexRepository', array('repositoryAccessHash' => $repositoryAccessHash));
     $contentTypeDefinition = $repository->getContentTypeDefinition();
     $app['context']->setCurrentContentType($contentTypeDefinition);
     $vars['definition'] = $contentTypeDefinition;
     $vars['menu_mainmenu'] = $app['menus']->renderMainMenu();
     $buttons = array();
     $buttons[100] = array('label' => 'List Records', 'url' => $app['url_generator']->generate('listRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => $app['context']->getCurrentListingPage())), 'glyphicon' => 'glyphicon-list');
     $vars['buttons'] = $app['menus']->renderButtonGroup($buttons);
     $vars['links']['search'] = $app['url_generator']->generate('listRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => 1, 's' => 'name'));
     // context links
     $vars['links']['timeshift'] = $app['url_generator']->generate('timeShiftSortRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => 1));
     $vars['links']['workspaces'] = $app['url_generator']->generate('changeWorkspaceSortRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => 1));
     $vars['links']['languages'] = $app['url_generator']->generate('changeLanguageSortRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => 1));
     $vars['links']['reset'] = $app['url_generator']->generate('listRecordsReset', array('contentTypeAccessHash' => $contentTypeAccessHash));
     $vars['links']['sort'] = $app['url_generator']->generate('postSortRecords', array('contentTypeAccessHash' => $contentTypeAccessHash));
     // set workspace, language and timeshift of repository object to make sure content views are accessing the right content dimensions
     $repository->selectWorkspace($app['context']->getCurrentWorkspace());
     $repository->selectLanguage($app['context']->getCurrentLanguage());
     $repository->setTimeshift($app['context']->getCurrentTimeShift());
     $vars['records_left'] = $repository->getSortedRecords(0);
     $vars['records_right'] = array_diff_key($repository->getRecords(), $vars['records_left']);
     return $app->renderPage('sort-tree.twig', $vars);
 }
 public function init(Application $app, $options = array())
 {
     $app->addTemplatesFolders(__DIR__ . '/views/');
     // additional query parameter insertedby
     $app->get('/sequence/edit/{dataType}/{dataTypeAccessHash}/{viewName}/{insertName}/{recordId}/{property}', 'AnyContent\\CMCK\\Modules\\Backend\\Edit\\SequenceFormElement\\Controller::editSequence')->bind('editSequence');
     $app->post('/sequence/edit/{dataType}/{dataTypeAccessHash}/{viewName}/{insertName}/{recordId}/{property}', 'AnyContent\\CMCK\\Modules\\Backend\\Edit\\SequenceFormElement\\Controller::postSequence')->bind('postSequence');
     // additional query parameter insert and count
     $app->get('/sequence/add/{dataType}/{dataTypeAccessHash}/{viewName}/{insertName}/{property}', 'AnyContent\\CMCK\\Modules\\Backend\\Edit\\SequenceFormElement\\Controller::addSequenceItem')->bind('addSequenceItem');
 }
 public static function adminEditConfigType(Application $app, $configTypeAccessHash)
 {
     $vars = array();
     $vars['menu_mainmenu'] = $app['menus']->renderMainMenu();
     $vars['links']['home'] = $app['url_generator']->generate('index');
     $vars['links']['admin'] = $app['url_generator']->generate('admin');
     $vars['links']['delete'] = $app['url_generator']->generate('adminDeleteConfigType', array('configTypeAccessHash' => $configTypeAccessHash));
     /** @var Repository $repository */
     $repository = $app['repos']->getRepositoryByConfigTypeAccessHash($configTypeAccessHash);
     if ($repository) {
         $app['layout']->addJsFile('admin.js');
         $vars['record'] = false;
         $configTypeDefinition = $repository->getConfigTypeDefinition();
         $cmdl = $configTypeDefinition->getCMDL();
         $vars['definition'] = $configTypeDefinition;
         $vars['cmdl'] = $cmdl;
         $vars['data_type'] = 'config';
         return $app->renderPage('admin-data-type.twig', $vars);
     }
 }
 public static function importRecords(Application $app, Request $request, $contentTypeAccessHash, Module $module = null)
 {
     $vars = array();
     $vars['links']['execute'] = $app['url_generator']->generate('executeImportRecords', array('contentTypeAccessHash' => $contentTypeAccessHash));
     /** @var Repository $repository */
     $repository = $app['repos']->getRepositoryByContentTypeAccessHash($contentTypeAccessHash);
     if ($repository) {
         $contentTypeDefinition = $repository->getContentTypeDefinition();
         $app['context']->setCurrentRepository($repository);
         $app['context']->setCurrentContentType($contentTypeDefinition);
     }
     return $app->renderPage('importrecords-modal.twig', $vars);
 }
 public static function editConfig(Application $app, $configTypeAccessHash)
 {
     $vars = array();
     $vars['menu_mainmenu'] = $app['menus']->renderMainMenu();
     /** @var Repository $repository */
     $repository = $app['repos']->getRepositoryByConfigTypeAccessHash($configTypeAccessHash);
     /** @var ConfigTypeDefinition $configTypeDefinition */
     $configTypeDefinition = $app['repos']->getConfigTypeDefinitionByConfigTypeAccessHash($configTypeAccessHash);
     if ($repository) {
         $vars['repository'] = $repository;
         $repositoryAccessHash = $app['repos']->getRepositoryAccessHash($repository);
         $vars['links']['repository'] = $app['url_generator']->generate('indexRepository', array('repositoryAccessHash' => $repositoryAccessHash));
         $app['context']->setCurrentRepository($repository);
         $app['context']->setCurrentConfigType($configTypeDefinition);
         $app['form']->setDataTypeDefinition($configTypeDefinition);
         $repository->selectWorkspace($app['context']->getCurrentWorkspace());
         $repository->selectLanguage($app['context']->getCurrentLanguage());
         $repository->setTimeShift($app['context']->getCurrentTimeShift());
         $repository->selectView('default');
         /** @var Config $record */
         $record = $repository->getConfig($configTypeDefinition->getName());
         if ($record) {
             $app['context']->setCurrentConfig($record);
             $vars['record'] = $record;
             $vars['definition'] = $configTypeDefinition;
             /* @var ViewDefinition */
             $viewDefinition = $configTypeDefinition->getViewDefinition('default');
             $vars['form'] = $app['form']->renderFormElements('form_edit', $viewDefinition->getFormElementDefinitions(), $record->getProperties());
             $vars['links']['timeshift'] = $app['url_generator']->generate('timeShiftEditConfig', array('configTypeAccessHash' => $configTypeAccessHash));
             $vars['links']['workspaces'] = $app['url_generator']->generate('changeWorkspaceEditConfig', array('configTypeAccessHash' => $configTypeAccessHash));
             $vars['links']['languages'] = $app['url_generator']->generate('changeLanguageEditConfig', array('configTypeAccessHash' => $configTypeAccessHash));
             return $app->renderPage('editconfig.twig', $vars);
         }
     }
     return $app->renderPage('config-not-found.twig', $vars);
 }
 public function init()
 {
     $repositoryFactory = new RepositoryFactory();
     if ($this->getConfigService()->hasConfigurationSection('repositories')) {
         $config = $this->getConfigService()->getConfigurationSection('repositories');
         foreach ($config as $k => $params) {
             if (!is_array($params)) {
                 $params = ['type' => 'rlike-v1', 'url' => $params];
             }
             $options = [];
             $cacheKeyContentTypes = 'sessioncache.repository.' . $k . '.contenttypes';
             $cacheKeyConfigTypes = 'sessioncache.repository.' . $k . '.configtypes';
             if ($this->getSession()->has($cacheKeyContentTypes)) {
                 $options['contenttypes'] = $this->getSession()->get($cacheKeyContentTypes);
             }
             if ($this->getSession()->has($cacheKeyConfigTypes)) {
                 $options['configtypes'] = $this->getSession()->get($cacheKeyConfigTypes);
             }
             switch ($params['type']) {
                 case 'rlike-v1':
                     $repository = $repositoryFactory->createRestLikeRepository($k, $params['url'], $options);
                     $repository->setPublicUrl($params['url']);
                     if (isset($params['files'])) {
                         $fileManager = $repository->getFileManager();
                         if ($fileManager) {
                             $fileManager->setPublicUrl($params['files']);
                         }
                     }
                     break;
             }
             if (!$this->getSession()->has($cacheKeyContentTypes)) {
                 $this->getSession()->set($cacheKeyContentTypes, $repository->getContentTypeNames());
             }
             if (!$this->getSession()->has($cacheKeyConfigTypes)) {
                 $this->getSession()->set($cacheKeyConfigTypes, $repository->getConfigTypeNames());
             }
             $repository = $this->app->getClient()->addRepository($repository);
             $this->addRepository($repository->getName(), $repository, $repository->getTitle());
         }
     }
 }
 public static function listRecords(Application $app, Request $request, $contentTypeAccessHash, $page = 1, $workspace = null, $language = null, $nr = 0)
 {
     /** @var UserManager $user */
     $user = $app['user'];
     /** @var ContentViewsManager $contentViewsManager */
     $contentViewsManager = $app['contentViews'];
     $vars = array();
     $vars['menu_mainmenu'] = $app['menus']->renderMainMenu();
     /** @var Repository $repository */
     $repository = $app['repos']->getRepositoryByContentTypeAccessHash($contentTypeAccessHash);
     $vars['repository'] = $repository;
     $repositoryAccessHash = $app['repos']->getRepositoryAccessHash($repository);
     $vars['links']['repository'] = $app['url_generator']->generate('indexRepository', array('repositoryAccessHash' => $repositoryAccessHash));
     $vars['links']['self'] = $app['url_generator']->generate('listRecords', array('contentTypeAccessHash' => $contentTypeAccessHash));
     $contentTypeDefinition = $repository->getContentTypeDefinition();
     $app['context']->setCurrentRepository($repository);
     $app['context']->setCurrentContentType($contentTypeDefinition);
     $app['context']->setCurrentListingPage($page);
     $vars['definition'] = $contentTypeDefinition;
     if ($workspace != null && $contentTypeDefinition->hasWorkspace($workspace)) {
         $app['context']->setCurrentWorkspace($workspace);
     }
     if ($language != null && $contentTypeDefinition->hasLanguage($language)) {
         $app['context']->setCurrentLanguage($language);
     }
     // set workspace, language and timeshift of repository object to make sure content views are accessing the right content dimensions
     $repository->selectWorkspace($app['context']->getCurrentWorkspace());
     $repository->selectLanguage($app['context']->getCurrentLanguage());
     $repository->setTimeshift($app['context']->getCurrentTimeShift());
     // Jump to record if existing id has been entered into the search field
     if ($request->query->has('q')) {
         if (is_numeric($request->query->get('q'))) {
             $recordId = (int) $request->query->get('q');
             if ($repository->getRecord($recordId)) {
                 $app['context']->setCurrentSearchTerm('');
                 return new RedirectResponse($app['url_generator']->generate('editRecord', array('contentTypeAccessHash' => $contentTypeAccessHash, 'recordId' => $recordId)), 303);
             }
         }
         $app['context']->setCurrentSearchTerm($request->query->get('q'));
     }
     // store sorting order
     if ($request->query->has('s')) {
         $app['context']->setCurrentSortingOrder($request->query->get('s'));
     }
     // store items per page
     if ($request->query->has('c')) {
         $app['context']->setCurrentItemsPerPage($request->query->get('c'));
     }
     // Determine Content View
     $contentViews = $contentViewsManager->getContentViews($repository, $contentTypeDefinition, $contentTypeAccessHash);
     if ((int) $nr == 0) {
         $nr = $app['context']->getCurrentContentViewNr();
     }
     if (count($contentViews) == 0) {
         $contentViews[1] = new ContentViewDefault(1, $app, $repository, $contentTypeDefinition, $contentTypeAccessHash);
     }
     $vars['contentViews'] = $contentViews;
     $currentContentView = $contentViewsManager->getContentView($repository, $contentTypeDefinition, $contentTypeAccessHash, $nr);
     if (!$currentContentView) {
         $currentContentView = reset($contentViews);
         $nr = key($contentViews);
     }
     // Switch to first content view which support search queries
     if ($request->query->has('q') && !$currentContentView->doesProcessSearch()) {
         $error = true;
         foreach ($contentViews as $nr => $currentContentView) {
             if ($currentContentView->doesProcessSearch()) {
                 $error = false;
                 break;
             }
         }
         if ($error) {
             $app['context']->addAlertMessage('Configuration error. Could not find content view, which is able to process search queries.');
         }
     }
     $vars['contentView'] = $currentContentView;
     $vars['currentContentViewNr'] = $nr;
     $app['context']->setCurrentContentViewNr($nr);
     // sorting links
     $vars['links']['search'] = $app['url_generator']->generate('listRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => 1, 's' => 'name', 'workspace' => $app['context']->getCurrentWorkspace(), 'language' => $app['context']->getCurrentLanguage()));
     $vars['links']['closeSearchBox'] = $app['url_generator']->generate('listRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => 1, 'q' => ''));
     // context links
     $vars['links']['timeshift'] = $app['url_generator']->generate('timeShiftListRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => $page));
     $vars['links']['workspaces'] = $app['url_generator']->generate('changeWorkspaceListRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => $page));
     $vars['links']['languages'] = $app['url_generator']->generate('changeLanguageListRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'page' => $page));
     $vars['links']['reset'] = $app['url_generator']->generate('listRecordsReset', array('contentTypeAccessHash' => $contentTypeAccessHash));
     $buttons = array();
     $buttons[100] = array('label' => 'List Records', 'url' => $app['url_generator']->generate('listRecordsReset', array('contentTypeAccessHash' => $contentTypeAccessHash, 'workspace' => $app['context']->getCurrentWorkspace(), 'language' => $app['context']->getCurrentLanguage())), 'glyphicon' => 'glyphicon-list');
     if ($contentTypeDefinition->isSortable() && $user->canDo('sort', $repository, $contentTypeDefinition)) {
         $buttons[200] = array('label' => 'Sort Records', 'url' => $app['url_generator']->generate('sortRecords', array('contentTypeAccessHash' => $contentTypeAccessHash, 'workspace' => $app['context']->getCurrentWorkspace(), 'language' => $app['context']->getCurrentLanguage())), 'glyphicon' => 'glyphicon-move');
     }
     if ($user->canDo('add', $repository, $contentTypeDefinition)) {
         $buttons[300] = array('label' => 'Add Record', 'url' => $app['url_generator']->generate('addRecord', array('contentTypeAccessHash' => $contentTypeAccessHash, 'workspace' => $app['context']->getCurrentWorkspace(), 'language' => $app['context']->getCurrentLanguage())), 'glyphicon' => 'glyphicon-plus');
     }
     if ($user->canDo('export', $repository, $contentTypeDefinition)) {
         $buttons[400] = array('label' => 'Export Records', 'url' => $app['url_generator']->generate('exportRecords', array('contentTypeAccessHash' => $contentTypeAccessHash)), 'glyphicon' => 'glyphicon-cloud-download', 'id' => 'listing_button_export');
     }
     if ($user->canDo('import', $repository, $contentTypeDefinition)) {
         $buttons[500] = array('label' => 'Import Records', 'url' => $app['url_generator']->generate('importRecords', array('contentTypeAccessHash' => $contentTypeAccessHash)), 'glyphicon' => 'glyphicon-cloud-upload', 'id' => 'listing_button_import');
     }
     $vars['buttons'] = $app['menus']->renderButtonGroup($buttons);
     $vars = $currentContentView->apply($vars);
     return $app->renderPage($currentContentView->getTemplate(), $vars);
 }
 /**
  * Displays the transfer record dialog
  *
  * @param Application $app
  * @param Request $request
  * @param             $contentTypeAccessHash
  * @param             $recordId
  * @param             $workspace
  * @param             $language
  *
  * @return mixed
  */
 public function transferRecordModal(Application $app, Request $request, $contentTypeAccessHash, $recordId, $workspace, $language)
 {
     $vars = array();
     $vars['record'] = false;
     $recordId = (int) $recordId;
     if ($recordId) {
         /** @var Repository $repository */
         $repository = $app['repos']->getRepositoryByContentTypeAccessHash($contentTypeAccessHash);
         if ($repository) {
             $contentTypeDefinition = $repository->getContentTypeDefinition();
             $app['context']->setCurrentRepository($repository);
             $app['context']->setCurrentContentType($contentTypeDefinition);
             if ($workspace != null && $contentTypeDefinition->hasWorkspace($workspace)) {
                 $app['context']->setCurrentWorkspace($workspace);
             }
             if ($language != null && $contentTypeDefinition->hasLanguage($language)) {
                 $app['context']->setCurrentLanguage($language);
             }
             $repository->selectWorkspace($app['context']->getCurrentWorkspace());
             $repository->selectLanguage($app['context']->getCurrentLanguage());
             $repository->setTimeShift($app['context']->getCurrentTimeShift());
             $repository->selectView('default');
             /** @var Record $record */
             //$record = $repository->getRecord($recordId, $app['context']->getCurrentWorkspace(), 'default', $app['context']->getCurrentLanguage(), $app['context']->getCurrentTimeShift());
             $record = $repository->getRecord($recordId);
             if ($record) {
                 $app['context']->setCurrentRecord($record);
                 $vars['record'] = $record;
                 /** @var ContentTypeDefinition $contentTypeDefinition */
                 $contentTypeDefinition = $repository->getContentTypeDefinition();
                 $vars['definition'] = $contentTypeDefinition;
                 $records = array();
                 $repository->setTimeShift(0);
                 foreach ($repository->getRecords() as $record) {
                     $records[$record->getID()] = '#' . $record->getID() . ' ' . $record->getName();
                 }
                 $vars['records'] = $records;
                 $vars['links']['transfer'] = $app['url_generator']->generate('transferRecord', array('contentTypeAccessHash' => $contentTypeAccessHash, 'recordId' => $recordId, "workspace" => $app['context']->getCurrentWorkspace(), "language" => $app['context']->getCurrentLanguage()));
             }
         }
     }
     return $app->renderPage('transferrecord-modal.twig', $vars);
 }
 public static function listFiles(Application $app, Request $request, $repositoryAccessHash, $path = '', $mode = 'page')
 {
     $vars = array();
     $vars['root'] = false;
     if ($mode == 'modal') {
         $listFilesRouteName = 'listFilesSelect';
         $listFilesTemplateName = 'files-list-modal.twig';
         $app['layout']->addJsFile('files-modal.js');
     } else {
         $listFilesRouteName = 'listFiles';
         $listFilesTemplateName = 'files-list-page.twig';
     }
     $vars['links']['files'] = $app['url_generator']->generate($listFilesRouteName, array('repositoryAccessHash' => $repositoryAccessHash, 'path' => ''));
     /** @var Repository $repository */
     $repository = $app['repos']->getRepositoryByRepositoryAccessHash($repositoryAccessHash);
     if ($repository) {
         $app['context']->setCurrentRepository($repository);
         $path = '/' . trim($path, '/');
         $vars['delete_folder_path'] = $path;
         $vars['create_folder_path'] = trim($path, '/') . '/';
         $breadcrumbs = explode('/', $path);
         if ($path == '/') {
             $breadcrumbs = array('');
             $vars['root'] = true;
         }
         $folders = array();
         $nextPath = '';
         foreach ($breadcrumbs as $subPath) {
             $nextPath .= '/' . $subPath;
             $folder = $repository->getFolder($nextPath);
             if ($folder) {
                 $items = array();
                 foreach ($folder->listSubFolders() as $id => $name) {
                     $id = trim($id, '/');
                     $item = array('name' => $name, 'class' => '', 'url' => $app['url_generator']->generate($listFilesRouteName, array('repositoryAccessHash' => $repositoryAccessHash, 'path' => $id)));
                     if (strstr($path, $id)) {
                         $item['class'] = 'active';
                     }
                     $items[] = $item;
                 }
                 $folders[] = $items;
                 $files = array();
                 /* @var $file File */
                 foreach ($folder->getFiles() as $file) {
                     $item = array();
                     $item['file'] = $file;
                     $item['links']['download'] = $app['url_generator']->generate('downloadFile', array('repositoryAccessHash' => $repositoryAccessHash, 'id' => $file->getId()));
                     $item['links']['view'] = $app['url_generator']->generate('viewFile', array('repositoryAccessHash' => $repositoryAccessHash, 'id' => $file->getId()));
                     $item['links']['delete'] = $app['url_generator']->generate('deleteFile', array('repositoryAccessHash' => $repositoryAccessHash, 'id' => $file->getId()));
                     if ($file->hasPublicUrl()) {
                         $item['links']['src'] = $file->getUrl('default');
                     } else {
                         $item['links']['src'] = $item['links']['view'];
                     }
                     $files[] = $item;
                 }
             } else {
                 return new RedirectResponse($vars['links']['files'], 303);
             }
         }
         $vars['folders'] = $folders;
         $vars['files'] = $files;
     }
     $vars['menu_mainmenu'] = $app['menus']->renderMainMenu();
     $buttons = array();
     $buttons[100] = array('label' => 'Upload File', 'url' => '', 'glyphicon' => 'glyphicon-cloud-upload', 'id' => 'form_files_button_upload_file');
     $buttons[200] = array('label' => 'Create Folder', 'url' => '', 'glyphicon' => 'glyphicon-folder-open', 'id' => 'form_files_button_create_folder');
     $buttons[300] = array('label' => 'Delete Folder', 'url' => '', 'glyphicon' => 'glyphicon-trash', 'id' => 'form_files_button_delete_folder');
     $vars['buttons'] = $app['menus']->renderButtonGroup($buttons);
     return $app->renderPage($listFilesTemplateName, $vars);
 }
 public function init(Application $app, $options = array())
 {
     $app->addTemplatesFolders(__DIR__ . '/views/');
 }
 public static function login(Application $app, Request $request)
 {
     return $app->renderPage('login.twig');
 }
 public function init(Application $app, $options = array())
 {
     $app->addTemplatesFolders(__DIR__ . '/views/');
     $app->get('/edit/modal/{repositoryAccessHash}/file/{path}', 'AnyContent\\CMCK\\Modules\\Backend\\Edit\\FileFormElements\\Controller::modal')->value('module', $this)->assert('path', '.+')->bind('formElementFileModal');
 }
 public static function changeLanguageEditConfig(Application $app, Request $request, $configTypeAccessHash)
 {
     $app['context']->setCurrentLanguage($request->get('language'));
     return $app->redirect($app['url_generator']->generate('editConfig', array('configTypeAccessHash' => $configTypeAccessHash)), 303);
 }