public function setDefaultSortColumn(Column $col, $direction = false) { if ($direction != false) { $col->setColumnDefaultSortDirection($direction); } $this->defaultSortColumn = $col; }
public function removeSubColumn(Column $column) { $this->subColumns = array_values(array_filter($this->subColumns, function ($elm) use($column) { return $elm->getName() !== $column->getName(); })); return $this; }
public function create_column(&$column) { $c = new Column(); $c->inflected_name = Inflector::instance()->variablize($column['field']); $c->name = $column['field']; $c->nullable = $column['null'] === 'YES' ? true : false; $c->pk = $column['key'] === 'PRI' ? true : false; $c->auto_increment = $column['extra'] === 'auto_increment' ? true : false; if ($column['type'] == 'timestamp' || $column['type'] == 'datetime') { $c->raw_type = 'datetime'; $c->length = 19; } elseif ($column['type'] == 'date') { $c->raw_type = 'date'; $c->length = 10; } else { preg_match('/^([A-Za-z0-9_]+)(\\(([0-9]+(,[0-9]+)?)\\))?/', $column['type'], $matches); $c->raw_type = count($matches) > 0 ? $matches[1] : $column['type']; if (count($matches) >= 4) { $c->length = intval($matches[3]); } } $c->map_raw_type(); $c->default = $c->cast($column['default']); return $c; }
/** * Adds Columns to the specified table. * * @param Table $table The Table model class to add columns to. */ protected function addColumns(Table $table) { $stmt = $this->dbh->query("sp_columns '" . $table->getName() . "'"); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $name = $row['COLUMN_NAME']; $type = $row['TYPE_NAME']; $size = $row['LENGTH']; $is_nullable = $row['NULLABLE']; $default = $row['COLUMN_DEF']; $precision = $row['PRECISION']; $scale = $row['SCALE']; $autoincrement = false; if (strtolower($type) == "int identity") { $autoincrement = true; } $propelType = $this->getMappedPropelType($type); if (!$propelType) { $propelType = Column::DEFAULT_TYPE; $this->warn("Column [" . $table->getName() . "." . $name . "] has a column type (" . $type . ") that Propel does not support."); } $column = new Column($name); $column->setTable($table); $column->setDomainForType($propelType); // We may want to provide an option to include this: // $column->getDomain()->replaceSqlType($type); $column->getDomain()->replaceSize($size); $column->getDomain()->replaceScale($scale); if ($default !== null) { $column->getDomain()->setDefaultValue(new ColumnDefaultValue($default, ColumnDefaultValue::TYPE_VALUE)); } $column->setAutoIncrement($autoincrement); $column->setNotNull(!$is_nullable); $table->addColumn($column); } }
protected function populateFromOptions($options) { foreach ($options as $name => $attrs) { $column = new Column($name); if (isset($attrs['field'])) { $column->setFieldName($attrs['field']); } if (isset($attrs['type'])) { $column->setType($attrs['type']); } if (isset($attrs['sortable'])) { $column->setSortable($attrs['sortable']); } if (isset($attrs['label'])) { $column->setLabel($attrs['label']); } if (isset($attrs['format'])) { $column->setFormat($attrs['format']); } if (isset($attrs['format_function'])) { $column->setFormatFunction($attrs['format_function']); } if (isset($attrs['template'])) { $column->setTemplate($attrs['template']); } if (isset($attrs['boolean_actions'])) { $column->setBooleanActions($attrs['boolean_actions']); } if (isset($attrs['get_methods'])) { $column->setMethods($attrs['get_methods']); } $this->add($column); } }
public function createColumn(&$column) { $c = new Column(); $c->inflectedName = Inflector::instance()->variablize($column['field']); $c->name = $column['field']; $c->nullable = $column['not_nullable'] ? false : true; $c->pk = $column['pk'] ? true : false; $c->autoIncrement = false; if (substr($column['type'], 0, 9) == 'timestamp') { $c->rawType = 'datetime'; $c->length = 19; } elseif ($column['type'] == 'date') { $c->rawType = 'date'; $c->length = 10; } else { preg_match('/^([A-Za-z0-9_]+)(\\(([0-9]+(,[0-9]+)?)\\))?/', $column['type'], $matches); $c->rawType = count($matches) > 0 ? $matches[1] : $column['type']; $c->length = count($matches) >= 4 ? intval($matches[3]) : intval($column['attlen']); if ($c->length < 0) { $c->length = null; } } $c->mapRawType(); if ($column['default']) { preg_match('/^nextval\\(\'(.*)\'\\)$/', $column['default'], $matches); if (count($matches) == 2) { $c->sequence = $matches[1]; } else { $c->default = $c->cast($column['default'], $this); } } return $c; }
public function testReplaceColumnWithoutReplacement() { $xml = '<?xml version="1.0" ?> <column name="test" dump="replace" />'; $xmlElement = new \SimpleXMLElement($xml); $columnConfig = new Column($xmlElement); $this->assertEquals('', $columnConfig->processRowValue('test value')); }
public function createEnumColumn($defaultValues, $defaultValue) { $column = new Column(); $column->setType(PropelTypes::ENUM); $column->setValueSet($defaultValues); $column->setDefaultValue($defaultValue); return $column; }
/** * * @return database.model.Column */ function columnName() { if (!Rhaco::isVariable("_R_D_C_", "Category::Name")) { $column = new Column("column=name,variable=name,type=string,size=30,require=true,", __CLASS__); $column->label(Message::_("name")); Rhaco::addVariable("_R_D_C_", $column, "Category::Name"); } return Rhaco::getVariable("_R_D_C_", null, "Category::Name"); }
public function add_column($name, $cfg) { $col = new Column($this, $name); if (!$col->exists()) { $col->set_cfg($cfg); $this->columns[$name] = $col; return $col; } else { throw new \System\Error\Database(sprintf("Column '%s' already exists in table '%s'", $name, $this->name)); } }
/** * @api * @since 1.0.0 * * @param DataTable\Column $column * @param integer|string|\DateTime $value * @param string $label * @throws InvalidArgumentException if the supplied value is not of the supplied column's data type * @throws InvalidArgumentException if the supplied label is not a string */ public function __construct(Column $column, $value, $label = '') { $this->column = $column; if (!$this->column->isValueValidType($value)) { throw new \InvalidArgumentException("'{$value}' is not of type '{$column->getType()}'!"); } if (!is_string($label)) { throw new \InvalidArgumentException("The cell label must be a string!"); } $this->value = $value; $this->label = $label; }
public function create($name, $configures = NULL) { $column = new Column(); if (!empty($configures)) { if (is_array($configures)) { $column->set($configures); } } $column->set("name", $name); $this->add($column); return $column; }
protected function readHeader() { $this->version = $this->readChar(); $this->foxpro = $this->version == 48 || $this->version == 49 || $this->version == 245 || $this->version == 251; $this->modifyDate = $this->read3ByteDate(); $this->recordCount = $this->readInt(); $this->headerLength = $this->readShort(); $this->recordByteLength = $this->readShort(); $this->readBytes(2); //reserved $this->inTransaction = $this->readByte() != 0; $this->encrypted = $this->readByte() != 0; $this->readBytes(4); //Free record thread $this->readBytes(8); //Reserved for multi-user dBASE $this->mdxFlag = $this->readByte(); $this->languageCode = $this->readByte(); $this->readBytes(2); //reserved $fieldCount = floor(($this->headerLength - ($this->foxpro ? 296 : 33)) / 32); /* some checking */ if ($this->headerLength > filesize($this->tableName)) { throw new Exception\TableException(sprintf('File %s is not DBF', $this->tableName)); } if ($this->headerLength + $this->recordCount * $this->recordByteLength - 500 > filesize($this->tableName)) { throw new Exception\TableException(sprintf('File %s is not DBF', $this->tableName)); } /* columns */ $this->columns = array(); $bytepos = 1; $j = 0; for ($i = 0; $i < $fieldCount; $i++) { $column = new Column(strtolower($this->readString(11)), $this->readByte(), $this->readInt(), $this->readChar(), $this->readChar(), $this->readBytes(2), $this->readChar(), $this->readBytes(2), $this->readByte() != 0, $this->readBytes(7), $this->readByte() != 0, $j, $bytepos); $bytepos += $column->getLength(); if (!$this->avaliableColumns || $this->avaliableColumns && in_array($column->name, $this->avaliableColumns)) { $this->addColumn($column); $j++; } } if ($this->foxpro) { $this->backlist = $this->readBytes(263); } $this->setFilePos($this->headerLength); $this->recordPos = -1; $this->record = false; $this->deleteCount = 0; }
/** * @param mixed $index * @return string */ public function getValue($index) { $value = parent::getValue($index); $total = $this->table->getFooterValue($this->name); $this->table->setFooterValue($this->name, $total + $value); return $value; }
public function testFactories() { // char $this->assertEquals(new CharColumn('foo', 'char', 0), Column::char('foo', 0)); $this->assertEquals(new CharColumn('foo', 'varchar', 0), Column::varchar('foo', 0)); // datetime $this->assertEquals(new DateTimeColumn('foo'), Column::datetime('foo')); // decimal $this->assertEquals(new DecimalColumn('foo', 10, 2), Column::decimal('foo', 10, 2)); // float $this->assertEquals(new FloatColumn('foo', 10, 2), Column::float('foo', 10, 2)); // int $this->assertEquals(new IntColumn('foo', 'tinyint'), Column::tinyint('foo')); $this->assertEquals(new IntColumn('foo', 'smallint'), Column::smallint('foo')); $this->assertEquals(new IntColumn('foo', 'int'), Column::int('foo')); $this->assertEquals(new IntColumn('foo', 'mediumint'), Column::mediumint('foo')); $this->assertEquals(new IntColumn('foo', 'bigint'), Column::bigint('foo')); $this->assertEquals((new IntColumn('foo', 'tinyint'))->setUnsigned()->setAutoIncrement(), Column::tinyserial('foo')); $this->assertEquals((new IntColumn('foo', 'smallint'))->setUnsigned()->setAutoIncrement(), Column::smallserial('foo')); $this->assertEquals((new IntColumn('foo', 'int'))->setUnsigned()->setAutoIncrement(), Column::serial('foo')); $this->assertEquals((new IntColumn('foo', 'mediumint'))->setUnsigned()->setAutoIncrement(), Column::mediumserial('foo')); $this->assertEquals((new IntColumn('foo', 'bigint'))->setUnsigned()->setAutoIncrement(), Column::bigserial('foo')); // text $this->assertEquals(new TextColumn('foo', 'tinytext'), Column::tinytext('foo')); $this->assertEquals(new TextColumn('foo', 'text'), Column::text('foo')); $this->assertEquals(new TextColumn('foo', 'mediumtext'), Column::mediumtext('foo')); $this->assertEquals(new TextColumn('foo', 'longtext'), Column::longtext('foo')); // timestamp $this->assertEquals(new TimestampColumn('foo'), Column::timestamp('foo')); }
public function columns($cb) { Column::reset(); call_user_func($cb); $this->column = Column::get(); return $this; }
public function checkConstraints($target) { parent::checkConstraints($target); if (is_null($this->className) && is_null($this->name)) { throw new \Exception("L'un des attributs className ou name est obligatoire pour une annotation de type JoinColumn"); } }
public function isVisible($isExported = false) { if ($isExported) { return false; } return parent::isVisible(); }
public function setContext(array $row) { parent::setContext($row); foreach ($this->actions as $action) { $action->setContext($row); } }
public function __construct($name, $label, $url, $options = array()) { $options['formatter'] = array($this, 'formatLink'); $this->url = $url; $this->idProperty = $options['idProperty'] ?: 'id'; parent::__construct($name, $label, $options); }
private static function getInstance() { if (empty(self::$instance)) { self::$instance = new Column(); } return self::$instance; }
/** * @param Grido\Grid $grid * @param string $name * @param string $label * @param string $dateFormat */ public function __construct($grid, $name, $label, $dateFormat = NULL) { parent::__construct($grid, $name, $label); if ($dateFormat !== NULL) { $this->dateFormat = $dateFormat; } }
public function __call($method, $arguments) { if ($method === 'index' || array_key_exists($method, Column::$TYPES)) { if (count($arguments) <= 0) { throw new MissingArgumentException($method, __CLASS__); } $column = $arguments[0]; $options = !empty($arguments[1]) ? $arguments[1] : array(); if ($method === 'index') { if (!is_array($column)) { $column = array($column); } $this->indexes = array_merge($this->indexes, array(array('name' => Index::instance()->getName($column, $options), 'keys' => '`' . implode('`,`', $column) . '`'))); } else { $options['id'] = $column; $options['type'] = $method; $this->columns = array_merge($this->columns, array(Column::instance()->parseToDatabase($options))); } } else { if ($method === 'timestamps') { $this->columns = array_merge($this->columns, array(Column::instance()->parseToDatabase(array('id' => 'created_at', 'type' => 'datetime')))); $this->columns = array_merge($this->columns, array(Column::instance()->parseToDatabase(array('id' => 'updated_at', 'type' => 'datetime')))); } else { throw new UndefinedMethodException($method, __CLASS__); } } }
public static function getDefaultValueStringProvider() { $col1 = new Column('Bar'); $col1->setDomain(new Domain('VARCHAR')); $col1->setDefaultValue(new ColumnDefaultValue('abc', ColumnDefaultValue::TYPE_VALUE)); $val1 = "'abc'"; $col2 = new Column('Bar'); $col2->setDomain(new Domain('INTEGER')); $col2->setDefaultValue(new ColumnDefaultValue(1234, ColumnDefaultValue::TYPE_VALUE)); $val2 = "1234"; $col3 = new Column('Bar'); $col3->setDomain(new Domain('DATE')); $col3->setDefaultValue(new ColumnDefaultValue('0000-00-00', ColumnDefaultValue::TYPE_VALUE)); $val3 = "NULL"; return array(array($col1, $val1), array($col2, $val2), array($col3, $val3)); }
/** * get header string, if any * * @return mixed */ public function getHeader() { if (isset($this->header)) { return $this->header; } return parent::getHeader(); }
public function setDefault($value) : Column { if ($this->isAutoIncrement()) { throw new ColumnException('Auto increment column can\'t have default value'); } return parent::setDefault($value); }
public function __initialize(array $params) { $params['filterable'] = false; $params['sortable'] = false; $params['source'] = false; parent::__initialize($params); }
/** * @param $old * @param $new * @return bool|string */ public static function computeAlter(Column $old, Column $new) { if ($old->getCreateSql() == $new->getCreateSql()) { return false; } return "MODIFY COLUMN " . $new->getCreateSql(); }
public function setDefault($value) : Column { if ($value === 'CURRENT_TIMESTAMP') { $this->default_current = true; } return parent::setDefault($value); }
/** * Formatitem value * @param mixd $item * @return mixed */ public function getColumnValue($item) { $value = parent::getColumnValue($item); if (!is_numeric($value)) { return $value; } return number_format($value, $this->number_format[0], $this->number_format[1], $this->number_format[2]); }