Ejemplo n.º 1
0
 public function execute($threadClass, array $threadOptions = array())
 {
     if (!isset($threadOptions['culture'])) {
         $threadOptions['culture'] = dmDoctrineRecord::getDefaultCulture();
     }
     $command = $this->getCommand($threadClass, $threadOptions);
     if (!$this->filesystem->exec($command)) {
         throw new dmThreadException(sprintf("Thread %s failed ( app: %s, env: %s )\ncommand : %s\nmessage : %s", $threadClass, $this->options['app'], $this->options['env'], $this->getLastExec('command'), $this->getLastExec('output')));
     }
 }
Ejemplo n.º 2
0
 /**
  * Will join all relations
  * @return myDoctrineQuery
  */
 public function joinAll(dmDoctrineQuery $query = null)
 {
     if ($query instanceof dmDoctrineQuery) {
         $rootAlias = $query->getRootAlias();
     } else {
         $query = $this->createQuery($rootAlias = 'q');
     }
     foreach ($this->getRelationHolder()->getAll() as $relation) {
         if ($relation->getAlias() === 'Version' && $this->isVersionable()) {
             continue;
         } elseif ($relation->getAlias() === 'Translation') {
             $query->withI18n();
         } elseif ($relation->getClass() === 'DmMedia') {
             if ($relation instanceof Doctrine_Relation_Association && $this->hasTemplate('DmGallery')) {
                 continue;
             }
             $query->withDmMedia($relation->getAlias());
         } else {
             if ($relation instanceof Doctrine_Relation_ForeignKey) {
                 if ($this->getRelationHolder()->getAssociationByRefClass($relation->getClass())) {
                     continue;
                 }
             }
             $joinAlias = dmString::lcfirst($relation->getAlias());
             $query->leftJoin(sprintf('%s.%s %s', $rootAlias, $relation->getAlias(), $joinAlias));
             if ($relation->getTable()->hasRelation('Translation')) {
                 $joinI18nAlias = $joinAlias . 'Translation';
                 $query->leftJoin(sprintf('%s.%s %s WITH %s.lang = ?', $joinAlias, 'Translation', $joinI18nAlias, $joinI18nAlias), dmDoctrineRecord::getDefaultCulture());
             }
         }
     }
     return $query;
 }
Ejemplo n.º 3
0
 /**
  * Create current i18n form
  */
 protected function createI18nForm($culture = null)
 {
     if (!$this->isI18n()) {
         throw new dmException(sprintf('The model "%s" is not internationalized.', $this->getModelName()));
     }
     $i18nFormClass = $this->getI18nFormClass();
     $culture = null === $culture ? dmDoctrineRecord::getDefaultCulture() : $culture;
     // translation already set, use it
     if ($this->object->get('Translation')->contains($culture)) {
         $translation = $this->object->get('Translation')->get($culture);
     } else {
         $translation = $this->object->get('Translation')->get($culture);
         // populate new translation with fallback values
         if (!$translation->exists()) {
             if ($fallback = $this->object->getI18nFallBack()) {
                 $fallBackData = $fallback->toArray();
                 unset($fallBackData['id'], $fallBackData['lang']);
                 $translation->fromArray($fallBackData);
             }
         }
     }
     $i18nForm = new $i18nFormClass($translation);
     unset($i18nForm['id'], $i18nForm['lang']);
     return $i18nForm;
 }
Ejemplo n.º 4
0
 public function findOneBySlug($slug, $culture = null)
 {
     return $this->createQuery('p')->innerJoin('p.Translation t')->where('t.slug = ?', $slug)->andWhere('t.lang = ?', $culture ? $culture : dmDoctrineRecord::getDefaultCulture())->fetchOne();
 }
Ejemplo n.º 5
0
 protected function getRandomLink()
 {
     if (mt_rand(0, 1)) {
         return sprintf('http://' . dmString::random() . '.random.com');
     }
     if (!class_exists('DmPageTranslation', false)) {
         new DmPage();
     }
     $page = dmDb::query('DmPageTranslation p')->select('p.id, p.name, p.lang, RANDOM() AS rand')->where('p.lang = ?', dmDoctrineRecord::getDefaultCulture())->orderBy('rand')->limit(1)->fetchPDO();
     return sprintf('page:%d %s', $page[0][0], $page[0][1]);
 }
Ejemplo n.º 6
0
 public function createUniqueSlug($slug, $id, $parentSlug = null)
 {
     if (null === $parentSlug) {
         $parentSlug = $this->getI18nTable()->createQuery('pt')->where('pt.id = ?', $this->findOneById($id)->getNodeParentId())->andWhere('pt.lang = ?', dmDoctrineRecord::getDefaultCulture())->select('pt.slug')->fetchValue();
     }
     if ($slug == $parentSlug) {
         $slug .= '/' . $id;
     } else {
         $slug .= '-' . $id;
     }
     return $slug;
 }
 protected function getDefaultConfig()
 {
     return array_merge(array('language' => dmDoctrineRecord::getDefaultCulture()), sfConfig::get('dm_ckeditor_config'));
 }