private static function getForeignColsSelection($class, $selectedColumns, $refTables) { $tableMap = afMetaDb::getTableMap($class); $duplication = false; $joined = array(); $selectedFCols = array(); $excludedFCols = array(); foreach ($tableMap->getColumns() as $col) { $relatedTable = $col->getRelatedTableName(); if ($relatedTable) { if (in_array($relatedTable, $refTables) || in_array(strtolower($col->getName()), $selectedColumns)) { if (isset($joined[$relatedTable])) { // It prevents multiple joins to the same table. $duplication = true; $excludedFCols[] = $col; } else { $joined[$relatedTable] = true; $selectedFCols[] = $col; } } else { $excludedFCols[] = $col; } } } return array($duplication, $selectedFCols, $excludedFCols); }
public function setSort($column, $sortDir = 'ASC') { $this->initialized = false; $tableMap = afMetaDb::getTableMap($this->class); $this->sortDir = $sortDir; if (!StringUtil::isIn('.', $column) && $tableMap->hasColumn($column)) { $this->sortColumn = $column; $this->sortColumn = $tableMap->getColumn($column)->getFullyQualifiedName(); } else { $this->sortColumn = false; } }
public static function _getPhpName($dbName, $tableName) { if (!isset(self::$dbschema)) { $root = sfConfig::get("sf_root_dir"); self::$dbschema = sfYaml::load($root . '/config/schema.yml'); } if (isset(self::$dbschema[$dbName][$tableName]['_attributes']['phpName'])) { $phpName = self::$dbschema[$dbName][$tableName]['_attributes']['phpName']; } else { $phpName = sfInflector::camelize($tableName); } return $phpName; }
private function createGetter($tableMap, $column) { if ($tableMap->containsColumn($column)) { $col = $tableMap->getColumn($column); if ($col->getRelatedTableName()) { $methodName = afMetaDb::getRelatedMethodName($col); $getter = $this->createMethodGetter($methodName); } else { $methodName = 'get' . $col->getPhpName(); if ($col->isTemporal()) { $getter = new afDatetimeGetter($methodName); } else { $getter = $this->createMethodGetter($methodName); } } } else { $methodName = 'get' . sfInflector::camelize($column); $getter = $this->createMethodGetter($methodName, in_array($column, $this->specialColumns)); } return $getter; }
<?php include dirname(__FILE__) . '/../bootstrap/dbunit.php'; $t = new lime_test(2, new lime_output_color()); $colMap = EventInfoPeer::getTableMap()->getColumn('publisher_id'); $t->is(afMetaDb::getRelatedMethodName($colMap), 'getPublisher'); $colMap = EventInfoPeer::getTableMap()->getColumn('confidentiality_id'); $t->is(afMetaDb::getRelatedMethodName($colMap), 'getEventImpactRelatedByConfidentialityId');