public function asModel() { $fields = array(); foreach ($this->getColumns()->getColumns() as $column) { $fields[] = $column->asField(); } return $this->getJSObject(array('id' => $this->getModelName(), 'url' => ZendURLFormatter::fromCamelCaseToDashConnection($this->getModelName()), 'title' => str_replace('-', ' ', ZendURLFormatter::fromCamelCaseToDashConnection($this->getModelName())), 'fields' => $fields)); }
public function asFormItem() { $result = array(); // @see http://docs.sencha.com/ext-js/3-4/#!/api/Ext.form.ComboBox-cfg-hiddenName if (count($this->getLocalForeignKeys())) { $result['hiddenName'] = $this->getColumnName(); } else { $result['name'] = $this->getColumnName(); } $anchor = null; switch (true) { case $this->isPrimary(): $type = 'hidden'; break; case $this->getColumnType() === DatatypeConverter::DATATYPE_DATETIME: case $this->getColumnType() === DatatypeConverter::DATATYPE_TIMESTAMP: $type = 'xdatetime'; break; case $this->getColumnType() === DatatypeConverter::DATATYPE_TINYTEXT: case $this->getColumnType() === DatatypeConverter::DATATYPE_MEDIUMTEXT: case $this->getColumnType() === DatatypeConverter::DATATYPE_LONGTEXT: case $this->getColumnType() === DatatypeConverter::DATATYPE_TEXT: $type = 'htmleditor'; $anchor = '100%'; break; case count($this->getLocalForeignKeys()): $type = 'combo'; break; default: $type = 'textfield'; } $result['xtype'] = $type; $result['fieldLabel'] = ucwords(str_replace('_', ' ', $this->getColumnName())); $result['allowBlank'] = $this->isNotNull() ? false : true; if ($anchor) { $result['anchor'] = $anchor; } foreach ($this->getLocalForeignKeys() as $local) { $result['valueField'] = $local->getForeign()->getColumnName(); $result['displayField'] = $local->getReferencedTable()->getRawTableName(); $result['mode'] = 'local'; $result['forceSelection'] = true; $result['triggerAction'] = 'all'; $result['listeners'] = array('afterrender' => $this->getTable()->getJSObject('function() {this.store.load();}', true, true)); $result['store'] = $this->getTable()->getJSObject(sprintf('new Ext.data.JsonStore(%s);', $this->getTable()->getJSObject(array('id' => str_replace(' ', '', ucwords(str_replace('_', ' ', $local->getReferencedTable()->getRawTableName()))) . 'Store', 'url' => ZendURLFormatter::fromUnderscoreConnectionToDashConnection($local->getReferencedTable()->getRawTableName()), 'root' => 'data', 'fields' => array('id', 'name')), true)), false, true); } return $result; }