Пример #1
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;
 }
Пример #2
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;
 }
 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);
         }
     }
 }
Пример #4
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');
 }