/**
  * @param RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter
  * @return string
  */
 protected static function resolveSortColumnName(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter)
 {
     if ($modelAttributeToDataProviderAdapter->hasRelatedAttribute()) {
         return $modelAttributeToDataProviderAdapter->getRelatedAttributeColumnName();
     } else {
         return $modelAttributeToDataProviderAdapter->getColumnName();
     }
 }
예제 #2
0
 /**
  * @param null $onTableAliasName
  * @param bool $canUseFromJoins
  * @return null|string
  */
 public function resolveJoins($onTableAliasName = null, $canUseFromJoins = true)
 {
     assert('is_string($onTableAliasName) || $onTableAliasName == null');
     assert('is_bool($canUseFromJoins)');
     $onTableAliasName = $this->resolveOnTableAliasName($onTableAliasName);
     $this->tableAliasNameForBaseModel = $onTableAliasName;
     $onTableAliasName = $this->resolveJoinsForAttribute($onTableAliasName, $canUseFromJoins);
     $this->resolvedOnTableAliasName = $onTableAliasName;
     if ($this->modelAttributeToDataProviderAdapter->hasRelatedAttribute()) {
         $modelAttributeToDataProviderAdapter = new RedBeanModelAttributeToDataProviderAdapter($this->modelAttributeToDataProviderAdapter->getRelationModelClassNameThatCanHaveATable(), $this->modelAttributeToDataProviderAdapter->getRelatedAttribute());
         $builderClassName = get_class($this);
         $builder = new $builderClassName($modelAttributeToDataProviderAdapter, $this->joinTablesAdapter);
         $this->tableAliasNameForRelatedModel = $onTableAliasName;
         $onTableAliasName = $builder->resolveJoinsForAttribute($onTableAliasName, false);
     }
     return $onTableAliasName;
 }
 public function testAllMethodsOnAttributeOnSameModelAndRelatedAttribute()
 {
     $adapter = new RedBeanModelAttributeToDataProviderAdapter('I', 'j', 'jMember');
     $this->assertEquals('I', $adapter->getModelClassName());
     $this->assertEquals('j', $adapter->getAttribute());
     $this->assertEquals('jMember', $adapter->getRelatedAttribute());
     $this->assertEquals('i', $adapter->getModelTableName());
     $this->assertEquals('I', $adapter->getAttributeModelClassName());
     $this->assertEquals('i', $adapter->getAttributeTableName());
     $this->assertEquals('j_id', $adapter->getColumnName());
     $this->assertTrue($adapter->isRelation());
     $this->assertTrue($adapter->hasRelatedAttribute());
     $this->assertEquals('J', $adapter->getRelationModelClassName());
     $this->assertEquals('J', $adapter->getRelatedAttributeModelClassName());
     $this->assertEquals('j', $adapter->getRelationTableName());
     $this->assertEquals('j', $adapter->getRelatedAttributeTableName());
     $this->assertEquals('jmember', $adapter->getRelatedAttributeColumnName());
     $this->assertFalse($adapter->isRelatedAttributeRelation());
 }
예제 #4
0
 public static function resolveSortAttributeColumnName(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter)
 {
     if ($modelAttributeToDataProviderAdapter->isRelation()) {
         if (!$modelAttributeToDataProviderAdapter->hasRelatedAttribute()) {
             throw new NotSupportedException();
         }
         assert('$modelAttributeToDataProviderAdapter->getRelationType() != RedBeanModel::MANY_MANY');
         $onTableAliasName = self::resolveShouldAddFromTableAndGetAliasName($modelAttributeToDataProviderAdapter, $joinTablesAdapter);
         $tableAliasName = self::resolveJoinsForRelatedAttributeAndGetRelationAttributeTableAliasName($modelAttributeToDataProviderAdapter, $joinTablesAdapter, $onTableAliasName);
         $resolvedSortColumnName = $modelAttributeToDataProviderAdapter->getRelatedAttributeColumnName();
     } else {
         $tableAliasName = self::resolveShouldAddFromTableAndGetAliasName($modelAttributeToDataProviderAdapter, $joinTablesAdapter);
         $resolvedSortColumnName = $modelAttributeToDataProviderAdapter->getColumnName();
     }
     $sort = DatabaseCompatibilityUtil::quoteString($tableAliasName);
     $sort .= '.';
     $sort .= DatabaseCompatibilityUtil::quoteString($resolvedSortColumnName);
     return $sort;
 }
 /**
  * If the $onTableAliasName is used (not null):
  * Special use of group by attribute resolution. If you are resolving a group by attribute against a relation then
  * the joins must utilize a left join in the case of casting up.  Does not support when the attribute is a
  * relation itself as this expects any relation processing to be done before this is called.
  *
  * @param RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter
  * @param RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter
  * @param null | string $onTableAliasName
  * @return string
  * @throws NotSupportedException
  */
 public static function resolveGroupByAttributeColumnName(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter, $onTableAliasName = null)
 {
     assert('is_string($onTableAliasName) || $onTableAliasName == null');
     $builder = new ModelJoinBuilder($modelAttributeToDataProviderAdapter, $joinTablesAdapter);
     $tableAliasName = $builder->resolveJoins($onTableAliasName, self::resolveCanUseFromJoins($onTableAliasName));
     if ($modelAttributeToDataProviderAdapter->hasRelatedAttribute()) {
         $resolvedGroupByColumnName = $modelAttributeToDataProviderAdapter->getRelatedAttributeColumnName();
     } else {
         $resolvedGroupByColumnName = $modelAttributeToDataProviderAdapter->getColumnName();
     }
     return self::resolveGroupByColumnNameString($tableAliasName, $resolvedGroupByColumnName);
 }
 /**
  * @param RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter
  * @param ModelJoinBuilder $builder
  * @return string
  */
 protected function resolvedTableAliasName(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter, ModelJoinBuilder $builder)
 {
     if ($modelAttributeToDataProviderAdapter->hasRelatedAttribute()) {
         return $builder->getTableAliasNameForRelatedModel();
     } else {
         return $builder->getTableAliasNameForBaseModel();
     }
 }