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());
 }
 /**
  * If the attribute is not on the same model class but nested up, it should be blocked from being configured
  * in the designer tool since it can have side effects. You can still manually override this in the code if
  * necessary.
  */
 protected function isAttributeOnModelOrCastedUp($attributeName)
 {
     assert('is_string($attributeName)');
     $attributeAdapter = new RedBeanModelAttributeToDataProviderAdapter($this->modelClassName, $attributeName);
     if (!$attributeAdapter->getModel()->isAttribute($attributeName)) {
         return false;
     }
     if ($attributeAdapter->getAttributeModelClassName() != $this->modelClassName) {
         return true;
     }
     return false;
 }
예제 #3
0
 /**
  * @param $modelToReportAdapter
  * @param $modelAttributeToDataProviderAdapter
  * @param string $modelClassName
  * @param string $realAttributeName
  */
 protected function resolveCastingHintForAttribute($modelToReportAdapter, $modelAttributeToDataProviderAdapter, $modelClassName, $realAttributeName)
 {
     assert('$modelToReportAdapter instanceof ModelRelationsAndAttributesToReportAdapter');
     $hintAdapter = new RedBeanModelAttributeToDataProviderAdapter($modelClassName, $realAttributeName);
     $hintModelClassName = $hintAdapter->getAttributeModelClassName();
     $modelAttributeToDataProviderAdapter->setCastingHintModelClassNameForAttribute($hintModelClassName);
 }
예제 #4
0
 /**
  * @param $onTableAliasName
  * @return null|string
  */
 protected function addLeftJoinsForAttributeThatIsCastedUp($onTableAliasName)
 {
     $modelClassName = $this->modelAttributeToDataProviderAdapter->getResolvedModelClassName();
     $attributeModelClassName = $this->modelAttributeToDataProviderAdapter->getAttributeModelClassName();
     return $this->resolveAndProcessLeftJoinsForAttributeThatIsCastedUp($onTableAliasName, $modelClassName, $attributeModelClassName);
 }
예제 #5
0
 /**
  * For both non related and related attributes, this method resolves whether a from join is needed.  This occurs
  * for example if a model attribute is castedUp. And that attribute is a relation that needs to be joined in
  * order to search.  Since that attribute is castedUp, the castedUp model needs to be from joined first.  This
  * also applies if the attribute is not a relation and just a member on the castedUp model. In that scenario,
  * the castedUp model also needs to be joined.
  *
  * This methhod assumes if the attribute is not on the base model, that it is casted up not down from it.
  */
 public static function resolveShouldAddFromTableAndGetAliasName(RedBeanModelAttributeToDataProviderAdapter $modelAttributeToDataProviderAdapter, RedBeanModelJoinTablesQueryAdapter $joinTablesAdapter)
 {
     $attributeTableName = $modelAttributeToDataProviderAdapter->getAttributeTableName();
     $tableAliasName = $attributeTableName;
     if ($modelAttributeToDataProviderAdapter->getModelClassName() == 'User' && $modelAttributeToDataProviderAdapter->getAttributeModelClassName() == 'Person') {
         $modelTableName = $modelAttributeToDataProviderAdapter->getModelTableName();
         if (!$joinTablesAdapter->isTableInFromTables('person')) {
             $personTableName = $attributeTableName;
             $joinTablesAdapter->addFromTableAndGetAliasName($personTableName, "{$personTableName}_id", $modelTableName);
         }
     } elseif ($modelAttributeToDataProviderAdapter->getAttributeModelClassName() != $modelAttributeToDataProviderAdapter->getModelClassName()) {
         $modelClassName = $modelAttributeToDataProviderAdapter->getModelClassName();
         while (get_parent_class($modelClassName) != $modelAttributeToDataProviderAdapter->getAttributeModelClassName()) {
             $castedDownModelClassName = $modelClassName;
             $modelClassName = get_parent_class($modelClassName);
             $castedUpAttributeTableName = $modelClassName::getTableName($modelClassName);
             if (!$joinTablesAdapter->isTableInFromTables($castedUpAttributeTableName)) {
                 $joinTablesAdapter->addFromTableAndGetAliasName($castedUpAttributeTableName, "{$castedUpAttributeTableName}_id", $castedDownModelClassName::getTableName($castedDownModelClassName));
             }
         }
         if (!$joinTablesAdapter->isTableInFromTables($attributeTableName)) {
             $tableAliasName = $joinTablesAdapter->addFromTableAndGetAliasName($attributeTableName, "{$attributeTableName}_id", $modelClassName::getTableName($modelClassName));
         }
     }
     return $tableAliasName;
 }