コード例 #1
0
ファイル: Validation.php プロジェクト: fraym/core
 /**
  * Build errormessages and add rules
  *
  * @param $modelName
  * @return $this
  */
 public function getFormFieldValidation($modelName)
 {
     $formField = $this->formField->setClassName($modelName);
     $errorMessages = [];
     $defaultLocale = $this->locale->getDefaultLocale();
     foreach ($formField->getFields() as $field => $annotation) {
         if (isset($annotation['validation'])) {
             foreach ($annotation['validation'] as $validationRule) {
                 $value = isset($this->fieldsArray[$field]) ? $this->fieldsArray[$field] : '';
                 $formFieldAnnotationTranslation = $formField->getAnnotation($annotation['annotations'], 'Gedmo\\Mapping\\Annotation\\Translatable');
                 if (false !== $formFieldAnnotationTranslation && is_array($value)) {
                     $translation = isset($value[$defaultLocale->locale]) ? $value[$defaultLocale->locale] : '';
                     $this->fieldsArray[$field] = $translation;
                     // set default translation
                     $errorMessages[$field][$validationRule] = $formField->getErrorMessage($field, $translation, $modelName, $validationRule);
                 } elseif (is_array($value)) {
                     $errorMessages[$field][$validationRule] = $formField->getErrorMessage($field, implode(',', $value), $modelName, $validationRule);
                 } elseif (is_string($value)) {
                     $errorMessages[$field][$validationRule] = $formField->getErrorMessage($field, $value, $modelName, $validationRule);
                 }
                 if ($validationRule === 'unique' && !isset($this->fieldsArray['id'])) {
                     $this->addRule($field, [$this->formField, 'uniqueEntityCheck'], [$modelName, $field]);
                 } elseif ($validationRule !== 'unique') {
                     $this->addRule($field, $validationRule);
                 }
             }
         }
     }
     $this->setErrorMessages($errorMessages);
     return $this;
 }
コード例 #2
0
ファイル: LanguageMenu.php プロジェクト: jewelhuq/fraym
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $languageMenu = array();
     $currentLocale = $this->locale->getLocale()->id;
     $defaultLocale = $this->locale->getDefaultLocale();
     $currentMenuItem = $this->route->getCurrentMenuItem();
     $locales = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findAll();
     foreach ($currentMenuItem->translations as $translation) {
         $url = $translation->url === '' ? '/' : $translation->url;
         $languageMenu[$translation->locale->id] = array('url' => $url, 'active' => $translation->locale->id === $currentLocale, 'name' => $translation->locale->name);
     }
     foreach ($locales as $locale) {
         if (!isset($languageMenu[$locale->id])) {
             $menuItem = $currentMenuItem;
             do {
                 $m = $menuItem->parent;
                 if ($m) {
                     $menuItem = $m;
                 }
             } while ($m);
             foreach ($menuItem->translations as $mTranslation) {
                 if ($mTranslation->locale->id === $locale->id) {
                     $url = $mTranslation->url;
                     break;
                 } elseif ($mTranslation->locale->id === $defaultLocale->id) {
                     $url = $mTranslation->url;
                 }
             }
             $languageMenu[$locale->id] = array('url' => $url === '' ? '/' : $url, 'active' => $locale->id === $currentLocale, 'name' => $locale->name);
         }
     }
     $this->languageMenuController->renderHtml($languageMenu);
 }
コード例 #3
0
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $languageMenu = array();
     $currentLocale = $this->locale->getLocale()->id;
     $currentMenuItem = $this->route->getCurrentMenuItem();
     foreach ($currentMenuItem->translations as $translation) {
         $url = $translation->getUrl(true);
         $languageMenu[$translation->locale->id] = array('enable' => $translation->active, 'url' => $url, 'active' => $translation->locale->id === $currentLocale, 'name' => $translation->locale->name);
     }
     foreach ($languageMenu as $locale => $language) {
         if ($language['enable'] === false) {
             $menuItem = $currentMenuItem;
             do {
                 $menuItem = $menuItem->parent;
             } while ($menuItem->parent);
             $translation = $menuItem->getTranslation($locale);
             $languageMenu[$locale]['url'] = $translation ? $translation->url : '/';
         } else {
             $localeData = $this->db->getRepository('\\Fraym\\Locale\\Entity\\Locale')->findOneById($locale);
             $localeData = explode('_', strtolower($localeData->locale));
             $this->template->addHeadData('<link rel="alternate" hreflang="' . $localeData[0] . '" href="' . $language['url'] . '" />', 'hreflang_' . $localeData[0]);
         }
     }
     $this->languageMenuController->renderHtml($languageMenu);
 }
コード例 #4
0
ファイル: InstallController.php プロジェクト: fraym/core
 /**
  * @param $site
  * @return $this
  */
 protected function addMenuItems($site)
 {
     $pageRoot = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById(1);
     /**
      * 404 Page
      */
     $newPage = new \Fraym\Menu\Entity\MenuItem();
     $newPage->site = $site;
     $newPage->caching = true;
     $newPage->https = false;
     $newPage->checkPermission = false;
     $newPage->is404 = true;
     $newPage->parent = $pageRoot;
     $newPageTranslation = new \Fraym\Menu\Entity\MenuItemTranslation();
     $newPageTranslation->menuItem = $newPage;
     $newPageTranslation->visible = false;
     $newPageTranslation->active = true;
     $newPageTranslation->title = $this->translation->autoTranslation('404 Page not found', 'en', $this->locale->getLocale()->locale);
     $newPageTranslation->subtitle = '';
     $newPageTranslation->url = '/' . $this->translation->autoTranslation('error', 'en', $this->locale->getLocale()->locale) . '-404';
     $newPageTranslation->description = $this->translation->autoTranslation('404 Page not found', 'en', $this->locale->getLocale()->locale);
     $newPageTranslation->externalUrl = false;
     $this->db->persist($newPageTranslation);
     $this->db->flush();
     $this->db->clear();
     return $this;
 }
コード例 #5
0
 /**
  * @return bool|mixed
  */
 public function getContent()
 {
     if ($this->user->isAdmin() === false) {
         return false;
     }
     $currentEntity = false;
     $errors = false;
     $data = array();
     $formFields = array();
     $entities = array();
     $modelClass = false;
     $model = false;
     $modelName = $this->request->gp('model', false);
     $groupedModels = $this->db->getRepository('\\Fraym\\EntityManager\\Entity\\Group')->findAll();
     if ($modelName) {
         $model = $this->entityManager->getEntityByStringOrId($modelName);
         if ($model) {
             $modelClass = $model->className;
         }
     }
     if ($this->request->isXmlHttpRequest()) {
         return $this->createEntityFromSingleField($modelClass);
     }
     if ($modelClass && $this->request->isPost()) {
         $data = $this->request->getGPAsArray();
         $validation = $this->validation->setData($data)->getFormFieldValidation($modelClass);
         if ($id = $this->request->post('id')) {
             $currentEntity = $this->db->getRepository($modelClass)->findOneById($id);
             if (isset($data['cmd']) && $data['cmd'] == 'update' && $currentEntity && ($errors = $validation->check()) === true) {
                 $currentEntity->updateEntity($data);
             } elseif (isset($data['cmd']) && $data['cmd'] == 'remove' && $currentEntity) {
                 $this->db->remove($currentEntity);
                 $this->db->flush();
                 $data = array();
                 $currentEntity = false;
             } elseif (isset($data['cmd']) && $data['cmd'] == 'update') {
                 $currentEntity->updateEntity($data, false);
             }
         } else {
             if (isset($data['cmd']) && $data['cmd'] == 'new' && ($errors = $validation->check()) === true) {
                 $currentEntity = new $modelClass();
                 $currentEntity->updateEntity($data);
             }
         }
     }
     if ($modelClass && $model) {
         $entities = $this->db->getRepository($modelClass)->findAll();
         $formFields = $this->formField->setClassName($modelClass)->getFields();
     }
     $this->view->assign('locales', $this->locale->getLocales());
     $this->view->assign('data', $data);
     $this->view->assign('errors', $errors);
     $this->view->assign('currentEntity', $currentEntity);
     $this->view->assign('entities', $entities);
     $this->view->assign('groupedModels', $groupedModels);
     $this->view->assign('model', $model);
     $this->view->assign('formFields', $formFields);
     return $this->siteManagerController->getIframeContent($this->template->fetch('EntityView'));
 }
コード例 #6
0
ファイル: Database.php プロジェクト: fraym/core
 /**
  * @return $this
  * @throws \Exception
  */
 public function setUpTranslateable()
 {
     $defaultLocale = $this->locale->getDefaultLocale();
     if ($defaultLocale === null) {
         throw new \Exception('Default locale not found! Fraym is not correctly installed, please reinstall Fraym.');
     }
     $this->translatableListener = new \Gedmo\Translatable\TranslatableListener();
     $this->translatableListener->setDefaultLocale($defaultLocale->locale);
     $this->translatableListener->setAnnotationReader($this->cachedAnnotationReader);
     $this->translatableListener->setTranslationFallback(true);
     $this->translatableListener->setPersistDefaultLocaleTranslation(true);
     $this->eventManager->addEventSubscriber($this->translatableListener);
     return $this;
 }
コード例 #7
0
ファイル: RegistryManager.php プロジェクト: jewelhuq/fraym
 /**
  * Create the table entries from the registry annotation
  *
  * @param $registry
  * @param $classAnnotation
  * @param $oldRegistryEntry
  * @return $this
  */
 private function createEntities($registry, $classAnnotation, $oldRegistryEntry = null)
 {
     if (count($classAnnotation->entity)) {
         foreach ($classAnnotation->entity as $className => $entries) {
             if ($oldRegistryEntry !== null && isset($classAnnotation->updateEntity[$className])) {
                 foreach ($classAnnotation->updateEntity[$className] as $entryData) {
                     $entry = $this->getEntity($className, $entryData);
                     if ($entry) {
                         $entryDataWithSubEntries['registry'] = $registry->id;
                         $data = $this->getEntityDataForUpdate($entryData, $classAnnotation->entity[$className]);
                         $entry->updateEntity($data);
                     }
                 }
             } elseif ($oldRegistryEntry === null) {
                 foreach ($entries as $entryData) {
                     $entryDataWithSubEntries = $this->getSubEntries($entryData, $registry);
                     if ($this->getEntity($className, $entryDataWithSubEntries) === null) {
                         $entry = new $className();
                         $entryDataWithSubEntries['registry'] = $registry->id;
                         $entry->updateEntity($entryDataWithSubEntries);
                     }
                 }
             }
         }
     }
     if (count($classAnnotation->config)) {
         foreach ($classAnnotation->config as $configName => $data) {
             $className = '\\Fraym\\Registry\\Entity\\Config';
             $data['name'] = $configName;
             $data['registry'] = $registry;
             $entity = $this->db->getRepository($className)->findOneByName($configName);
             if ($entity === null) {
                 $entry = new $className();
                 $entry->updateEntity($data);
             }
         }
     }
     if (count($classAnnotation->translation)) {
         foreach ($classAnnotation->translation as $translation) {
             $defaultValue = $translation[0];
             $key = isset($translation[1]) ? $translation[1] : $defaultValue;
             $locale = isset($translation[2]) ? $translation[2] : 'en_US';
             $this->translation->createTranslation($key, $defaultValue, $this->locale->getLocale()->locale, $locale);
         }
     }
     return $this;
 }
コード例 #8
0
ファイル: Translation.php プロジェクト: jewelhuq/fraym
 /**
  * @param $key
  * @param $locale
  * @param string $default
  * @param string $defaultLocale
  * @return Entity\Translation|mixed|object
  */
 private function getTranslationEntity($key, $locale, $default = '', $defaultLocale = 'en_US')
 {
     $translationString = empty($default) ? $key : $default;
     $translation = $this->db->getRepository('\\Fraym\\Translation\\Entity\\Translation')->findOneByKey($key);
     if (null === $translation) {
         return $this->createTranslation($key, $translationString, $locale, $defaultLocale);
     }
     $repository = $this->db->getRepository('Gedmo\\Translatable\\Entity\\Translation');
     $translations = $repository->findTranslations($translation);
     if (isset($translations[$locale])) {
         return (object) $translations[$locale];
     } elseif ($this->locale->getLocale()->locale == $locale) {
         $translation->locale = $locale;
         $this->db->refresh($translation);
         $this->db->clear();
         return $translation;
     } else {
         return $this->updateTranslationLocales($translation, $translationString, $locale, $defaultLocale);
     }
     return (object) $translations[$locale];
 }
コード例 #9
0
ファイル: DynamicTemplate.php プロジェクト: fraym/core
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $template = null;
     $dataSource = null;
     $locale = $this->locale->getLocale();
     $variables = unserialize((string) $xml->dynamicTemplateConfig);
     if (!empty((string) $xml->dynamicTemplate)) {
         $template = $this->getTemplatePath() . DIRECTORY_SEPARATOR . (string) $xml->dynamicTemplate;
     }
     $obj = $this->getTemplateXmlObject((string) $xml->dynamicTemplate);
     if (isset($obj->dataSource)) {
         $dataSource = $obj->dataSource;
         $class = (string) $dataSource->class;
         $method = (string) $dataSource->method;
         if (method_exists($class, $method)) {
             $classObj = $this->serviceLocator->get($class);
             $dataSource = $classObj->{$method}($locale->id, $variables);
         }
     }
     $this->dynamicTemplateController->render($template, $locale->id, $variables, $dataSource);
 }
コード例 #10
0
ファイル: Mailform.php プロジェクト: fraym/mailform-extension
 /**
  * @param $xml
  * @return mixed
  */
 public function execBlock($xml)
 {
     $errors = [];
     $submit = false;
     $values = $this->request->getGPAsArray();
     $requiredFields = $this->getRequiredFields($xml);
     $formHash = $this->createFormHash($requiredFields);
     if ($this->request->post('mailform')) {
         $required = $values['required'];
         $fields = $values['field'];
         if ($this->isFormValid($formHash, $this->getValidationRules($required))) {
             $submit = true;
             $this->validation->setData($fields);
             $this->validation->addRule('email', 'email');
             $errorMessages = [];
             foreach ($requiredFields as $field => $val) {
                 $this->validation->addRule($field, $val['rule'], $val['param']);
                 $errorMessages = array_merge($errorMessages, [$field => [$field => $this->translation->getTranslation('Please fill out the field')]]);
             }
             $this->validation->setErrorMessages($errorMessages);
             $check = $this->validation->check();
             if ($check === true) {
                 $config = json_decode($xml->mailformOptions, true);
                 $receiver = $config[$this->locale->getLocale()->id]['email'];
                 $subject = $config[$this->locale->getLocale()->id]['subject'];
                 $msg = $this->mail->getMessageInstance();
                 $msg->setFrom([$fields['email']]);
                 $msg->setSubject($subject);
                 $msg->setTo(explode(',', $receiver));
                 $this->template->assign('fields', $fields, false);
                 $msg->setBody($this->template->fetch('Extension/Mailform/Mail'), 'text/html');
                 $this->mail->send();
             } else {
                 $errors = $check;
             }
         }
     }
     $this->mailformController->renderHtml($submit, $values, $errors);
 }
コード例 #11
0
ファイル: Cache.php プロジェクト: fraym/core
 /**
  * if cacheing is active and a cached file is availible it outputs the cache and exits the script
  *
  * @return void
  */
 public function load()
 {
     // gets the current uri - example: /folder/folder2
     $filename = $this->getCacheName();
     // create the cache filename
     $cacheFilename = self::DIR_PAGES . $filename . '.cache.php';
     $cacheFilenamePhpData = self::DIR_PAGES . $filename . '.cache.config.php';
     $menuItemTranslation = false;
     $domain = false;
     $httpStatusCode = 200;
     $executedBlocks = [];
     if (defined('GLOBAL_CACHING_ENABLED') && GLOBAL_CACHING_ENABLED && !$this->request->isXmlHttpRequest() && !$this->request->isPost() && $this->user->isAdmin() === false && is_file($cacheFilename) && is_file($cacheFilenamePhpData)) {
         include $cacheFilenamePhpData;
         if ($menuItemTranslation) {
             $menuItemTranslation = json_decode($menuItemTranslation);
             if (is_object($menuItemTranslation)) {
                 if ($this->request->isXmlHttpRequest() === false && $this->route->isHttps() === false && $menuItemTranslation->menuItem->https === true) {
                     $this->route->redirectToUrl('https://' . $this->route->getRequestRoute());
                 }
                 $this->locale->setLocale($menuItemTranslation->locale);
                 $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir);
                 $this->route->setCurrentMenuItem($menuItemTranslation->menuItem);
                 $this->route->setCurrentMenuItemTranslation($menuItemTranslation);
                 $this->route->setCurrentDomain($domain);
                 if ($this->isCachingActive($menuItemTranslation->menuItem)) {
                     $this->blockParser->setExecutedBlocks(json_decode($executedBlocks));
                     // display the cached file to the client
                     $contents = file_get_contents($cacheFilename);
                     $this->blockParser->setParseCached(true);
                     $content = $this->blockParser->parse($contents, 'outputFilter');
                     $this->response->sendHTTPStatusCode($httpStatusCode);
                     echo $this->core->includeScript($content);
                     exit;
                 }
             }
         }
     }
 }
コード例 #12
0
ファイル: BlockController.php プロジェクト: jewelhuq/fraym
 /**
  * Save the block configuration received by the client.
  *
  * @return bool
  */
 public function saveBlockConfig()
 {
     $blockConfigGP = $this->request->getGPAsObject();
     $validate = $this->validation->setData($blockConfigGP);
     $validate->addRule('id', 'numeric')->addRule('menuId', 'numeric')->addRule('contentId', 'notEmpty');
     $block = false;
     $menuItemTranslation = null;
     if (($result = $validate->check()) === true) {
         $extension = $this->db->getRepository('\\Fraym\\Block\\Entity\\BlockExtension')->findOneById($blockConfigGP->id);
         $menu = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItem')->findOneById($blockConfigGP->menuId);
         $menuItemTranslation = $this->db->getRepository('\\Fraym\\Menu\\Entity\\MenuItemTranslation')->findOneById($blockConfigGP->menuTranslationId);
         if (isset($blockConfigGP->currentBlockId)) {
             $block = $this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findOneById($blockConfigGP->currentBlockId);
         }
         if ($extension) {
             if ($block) {
                 $newBlock = new BlockXML();
                 $newBlock->init($block->config);
             } else {
                 $newBlock = new BlockXML();
             }
             if (isset($blockConfigGP->excludedDevices)) {
                 $newBlock->setExcludedDevices($blockConfigGP->excludedDevices);
             }
             if (isset($blockConfigGP->permissions)) {
                 $newBlock->setPermissions($blockConfigGP->permissions);
             }
             $newBlock->setActive($blockConfigGP->active);
             $newBlock->setCache($blockConfigGP->cache);
             $newBlock->setMethod($extension->execMethod);
             $newBlock->setClass($extension->class);
             if (!empty($blockConfigGP->startDate)) {
                 $date = new \DateTime(date('Y-m-d H:i:s', strtotime($blockConfigGP->startDate)));
                 $newBlock->setStartDate($date);
             }
             if (!empty($blockConfigGP->endDate)) {
                 $date = new \DateTime(date('Y-m-d H:i:s', strtotime($blockConfigGP->endDate)));
                 $newBlock->setEndDate($date);
             }
             if ($blockConfigGP->template == 'custom') {
                 $newBlock->setTemplate($blockConfigGP->templateContent);
                 $newBlock->setTemplateType('string');
             } elseif (empty($blockConfigGP->template)) {
                 $newBlock->setTemplate($blockConfigGP->templateFile);
                 $newBlock->setTemplateType('file');
             } else {
                 $newBlock->setTemplateType($blockConfigGP->template);
             }
             $saveMethod = $extension->saveMethod;
             $instance = $this->serviceLocator->get($extension->class);
             if (empty($block)) {
                 $block = new \Fraym\Block\Entity\Block();
             }
             $blockCount = count($this->db->getRepository('\\Fraym\\Block\\Entity\\Block')->findByContentId($blockConfigGP->contentId));
             $block->contentId = $blockConfigGP->contentId;
             $block->position = $block->position ? $block->position : $blockCount;
             $block->menuItem = isset($blockConfigGP->menu) && $blockConfigGP->menu == '1' ? null : $menu;
             $block->site = $menu->site;
             $block->menuItemTranslation = $blockConfigGP->menuTranslation === 'current' ? $menuItemTranslation : null;
             $block->extension = $extension;
             $this->db->persist($block);
             $this->db->flush();
             /**
              * Set configuration for the block output
              */
             $this->locale->setLocale($menuItemTranslation->locale->id);
             $this->route->setCurrentMenuItem($menu);
             $this->route->setCurrentMenuItemTranslation($menuItemTranslation);
             /**
              * Extension event callback
              */
             if (method_exists($instance, $saveMethod)) {
                 $newBlock = $instance->{$saveMethod}($block->id, $newBlock);
             }
             $blockConfig = $this->blockParser->getBlockConfig((string) $newBlock);
             $block->config = $blockConfig;
             $this->db->flush();
             /**
              * Save block in history
              */
             if (isset($blockConfigGP->currentBlockId)) {
                 $this->block->saveHistory($block, 'edited');
             } else {
                 $this->block->saveHistory($block, 'added');
             }
             $data = $this->prepareBlockOutput($block);
             $this->response->sendAsJson(array('data' => $data, 'blockId' => $block->id));
         }
     }
     $this->response->sendAsJson(array('error' => $result));
 }
コード例 #13
0
ファイル: Template.php プロジェクト: fraym/core
 /**
  * @param $number
  * @param string $symbol
  * @return mixed
  */
 public function formatCurrency($number, $symbol = '')
 {
     $fmt = new \NumberFormatter($this->locale->getLocale()->locale, \NumberFormatter::CURRENCY);
     return $fmt->formatCurrency($number, $symbol);
 }
コード例 #14
0
ファイル: Route.php プロジェクト: jewelhuq/fraym
 /**
  * @param $menuItemTranslation
  * @return bool
  */
 private function setupPage($menuItemTranslation)
 {
     try {
         $this->currentMenuItemTranslation = $menuItemTranslation;
         $this->currentMenuItem = $menuItemTranslation->menuItem;
         $this->locale->setLocale($menuItemTranslation->locale);
         $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir);
         $pageTitle = ((string) $menuItemTranslation->pageTitle === '' ? $menuItemTranslation->title : $menuItemTranslation->pageTitle) . ' | ' . $menuItemTranslation->menuItem->site->name;
         $this->template->setPageTitle($pageTitle);
         $this->template->setPageDescription($menuItemTranslation->longDescription);
         $this->template->setKeywords(explode(',', $menuItemTranslation->keywords));
         setlocale(LC_ALL, $this->locale->getLocale()->locale);
     } catch (Exception $e) {
         return false;
     }
     return true;
 }
コード例 #15
0
ファイル: Route.php プロジェクト: fraym/core
 /**
  * @param $menuItemTranslation
  * @return bool
  * @throws \Exception
  */
 protected function setupPage($menuItemTranslation)
 {
     try {
         $this->currentMenuItemTranslation = $menuItemTranslation;
         $this->currentMenuItem = $menuItemTranslation->menuItem;
         $this->db->setTranslatableLocale($menuItemTranslation->locale->locale);
         $this->template->setSiteTemplateDir($menuItemTranslation->menuItem->site->templateDir);
         if ($this->request->isXmlHttpRequest() || $this->user->isAdmin()) {
             $localeId = $this->request->gp('locale_id');
             if ($localeId && is_numeric($localeId)) {
                 $this->locale->setLocale($localeId);
             } else {
                 $this->locale->setLocale($menuItemTranslation->locale);
             }
         } else {
             $this->locale->setLocale($menuItemTranslation->locale);
         }
         $pageTitle = (string) $menuItemTranslation->pageTitle === '' ? $menuItemTranslation->title : $menuItemTranslation->pageTitle;
         $pageTitle = str_replace('[SITE_NAME]', $menuItemTranslation->menuItem->site->name, $pageTitle);
         $this->template->setPageTitle($pageTitle);
         $this->template->setPageDescription($menuItemTranslation->description);
         $this->template->setKeywords(explode(',', $menuItemTranslation->keywords));
         setlocale(LC_ALL, $this->locale->getLocale()->locale);
     } catch (Exception $e) {
         throw new \Exception('Error setup page: ' . $e->getMessage());
     }
     return true;
 }
コード例 #16
0
ファイル: InstallController.php プロジェクト: jewelhuq/fraym
 /**
  * @return array|bool
  */
 private function initConfigurations()
 {
     $gp = $this->request->getGPAsObject();
     $errors = array();
     /**
      * create default language
      */
     $locale = new \Fraym\Locale\Entity\Locale();
     switch ($gp->locale) {
         case 'german':
             $locale->name = 'German';
             $locale->locale = 'de_DE';
             $locale->country = 'Germany';
             $locale->default = true;
             break;
         case 'french':
             $locale->name = 'French';
             $locale->locale = 'fr_FR';
             $locale->country = 'France';
             $locale->default = true;
             break;
         case 'swedish':
             $locale->name = 'swedish';
             $locale->locale = 'sv_SE';
             $locale->country = 'Sweden';
             $locale->default = true;
             break;
         case 'spanish':
             $locale->name = 'Spanish';
             $locale->locale = 'es_ES';
             $locale->country = 'Spain';
             $locale->default = true;
             break;
         default:
             // english
             $locale->name = 'English';
             $locale->locale = 'en_US';
             $locale->country = 'USA';
             $locale->default = true;
             break;
     }
     $this->db->persist($locale);
     $this->db->flush();
     $this->locale->setLocale($locale);
     $this->db->setUpTranslateable()->setUpSortable();
     /**
      * create site
      */
     $site = new \Fraym\Site\Entity\Site();
     $site->name = $gp->site->name;
     $site->caching = true;
     $site->active = true;
     $site->menuItems->clear();
     $this->db->persist($site);
     /**
      * create domain for site
      */
     $domain = new \Fraym\Site\Entity\Domain();
     $domain->site = $site;
     $domain->address = $gp->site->url;
     $this->db->persist($domain);
     $this->addMenuItems($site);
     $adminGroup = new \Fraym\User\Entity\Group();
     $adminGroup->name = $this->translation->autoTranslation('Administrator', 'en', $gp->locale);
     $adminGroup->identifier = 'Administrator';
     $this->db->persist($adminGroup);
     $adminUser = new \Fraym\User\Entity\User();
     $adminUser->updateEntity($gp->user, false);
     if (strlen($gp->user->password) < 8) {
         $errors[] = 'Password is too short.';
     } elseif ($gp->user->password === $gp->user->password_repeat) {
         $adminUser->password = $gp->user->password;
     } else {
         $errors[] = 'Passwords do not match.';
     }
     $adminUser->groups->add($adminGroup);
     $this->db->persist($adminUser);
     if (count($errors) === 0) {
         $this->db->flush();
         $this->db->clear();
         /**
          * Register extensions, default theme...
          */
         $this->registry->registerExtensions();
         /**
          * Set menuitem template -> default theme
          */
         $this->setupMenuItemTemplate();
         /**
          * Login admin user
          */
         $this->user->setUserId($adminUser->id);
         return true;
     }
     return $errors;
 }