getDefaultCulture() public static method

Return the default culture
public static getDefaultCulture ( ) : string
return string the default culture
 public function getDocument()
 {
     if (!$this->shouldIndex()) {
         $this->getSearch()->getEventDispatcher()->notify(new sfEvent($this, 'indexer.log', array('model "%s" cancelled indexation - primary key = %s', $this->getModelName(), current($this->getModel()->identifier()))));
         return false;
     }
     $old_culture = null;
     // automatic symfony i18n detection
     if ($this->getModel()->getTable()->hasRelation('Translation')) {
         $old_culture = sfDoctrineRecord::getDefaultCulture();
         sfDoctrineRecord::setDefaultCulture($this->getSearch()->getParameter('culture'));
     }
     // build document
     $doc = $this->getBaseDocument();
     $doc = $this->configureDocumentFields($doc);
     //$doc = $this->configureDocumentCategories($doc);
     $doc = $this->configureDocumentMetas($doc);
     // add document
     $doc->setField('sfl_guid', $this->getModelGuid());
     // restore culture in symfony i18n detection
     if ($old_culture) {
         sfDoctrineRecord::setDefaultCulture($old_culture);
     }
     return $doc;
 }
Example #2
0
 public function executeTemplate(sfWebRequest $request)
 {
     $this->name = $request->getParameter('name', '');
     if ('' !== $this->name) {
         $this->forward404Unless(in_array($this->name, $this->generateMailTemplateNames($this->config)));
     }
     $obj = Doctrine::getTable('NotificationMail')->findOneByName($this->name);
     if (!$obj) {
         $obj = Doctrine::getTable('NotificationMail')->create(array('name' => $this->name));
     }
     $translation = $obj->Translation[sfDoctrineRecord::getDefaultCulture()];
     $this->form = new NotificationMailTranslationForm($translation);
     $this->form->updateDefaultsByConfig($this->getMailConfiguration($this->config, $this->name));
     if ($this->request->isMethod(sfWebRequest::POST)) {
         $this->form->bind($request->getParameter('notification_mail_translation'));
         if ($this->form->isValid()) {
             if (!$this->form->getObject()->exists()) {
                 if ($this->form->getObject()->id instanceof Doctrine_Record) {
                     $this->form->getObject()->id->save();
                 }
             }
             $this->form->save();
             $this->getUser()->setFlash('notice', 'Saved.');
             $this->redirect('@mail_template_specified?name=' . $this->name);
         }
         $this->getUser()->setFlash('error', (string) $this->form->getErrorSchema());
     }
 }
 /**
  * Update changed documentation pages in database
  */
 protected function updateDatabase($branch)
 {
     $types = dmDb::query('Doc d')->select('d.type')->distinct()->fetchFlat();
     $cultures = sfConfig::get('dm_i18n_cultures');
     $originalCulture = sfDoctrineRecord::getDefaultCulture();
     foreach ($types as $type) {
         foreach ($cultures as $culture) {
             sfDoctrineRecord::setDefaultCulture($culture);
             $dir = dmOs::join($this->repo->getDir(), $type, $culture);
             $files = sfFinder::type('file')->name('/^\\d{2}\\s-\\s.+\\.markdown$/')->in($dir);
             foreach ($files as $file) {
                 $docName = preg_replace('/^\\d{2}\\s-\\s(.+)\\.markdown$/', '$1', basename($file));
                 $docRecord = dmDb::query('DocPage dp')->withI18n()->innerJoin('dp.Doc doc')->innerJoin('doc.Branch branch')->where('branch.number = ?', $branch)->andWhere('doc.type = ?', $type)->andWhere('dpTranslation.name = ?', $docName)->fetchOne();
                 if ($docRecord) {
                     $docText = file_get_contents($file);
                     if ($docRecord->text != $docText) {
                         $docRecord->text = $docText;
                         $docRecord->save();
                     }
                 }
             }
         }
     }
     sfDoctrineRecord::setDefaultCulture($originalCulture);
 }
 /**
  * Call get on Translation relationship.
  *
  * Allow access to I18n properties from the main object.
  *
  * @param Doctrine_Record $record
  * @param string          $name   Name of the property
  */
 public function filterGet(Doctrine_Record $record, $name)
 {
     $culture = sfDoctrineRecord::getDefaultCulture();
     if (isset($record['Translation'][$culture]) && '' != $record['Translation'][$culture][$name]) {
         return $record['Translation'][$culture][$name];
     }
     $defaultCulture = sfConfig::get('sf_default_culture');
     return $record['Translation'][$defaultCulture][$name];
 }
Example #5
0
 /**
  * Добавить JOIN к таблице переводов
  *
  * @param  string         $alias - алиас к таблице, которую надо перевести
  * @return Doctrine_Query
  */
 public function withI18n($alias = null)
 {
     if (null === $alias) {
         $alias = $this->getRootAlias();
     }
     $transAlias = $this->getTransAlias($alias);
     //$this->innerJoin("{$alias}.Translation {$transAlias} WITH {$transAlias}.lang = ?",
     $this->leftJoin("{$alias}.Translation {$transAlias} WITH {$transAlias}.lang = ?", sfDoctrineRecord::getDefaultCulture());
     return $this;
 }
 public function fetchTemplate($templateName)
 {
     $object = $this->findOneByName($templateName);
     if (!($object && $object->getTemplate())) {
         if (($sample = $this->fetchTemplateFromConfigSample($templateName)) && $sample[1]) {
             $object = new NotificationMail();
             $object->Translation[sfDoctrineRecord::getDefaultCulture()]->title = $sample[0];
             $object->Translation[sfDoctrineRecord::getDefaultCulture()]->template = $sample[1];
         }
     }
     return $object;
 }
Example #7
0
 /**
  * Добавить JOIN к таблице переводов
  *
  * @param  Doctrine_Query $q
  * @param  string         $rootAlias - алиас к таблице, которую надо перевести
  * @return Doctrine_Query
  */
 public function withI18n(Doctrine_Query $q = null, $rootAlias = null)
 {
     if (!$q) {
         $q = $this->createQuery($rootAlias);
     }
     if (!$rootAlias) {
         $rootAlias = $q->getRootAlias();
     }
     $transAlias = $this->getTranslationQueryAlias($rootAlias);
     $q->leftJoin("{$rootAlias}.Translation {$transAlias} WITH {$transAlias}.lang = ?", sfDoctrineRecord::getDefaultCulture());
     return $q;
 }
 /**
  * Implementation of filterGet() to call get on Translation relationship to allow
  * access to I18n properties from the main object.
  *
  * @param Doctrine_Record $record
  * @param string $name Name of the property
  * @param string $value Value of the property
  * @return void
  */
 public function filterGet(Doctrine_Record $record, $name)
 {
     return $record['Translation'][sfDoctrineRecord::getDefaultCulture()][$name];
 }
 /**
  * @param  string $name        The element name
  * @param  string $value       The date displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 protected function configure($options = array(), $attributes = array())
 {
     $options['culture'] = isset($options['culture']) ? $options['culture'] : sfDoctrineRecord::getDefaultCulture();
     parent::configure($options, $attributes);
     $this->setOption('culture', $options['culture']);
 }