Наследование: extends common\Locale
Пример #1
0
 /**
  * @param string $locale
  * @param AbstractPlatform $platform
  *
  * @return Locale
  */
 public function convertToPHPValue($locale, AbstractPlatform $platform)
 {
     if (APPLICATION === 'frontend') {
         return FrontendLocale::fromString($locale);
     }
     return BackendLocale::fromString($locale);
 }
Пример #2
0
 /**
  * @param Locale|null $language
  */
 public function __construct(Locale $language = null)
 {
     if ($language === null) {
         $language = Locale::workingLocale();
     }
     $this->language = $language;
 }
 /**
  * @param Locale $toLocale
  * @param Locale|null $fromLocale
  */
 public function __construct(Locale $toLocale, Locale $fromLocale = null)
 {
     if ($fromLocale === null) {
         $fromLocale = Locale::workingLocale();
     }
     $this->toLocale = $toLocale;
     $this->fromLocale = $fromLocale;
     $this->extraIdMap = [];
 }
Пример #4
0
 /**
  * Execute the action
  */
 public function execute()
 {
     /** @var ContentBlockRepository $contentBlockRepository */
     $contentBlockRepository = $this->get('content_blocks.repository.content_block');
     $contentBlock = $contentBlockRepository->findOneByIdAndLocale($this->getParameter('id', 'int'), Locale::workingLocale());
     if ($contentBlock === null) {
         return $this->redirect(BackendModel::createURLForAction('Index', null, null, ['error' => 'non-existing']));
     }
     // The command bus will handle the saving of the content block in the database.
     $this->get('command_bus')->handle(new DeleteContentBlock($contentBlock));
     $this->get('event_dispatcher')->dispatch(ContentBlockDeleted::EVENT_NAME, new ContentBlockDeleted($contentBlock));
     return $this->redirect(BackendModel::createURLForAction('Index', null, null, ['report' => 'deleted', 'var' => $contentBlock->getTitle()]));
 }
Пример #5
0
 /**
  * Load the datagrid
  */
 private function loadDataGrid()
 {
     $this->dataGrid = new ContentBlockDataGrid(Locale::workingLocale());
     $this->dataGrid->setSortingColumns(['title']);
     // show the hidden status
     $this->dataGrid->addColumn('isHidden', ucfirst(BL::lbl('VisibleOnSite')), '[hidden]');
     $this->dataGrid->setColumnFunction([TemplateModifiers::class, 'showBool'], ['[hidden]', true], 'isHidden');
     // check if this action is allowed
     if (BackendAuthentication::isAllowedAction('Edit')) {
         $editUrl = BackendModel::createURLForAction('Edit', null, null, ['id' => '[id]'], false);
         $this->dataGrid->setColumnURL('title', $editUrl);
         $this->dataGrid->addColumn('edit', null, BL::lbl('Edit'), $editUrl, BL::lbl('Edit'));
     }
 }
Пример #6
0
 /**
  * Parses a data grid with the revisions in the template
  */
 private function parseRevisionsDataGrid()
 {
     // create datagrid
     $revisions = new ContentBlockRevisionDataGrid($this->contentBlock, Locale::workingLocale());
     // hide columns
     $revisions->setColumnsHidden(['id', 'revision_id']);
     // disable paging
     $revisions->setPaging(false);
     // set headers
     $revisions->setHeaderLabels(['user_id' => SpoonFilter::ucfirst(Language::lbl('By')), 'edited_on' => SpoonFilter::ucfirst(Language::lbl('LastEditedOn'))]);
     // set column-functions
     $revisions->setColumnFunction([DataGridFunctions::class, 'getUser'], ['[user_id]'], 'user_id');
     $revisions->setColumnFunction([DataGridFunctions::class, 'getTimeAgo'], ['[edited_on]'], 'edited_on');
     // check if this action is allowed
     if (Authentication::isAllowedAction('Edit')) {
         $editRevisionUrl = BackendModel::createURLForAction('Edit', null, null, ['id' => '[id]', 'revision' => '[revision_id]'], false);
         // set column URLs
         $revisions->setColumnURL('title', $editRevisionUrl);
         // add use column
         $revisions->addColumn('use_revision', null, Language::lbl('UseThisVersion'), $editRevisionUrl, Language::lbl('UseThisVersion'));
     }
     $this->tpl->assign('revisions', (string) $revisions->getContent());
 }
Пример #7
0
 /**
  * Copy pages
  *
  * @param string $from The language code to copy the pages from.
  * @param string $to   The language code we want to copy the pages to.
  */
 public static function copy($from, $to)
 {
     // get db
     $db = BackendModel::getContainer()->get('database');
     // copy contentBlocks and get copied contentBlockIds
     $copyContentBlocks = new CopyContentBlocksToOtherLocale(Locale::fromString($to), Locale::fromString($from));
     BackendModel::get('command_bus')->handle($copyContentBlocks);
     $contentBlockIds = $copyContentBlocks->extraIdMap;
     // define old block ids
     $contentBlockOldIds = array_keys($contentBlockIds);
     // get all old pages
     $ids = $db->getColumn('SELECT id
          FROM pages AS i
          WHERE i.language = ? AND i.status = ?', array($to, 'active'));
     // any old pages
     if (!empty($ids)) {
         // delete existing pages
         foreach ($ids as $id) {
             // redefine
             $id = (int) $id;
             // get revision ids
             $revisionIDs = (array) $db->getColumn('SELECT i.revision_id
                  FROM pages AS i
                  WHERE i.id = ? AND i.language = ?', array($id, $to));
             // get meta ids
             $metaIDs = (array) $db->getColumn('SELECT i.meta_id
                  FROM pages AS i
                  WHERE i.id = ? AND i.language = ?', array($id, $to));
             // delete meta records
             if (!empty($metaIDs)) {
                 $db->delete('meta', 'id IN (' . implode(',', $metaIDs) . ')');
             }
             // delete blocks and their revisions
             if (!empty($revisionIDs)) {
                 $db->delete('pages_blocks', 'revision_id IN (' . implode(',', $revisionIDs) . ')');
             }
             // delete page and the revisions
             if (!empty($revisionIDs)) {
                 $db->delete('pages', 'revision_id IN (' . implode(',', $revisionIDs) . ')');
             }
         }
     }
     // delete search indexes
     $db->delete('search_index', 'module = ? AND language = ?', array('pages', $to));
     // get all active pages
     $ids = BackendModel::getContainer()->get('database')->getColumn('SELECT id
          FROM pages AS i
          WHERE i.language = ? AND i.status = ?', array($from, 'active'));
     // loop
     foreach ($ids as $id) {
         // get data
         $sourceData = self::get($id, null, $from);
         // get and build meta
         $meta = $db->getRecord('SELECT *
              FROM meta
              WHERE id = ?', array($sourceData['meta_id']));
         // remove id
         unset($meta['id']);
         // init page
         $page = array();
         // build page
         $page['id'] = $sourceData['id'];
         $page['user_id'] = BackendAuthentication::getUser()->getUserId();
         $page['parent_id'] = $sourceData['parent_id'];
         $page['template_id'] = $sourceData['template_id'];
         $page['meta_id'] = (int) $db->insert('meta', $meta);
         $page['language'] = $to;
         $page['type'] = $sourceData['type'];
         $page['title'] = $sourceData['title'];
         $page['navigation_title'] = $sourceData['navigation_title'];
         $page['navigation_title_overwrite'] = $sourceData['navigation_title_overwrite'];
         $page['hidden'] = $sourceData['hidden'];
         $page['status'] = 'active';
         $page['publish_on'] = BackendModel::getUTCDate();
         $page['created_on'] = BackendModel::getUTCDate();
         $page['edited_on'] = BackendModel::getUTCDate();
         $page['allow_move'] = $sourceData['allow_move'];
         $page['allow_children'] = $sourceData['allow_children'];
         $page['allow_edit'] = $sourceData['allow_edit'];
         $page['allow_delete'] = $sourceData['allow_delete'];
         $page['sequence'] = $sourceData['sequence'];
         $page['data'] = $sourceData['data'] !== null ? serialize($sourceData['data']) : null;
         // insert page, store the id, we need it when building the blocks
         $revisionId = self::insert($page);
         // init var
         $blocks = array();
         // get the blocks
         $sourceBlocks = self::getBlocks($id, null, $from);
         // loop blocks
         foreach ($sourceBlocks as $sourceBlock) {
             // build block
             $block = $sourceBlock;
             $block['revision_id'] = $revisionId;
             $block['created_on'] = BackendModel::getUTCDate();
             $block['edited_on'] = BackendModel::getUTCDate();
             if (in_array($block['extra_id'], $contentBlockOldIds)) {
                 $block['extra_id'] = $contentBlockIds[$block['extra_id']];
             }
             // add block
             $blocks[] = $block;
         }
         // insert the blocks
         self::insertBlocks($blocks);
         // init var
         $text = '';
         // build search-text
         foreach ($blocks as $block) {
             $text .= ' ' . $block['html'];
         }
         // add
         BackendSearchModel::saveIndex('Pages', (int) $page['id'], array('title' => $page['title'], 'text' => $text), $to);
         // get tags
         $tags = BackendTagsModel::getTags('pages', $id, 'string', $from);
         // save tags
         if ($tags != '') {
             $saveWorkingLanguage = BL::getWorkingLanguage();
             // If we don't set the working language to the target language,
             // BackendTagsModel::getURL() will use the current working
             // language, possibly causing unnecessary '-2' suffixes in
             // tags.url
             BL::setWorkingLanguage($to);
             BackendTagsModel::saveTags($page['id'], $tags, 'pages', $to);
             BL::setWorkingLanguage($saveWorkingLanguage);
         }
     }
     // build cache
     self::buildCache($to);
 }