本文整理汇总了PHP中Table::getColumns方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::getColumns方法的具体用法?PHP Table::getColumns怎么用?PHP Table::getColumns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Table
的用法示例。
在下文中一共展示了Table::getColumns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: common
/**
* @return array
*/
public function common()
{
$origin = [];
foreach ($this->origin->getColumns() as $column) {
$origin[] = $column->getName();
}
$destination = [];
foreach ($this->destination->getColumns() as $column) {
$destination[] = $column->getName();
}
$intersection = array_intersect($origin, $destination);
sort($intersection);
return $intersection;
}
示例2: testTable
public function testTable()
{
$table = new Table($this->connection, 'foo_table', array('bar' => TableInterface::TYPE_INT), array());
$this->assertEquals('foo_table', $table->getName());
$this->assertEquals(array('bar' => TableInterface::TYPE_INT), $table->getColumns());
$this->assertEquals(array(), $table->getConnections());
$table->addConnection('bar', 'bar_table');
$this->assertEquals(array('bar' => 'bar_table'), $table->getConnections());
}
示例3: addPopulateFromVersion
protected function addPopulateFromVersion(&$script)
{
$ARclassName = $this->getActiveRecordClassName();
$versionTable = $this->behavior->getVersionTable();
$versionColumnName = $versionTable->getColumn($this->behavior->getParameter('version_column'))->getPhpName();
$versionARClassname = $this->builder->getNewStubObjectBuilder($versionTable)->getClassname();
$tablePKs = $this->table->getPrimaryKey();
$primaryKeyName = $tablePKs[0]->getPhpName();
$script .= "\n/**\n * Sets the properties of the curent object to the value they had at a specific version\n *\n * @param {$versionARClassname} \$version The version object to use\n * @param PropelPDO \$con the connection to use\n * @param array \$loadedObjects objects thats been loaded in a chain of populateFromVersion calls on referrer or fk objects.\n *\n * @return {$ARclassName} The current object (for fluent API support)\n */\npublic function populateFromVersion(\$version, \$con = null, &\$loadedObjects = array())\n{\n";
$script .= "\n \$loadedObjects['{$ARclassName}'][\$version->get{$primaryKeyName}()][\$version->get{$versionColumnName}()] = \$this;";
foreach ($this->table->getColumns() as $col) {
$script .= "\n \$this->set" . $col->getPhpName() . "(\$version->get" . $col->getPhpName() . "());";
}
foreach ($this->behavior->getVersionableFks() as $fk) {
$foreignTable = $fk->getForeignTable();
$foreignVersionTable = $fk->getForeignTable()->getBehavior($this->behavior->getName())->getVersionTable();
$relatedClassname = $this->builder->getNewStubObjectBuilder($foreignTable)->getClassname();
$relatedVersionQueryBuilder = $this->builder->getNewStubQueryBuilder($foreignVersionTable);
$this->builder->declareClassFromBuilder($relatedVersionQueryBuilder);
$relatedVersionQueryClassname = $relatedVersionQueryBuilder->getClassname();
$fkColumnName = $fk->getLocalColumnName();
$fkColumnPhpName = $fk->getLocalColumn()->getPhpName();
$fkVersionColumnPhpName = $versionTable->getColumn($fkColumnName . '_version')->getPhpName();
$fkPhpname = $this->builder->getFKPhpNameAffix($fk, $plural = false);
// FIXME: breaks lazy-loading
$script .= "\n if (\$fkValue = \$version->get{$fkColumnPhpName}()) {\n if (isset(\$loadedObjects['{$relatedClassname}']) && isset(\$loadedObjects['{$relatedClassname}'][\$fkValue]) && isset(\$loadedObjects['{$relatedClassname}'][\$fkValue][\$version->get{$fkVersionColumnPhpName}()])) {\n \$related = \$loadedObjects['{$relatedClassname}'][\$fkValue][\$version->get{$fkVersionColumnPhpName}()];\n } else {\n \$related = new {$relatedClassname}();\n \$relatedVersion = {$relatedVersionQueryClassname}::create()\n ->filterBy{$fk->getForeignColumn()->getPhpName()}(\$fkValue)\n ->filterByVersion(\$version->get{$fkVersionColumnPhpName}())\n ->findOne(\$con);\n \$related->populateFromVersion(\$relatedVersion, \$con, \$loadedObjects);\n \$related->setNew(false);\n }\n \$this->set{$fkPhpname}(\$related);\n }";
}
foreach ($this->behavior->getVersionableReferrers() as $fk) {
$foreignTable = $fk->getTable();
$foreignBehavior = $foreignTable->getBehavior($this->behavior->getName());
$foreignVersionTable = $foreignBehavior->getVersionTable();
$fkColumn = $foreignVersionTable->getFirstPrimaryKeyColumn();
$fkVersionColumn = $foreignVersionTable->getColumn($this->behavior->getParameter('version_column'));
$relatedClassname = $this->builder->getNewStubObjectBuilder($foreignTable)->getClassname();
$relatedVersionQueryBuilder = $this->builder->getNewStubQueryBuilder($foreignVersionTable);
$this->builder->declareClassFromBuilder($relatedVersionQueryBuilder);
$relatedVersionQueryClassname = $relatedVersionQueryBuilder->getClassname();
$relatedVersionPeerBuilder = $this->builder->getNewStubPeerBuilder($foreignVersionTable);
$relatedVersionPeerClassname = $relatedVersionPeerBuilder->getClassname();
if ($fk->isLocalPrimaryKey()) {
$fkPhpName = $this->builder->getRefFKPhpNameAffix($fk, $plural = false);
$fkColumnId = $this->behavior->getReferrerIdsColumn($fk);
$fkColumnVersion = $this->behavior->getReferrerVersionsColumn($fk);
$fkColumnVersionPhpName = $fkColumnVersion->getPhpName();
$this->builder->declareClassFromBuilder($relatedVersionPeerBuilder);
$script .= "\n if (\$fkValue = \$version->get{$fkColumnId->getPhpName()}()) {\n if (isset(\$loadedObjects['{$relatedClassname}']) && isset(\$loadedObjects['{$relatedClassname}'][\$fkValue]) && isset(\$loadedObjects['{$relatedClassname}'][\$fkValue][\$version->get{$fkColumnVersionPhpName}()])) {\n \$related = \$loadedObjects['{$relatedClassname}'][\$fkValue][\$version->get{$fkColumnVersionPhpName}()];\n } else {\n \$related = new {$relatedClassname}();\n \$relatedVersion = {$relatedVersionQueryClassname}::create()\n ->filterBy{$fk->getLocalColumn()->getPhpName()}(\$fkValue)\n ->filterByVersion(\$version->get{$fkColumnVersionPhpName}())\n ->findOne(\$con);\n \$related->populateFromVersion(\$relatedVersion, \$con, \$loadedObjects);\n \$related->setNew(false);\n }\n \$this->set{$fkPhpName}(\$related);\n }";
} else {
$fkPhpNames = $this->builder->getRefFKPhpNameAffix($fk, $plural = true);
$fkPhpName = $this->builder->getRefFKPhpNameAffix($fk, $plural = false);
$fkColumnIds = $this->behavior->getReferrerIdsColumn($fk);
$fkColumnVersions = $this->behavior->getReferrerVersionsColumn($fk);
$this->builder->declareClassFromBuilder($relatedVersionPeerBuilder);
$script .= "\n if (\$fkValues = \$version->get{$fkColumnIds->getPhpName()}()) {\n \$this->clear{$fkPhpNames}();\n \$fkVersions = \$version->get{$fkColumnVersions->getPhpName()}();\n \$query = {$relatedVersionQueryClassname}::create();\n foreach (\$fkValues as \$key => \$value) {\n \$c1 = \$query->getNewCriterion({$this->builder->getColumnConstant($fkColumn, $relatedVersionPeerClassname)}, \$value);\n \$c2 = \$query->getNewCriterion({$this->builder->getColumnConstant($fkVersionColumn, $relatedVersionPeerClassname)}, \$fkVersions[\$key]);\n \$c1->addAnd(\$c2);\n \$query->addOr(\$c1);\n }\n foreach (\$query->find(\$con) as \$relatedVersion) {\n if (isset(\$loadedObjects['{$relatedClassname}']) && isset(\$loadedObjects['{$relatedClassname}'][\$relatedVersion->get{$fkColumn->getPhpName()}()]) && isset(\$loadedObjects['{$relatedClassname}'][\$relatedVersion->get{$fkColumn->getPhpName()}()][\$relatedVersion->get{$fkVersionColumn->getPhpName()}()])) {\n \$related = \$loadedObjects['{$relatedClassname}'][\$relatedVersion->get{$fkColumn->getPhpName()}()][\$relatedVersion->get{$fkVersionColumn->getPhpName()}()];\n } else {\n \$related = new {$relatedClassname}();\n \$related->populateFromVersion(\$relatedVersion, \$con, \$loadedObjects);\n \$related->setNew(false);\n }\n \$this->add{$fkPhpName}(\$related);\n }\n\n \$this->resetPartial{$fkPhpNames}(false);\n }";
}
}
$script .= "\n\n return \$this;\n}\n";
}
示例4: __construct
public function __construct(Table $table, $recordIndex, $rawData = false)
{
$this->table = $table;
$this->recordIndex = $recordIndex;
$this->choppedData = array();
if ($rawData && strlen($rawData) > 0) {
$this->inserted = false;
$this->deleted = ord($rawData[0]) != '32';
foreach ($table->getColumns() as $column) {
$this->choppedData[$column->getName()] = substr($rawData, $column->getBytePos(), $column->getDataLength());
}
} else {
$this->inserted = true;
$this->deleted = false;
foreach ($table->getColumns() as $column) {
$this->choppedData[$column->getName()] = str_pad('', $column->getDataLength(), chr(0));
}
}
}
示例5: validateTableColumns
protected function validateTableColumns(Table $table)
{
if (!$table->hasPrimaryKey() && !$table->isSkipSql()) {
$this->errors[] = sprintf('Table "%s" does not have a primary key defined. Propel requires all tables to have a primary key.', $table->getName());
}
$phpNames = array();
foreach ($table->getColumns() as $column) {
if (in_array($column->getPhpName(), $phpNames)) {
$this->errors[] = sprintf('Column "%s" declares a phpName already used in table "%s"', $column->getName(), $table->getName());
}
$phpNames[] = $column->getPhpName();
}
}
示例6: getAddTableDDL
public function getAddTableDDL(Table $table)
{
$tableDescription = $table->hasDescription() ? $this->getCommentLineDDL($table->getDescription()) : '';
$lines = array();
foreach ($table->getColumns() as $column) {
$lines[] = $this->getColumnDDL($column);
}
if ($table->hasPrimaryKey() && count($table->getPrimaryKey()) > 1) {
$lines[] = $this->getPrimaryKeyDDL($table);
}
foreach ($table->getUnices() as $unique) {
$lines[] = $this->getUniqueDDL($unique);
}
$sep = ",\n\t";
$pattern = "\n%sCREATE TABLE %s\n(\n\t%s\n);\n";
return sprintf($pattern, $tableDescription, $this->quoteIdentifier($table->getName()), implode($sep, $lines));
}
示例7: computeAlter
/**
* @param Table $old
* @param Table $new
* @return bool|string
*/
public static function computeAlter(Table $old, Table $new)
{
$oldColumnNames = array_keys($old->getColumns());
$newColumnNames = array_keys($new->getColumns());
$alterLines = [];
// Check for changed columns
$possiblyChangedColumnNames = array_intersect($oldColumnNames, $newColumnNames);
foreach ($possiblyChangedColumnNames as $possiblyChangedColumnName) {
$oldColumn = $old->getColumn($possiblyChangedColumnName);
$newColumn = $new->getColumn($possiblyChangedColumnName);
if ($oldColumn && $newColumn) {
$alter = Column::computeAlter($oldColumn, $newColumn);
if ($alter) {
$alterLines[] = $alter;
}
}
}
// check if columns have been added
$addedColumnNames = array_diff($newColumnNames, $oldColumnNames);
foreach ($addedColumnNames as $added) {
$column = $new->getColumn($added);
$query = "ADD COLUMN " . $column;
if ($column->isFirst()) {
$query .= " FIRST";
} elseif ($column->getAfter() !== false) {
$query .= " AFTER `" . $column->getAfter() . "`";
}
$alterLines[] = $query;
}
// check if columns have been removed
$removedColumnNames = array_diff($oldColumnNames, $newColumnNames);
foreach ($removedColumnNames as $removedColumnName) {
$alterLines[] = "DROP COLUMN `" . $removedColumnName . "`";
}
if (!empty($alterLines)) {
return "ALTER TABLE `" . $new->getName() . "`\n\t" . implode(",\n\t", $alterLines);
}
return false;
}
示例8: getAddTableDDL
public function getAddTableDDL(Table $table)
{
$lines = array();
foreach ($table->getColumns() as $column) {
$lines[] = $this->getColumnDDL($column);
}
if ($table->hasPrimaryKey()) {
$lines[] = $this->getPrimaryKeyDDL($table);
}
foreach ($table->getUnices() as $unique) {
$lines[] = $this->getUniqueDDL($unique);
}
foreach ($table->getIndices() as $index) {
$lines[] = $this->getIndexDDL($index);
}
foreach ($table->getForeignKeys() as $foreignKey) {
if ($foreignKey->isSkipSql()) {
continue;
}
$lines[] = str_replace("\n\t", "\n\t\t", $this->getForeignKeyDDL($foreignKey));
}
$vendorSpecific = $table->getVendorInfoForType('mysql');
if ($vendorSpecific->hasParameter('Type')) {
$mysqlTableType = $vendorSpecific->getParameter('Type');
} elseif ($vendorSpecific->hasParameter('Engine')) {
$mysqlTableType = $vendorSpecific->getParameter('Engine');
} else {
$mysqlTableType = $this->getDefaultTableEngine();
}
$tableOptions = $this->getTableOptions($table);
if ($table->getDescription()) {
$tableOptions[] = 'COMMENT=' . $this->quote($table->getDescription());
}
$tableOptions = $tableOptions ? ' ' . implode(' ', $tableOptions) : '';
$sep = ",\n\t";
$pattern = "\nCREATE TABLE %s\n(\n\t%s\n) %s=%s%s;\n";
return sprintf($pattern, $this->quoteIdentifier($table->getName()), implode($sep, $lines), $this->getTableEngineKeyword(), $mysqlTableType, $tableOptions);
}
示例9: hasPrimaryString
/**
* Checks whether the supplied table has a primary string defined.
*
* @param Table $table
*
* @return boolean
*/
protected function hasPrimaryString(Table $table)
{
foreach ($table->getColumns() as $column) {
if ($column->isPrimaryString()) {
return true;
}
}
return false;
}
示例10: Table
$profiles = get_profiles();
$detail_url = 'index.php?' . PAG_INDEX . '=' . $pages_refs['ms_profile_details'] . '&profile_id=';
$delete_url = 'index.php?' . PAG_INDEX . '=' . $pages_refs['ms_profiles'] . '&action=delete&profile_id=';
$table = new Table($form_name);
$table->addColumn(new CheckboxColumn('name'));
$table->addColumn(new LinkColumn('name', $l->g(1402), $detail_url, array('required' => true, 'idProperty' => 'name')));
$table->addColumn(new LinkColumn('label_translated', $l->g(1411), $detail_url, array('required' => true, 'idProperty' => 'name')));
$table->addColumn(new ActionsColumn(array($detail_url => 'glyphicon glyphicon-edit', $delete_url => 'glyphicon glyphicon-remove'), 'name'));
if (AJAX) {
$ajax = true;
parse_str($protectedPost['ocs']['0'], $params);
$protectedPost += $params;
$data = array();
foreach ($profiles as $profile) {
$profileData = array();
foreach ($table->getColumns() as $name => $col) {
$profileData[$name] = $col->format($profile);
}
$data[] = $profileData;
}
// JSON OUTPUT
$response = array('customized' => false, 'draw' => $_POST['draw'], 'data' => $data, 'recordsFiltered' => count($profiles), 'recordsTotal' => count($profiles));
echo json_encode($response);
} else {
$ajax = false;
require_once 'views/users_views.php';
require_once 'require/function_search.php';
require_once 'require/tables/TableRenderer.php';
// HTML OUTPUT
show_users_left_menu('ms_profiles');
echo '<div class="right-content">';
示例11: buildColumnList
/**
* Build SQL column list
* @param Table $table
* @return string
*/
protected function buildColumnList(Table $table)
{
$columns = '';
foreach ($table->getColumns() as $column) {
$columns .= ",\n\t{$column->getSQLExpression()}";
}
return substr($columns, 3);
// remove first ', '
}
示例12: getAddColumnsComments
protected function getAddColumnsComments(Table $table)
{
$ret = '';
foreach ($table->getColumns() as $column) {
$ret .= $this->getAddColumnComment($column);
}
return $ret;
}
示例13: testRemoveColumnFixesPositions
public function testRemoveColumnFixesPositions()
{
$table = new Table();
$col1 = new Column('Foo1');
$table->addColumn($col1);
$col2 = new Column('Foo2');
$table->addColumn($col2);
$col3 = new Column('Foo3');
$table->addColumn($col3);
$this->assertEquals(1, $col1->getPosition());
$this->assertEquals(2, $col2->getPosition());
$this->assertEquals(3, $col3->getPosition());
$this->assertEquals(array(0, 1, 2), array_keys($table->getColumns()));
$table->removeColumn($col2);
$this->assertEquals(1, $col1->getPosition());
$this->assertEquals(2, $col3->getPosition());
$this->assertEquals(array(0, 1), array_keys($table->getColumns()));
}
示例14: getAddTableDDL
public function getAddTableDDL(Table $table)
{
$tableDescription = $table->hasDescription() ? $this->getCommentLineDDL($table->getDescription()) : '';
$lines = array();
foreach ($table->getColumns() as $column) {
$lines[] = $this->getColumnDDL($column);
}
foreach ($table->getUnices() as $unique) {
$lines[] = $this->getUniqueDDL($unique);
}
$sep = ",\r\n ";
$pattern = "\r\n%sCREATE TABLE %s\r\n(\r\n %s\r\n)%s;\r\n";
$ret = sprintf($pattern, $tableDescription, $this->quoteIdentifier($table->getName()), implode($sep, $lines), $this->generateBlockStorage($table));
$ret .= $this->getAddPrimaryKeyDDL($table);
$ret .= $this->getAddSequencesDDL($table);
return $ret;
}
示例15: manyToMany
/**
* Create a relation where each record has many linked records in another table but using a liking table
* @param Table $toTable the related table definition
* @param Table $pivot the pivot table definition
* @param string|null $name the name of the relation (defaults to the related table name)
* @param string|array|null $toTableColumn the local columns pointing to the pivot table
* @param string|array|null $localColumn the pivot columns pointing to the related table PK
* @return self
*/
public function manyToMany(Table $toTable, Table $pivot, $name = null, $toTableColumn = null, $localColumn = null) : Table
{
$pivotColumns = $pivot->getColumns();
$keymap = [];
if (!isset($toTableColumn)) {
$toTableColumn = [];
}
if (!is_array($toTableColumn)) {
$toTableColumn = [$toTableColumn];
}
foreach ($this->getPrimaryKey() as $k => $pkField) {
$key = null;
if (isset($toTableColumn[$pkField])) {
$key = $toTableColumn[$pkField];
} elseif (isset($toTableColumn[$k])) {
$key = $toTableColumn[$k];
} else {
$key = $this->getName() . '_' . $pkField;
}
if (!in_array($key, $pivotColumns)) {
throw new DatabaseException('Missing foreign key mapping');
}
$keymap[$pkField] = $key;
}
$pivotKeymap = [];
if (!isset($localColumn)) {
$localColumn = [];
}
if (!is_array($localColumn)) {
$localColumn = [$localColumn];
}
foreach ($toTable->getPrimaryKey() as $k => $pkField) {
$key = null;
if (isset($localColumn[$pkField])) {
$key = $localColumn[$pkField];
} elseif (isset($localColumn[$k])) {
$key = $localColumn[$k];
} else {
$key = $toTable->getName() . '_' . $pkField;
}
if (!in_array($key, $pivotColumns)) {
throw new DatabaseException('Missing foreign key mapping');
}
$pivotKeymap[$key] = $pkField;
}
if (!isset($name)) {
$name = $toTable->getName() . '_' . implode('_', array_keys($keymap));
}
$this->relations[$name] = ['name' => $name, 'table' => $toTable, 'keymap' => $keymap, 'many' => true, 'pivot' => $pivot, 'pivot_keymap' => $pivotKeymap, 'sql' => null, 'par' => []];
return $this;
}