Пример #1
0
 /**
  * @param myDoctrineQuery $query        The query used to fetch the record
  * @return myDoctrineRecord $record
  */
 protected function getRecord(dmDoctrineQuery $query)
 {
     $record = $query->fetchOne();
     if (!$record instanceof dmDoctrineRecord) {
         throw new dmException(sprintf('No record found for %s %d', $this->getDmModule(), $this->recordId));
     }
     return $record;
 }
Пример #2
0
 /**
  * Initializes the current dmContext instance.
  *
  * @param dmApplicationConfiguration $configuration  An dmApplicationConfiguration instance
  */
 public function initialize(sfApplicationConfiguration $configuration)
 {
     $this->checkProjectIsSetup();
     parent::initialize($configuration);
     sfConfig::set('dm_debug', $this->getRequest()->getParameter('dm_debug', false));
     // load the service container instance
     $this->loadServiceContainer();
     // configure the service container with its required dependencies
     $this->configureServiceContainer($this->serviceContainer);
     if (method_exists($this->configuration, 'configureServiceContainer')) {
         $this->configuration->configureServiceContainer($this->serviceContainer);
     }
     // connect the service container and its services to the event dispatcher
     $this->serviceContainer->connect();
     /*
      * dmForm requires service container...
      */
     dmForm::setServiceContainer($this->serviceContainer);
     /*
      * some classes needs the event dispatcher to communicate
      * and the service container...
      */
     dmDoctrineQuery::setModuleManager($this->getModuleManager());
     dmDoctrineTable::setServiceContainer($this->serviceContainer);
     $this->helper = $this->serviceContainer->getService('helper');
     // notify that context is ready
     $this->dispatcher->notify(new sfEvent($this, 'dm.context.loaded'));
 }
Пример #3
0
 protected function getModuleManager()
 {
     if (null === $this->moduleManager) {
         $this->configuration->getConfigCache()->registerConfigHandler('config/dm/modules.yml', 'dmModuleManagerConfigHandler');
         $mm = (include $this->configuration->getConfigCache()->checkConfig('config/dm/modules.yml'));
         dmModule::setManager($mm);
         dmDoctrineTable::setModuleManager($mm);
         dmDoctrineQuery::setModuleManager($mm);
         $this->moduleManager = $mm;
     }
     return $this->moduleManager;
 }
Пример #4
0
 /**
  * @return dmDoctrineQuery the default admin list query
  */
 public function getAdminListQuery(dmDoctrineQuery $query)
 {
     return $this->joinLocals($query->withI18n(null, $this->getComponentName()), true);
 }
Пример #5
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;
 }
Пример #6
0
 public static function setModuleManager(dmModuleManager $moduleManager)
 {
     self::$moduleManager = $moduleManager;
 }
 public function getAdminListQuery(dmDoctrineQuery $query)
 {
     return $query->withI18n();
 }
 protected function processSearchQuery(dmDoctrineQuery $query, $search)
 {
     $searchParts = explode(' ', $search);
     $rootAlias = $query->getRootAlias();
     $translationAlias = $rootAlias . 'Translation';
     $table = $this->getDmModule()->getTable();
     $query->withI18n($this->getUser()->getCulture(), $this->getDmModule()->getModel());
     foreach ($searchParts as $searchPart) {
         $ors = array();
         $params = array();
         foreach ($table->getAllColumns() as $columnName => $column) {
             $alias = $table->isI18nColumn($columnName) ? $translationAlias : $rootAlias;
             switch ($column['type']) {
                 case 'blob':
                 case 'clob':
                 case 'string':
                 case 'enum':
                 case 'date':
                     $ors[] = $alias . '.' . $columnName . ' LIKE ?';
                     $params[] = '%' . $searchPart . '%';
                     break;
                 case 'integer':
                 case 'float':
                 case 'decimal':
                     if (is_numeric($searchPart)) {
                         $ors[] = $alias . '.' . $columnName . ' = ?';
                         $params[] = $searchPart;
                     }
                     break;
                 case 'boolean':
                 case 'time':
                 case 'timestamp':
                 case 'date':
                 default:
             }
         }
         if (count($ors)) {
             $query->addWhere(implode(' OR ', $ors), $params);
         }
     }
 }
Пример #9
0
 /**
  * Will join named relations
  * @param dmDoctrineQuery $query
  * @param array $aliases
  * @param boolean $with18n
  */
 public function joinRelations($query, array $aliases, $withI18n = false)
 {
     $rootAlias = $query->getRootAlias();
     foreach ($aliases as $alias) {
         if (!($relation = $this->getRelationHolder()->get($alias))) {
             throw new dmException(sprintf('%s is not a valid alias for the table %s', $alias, $this->getComponentName()));
         }
         if ($relation->getAlias() === 'Translation') {
             $query->withI18n();
         } elseif ($relation->getClass() === 'DmMedia') {
             $mediaJoinAlias = dmString::lcfirst($relation->getAlias());
             $query->leftJoin(sprintf('%s.%s %s', $rootAlias, $relation->getAlias(), $mediaJoinAlias))->leftJoin(sprintf('%s.%s %s', $mediaJoinAlias, 'Folder', $mediaJoinAlias . 'Folder'));
         } else {
             $joinAlias = dmString::lcfirst($relation->getAlias());
             $query->leftJoin(sprintf('%s.%s %s', $rootAlias, $relation->getAlias(), $joinAlias));
             if ($withI18n && $relation->getTable()->hasI18n()) {
                 $joinTranslationAlias = $joinAlias . 'Translation';
                 $query->leftJoin($joinAlias . '.Translation ' . $joinTranslationAlias . ' ON ' . $joinAlias . '.id = ' . $joinTranslationAlias . '.id AND ' . $joinTranslationAlias . '.lang = ?', myDoctrineRecord::getDefaultCulture());
             }
         }
     }
     return $this;
 }
Пример #10
0
 public function getAdminListQuery(dmDoctrineQuery $q)
 {
     return $q->leftJoin($q->getRootAlias() . '.Areas a')->leftJoin('a.Zones z')->leftJoin('z.Widgets w')->orderBy('a.type DESC');
 }