/** * Return all columns * @return array */ protected function _getColumns() { $columns = array(); foreach ($this->_table->getColumns() as $name => $definition) { if (isset($definition['primary']) && $definition['primary'] || !isset($this->_columnTypes[$definition['type']]) || in_array($name, $this->_ignoreColumns)) { continue; } $definition['fieldName'] = $this->_table->getFieldName($name); $columns[$name] = $definition; } return $columns; }
/** * Return all columns as an array * * Array must contain 'type' for column type, 'notnull' true/false * for the column's nullability, and 'values' for enum values, 'primary' * true/false for primary key. Key = column's name * * @return array */ public function getColumns() { $foreignKeyColumns = array(); foreach ($this->_table->getRelations() as $alias => $relation) { $localColumn = strtolower($relation['local']); $foreignKeyColumns[$localColumn] = $relation['class']; } $data = $this->_table->getColumns(); $cols = array(); foreach ($data as $name => $def) { $isPrimary = isset($def['primary']) ? $def['primary'] : false; $isForeignKey = isset($foreignKeyColumns[strtolower($name)]); $columnName = $this->_table->getColumnName($name); $fieldName = $this->_table->getFieldName($columnName); $cols[$fieldName] = array('type' => $def['type'], 'notnull' => isset($def['notnull']) ? $def['notnull'] : false, 'values' => isset($def['values']) ? $def['values'] : array(), 'primary' => $isPrimary, 'foreignKey' => $isForeignKey, 'class' => $isForeignKey ? $foreignKeyColumns[strtolower($name)] : null); } return $cols; }
public function generateClassFromTable(Doctrine_Table $table) { $definition = array(); $definition['columns'] = $table->getColumns(); $definition['tableName'] = $table->getTableName(); $definition['actAs'] = $table->getTemplates(); $definition['generate_once'] = true; $generatedclass = $this->generateClass($definition); Doctrine::loadModels(sfConfig::get('sf_lib_dir') . '/model/doctrine/opCommunityTopicPlugin/base/'); return $generatedclass; }
/** * Generate a Doctrine_Record from a populated Doctrine_Table instance * * @param Doctrine_Table $table * @return void */ public function generateClassFromTable(Doctrine_Table $table) { $definition = array(); $definition['columns'] = $table->getColumns(); $definition['tableName'] = $table->getTableName(); $definition['actAs'] = $table->getTemplates(); return $this->generateClass($definition); }
public function applyFieldsFromDoctrineRelation(Doctrine_Table $table) { foreach ($table->getColumns() as $column => $meta) { $options = array('sortType' => AppKitExtDataInterface::doctrineColumn2ExtSortType($meta['type'])); if (isset($meta['primary']) && $meta['primary'] == true) { $this->setMeta(self::PROPERTY_ID, $column); } $this->hasField($column, $options); } }
/** * Provides a array of columns * * @param Doctrine_Table $table The current Doctrine_Table * * @return array */ private function listColumns(Doctrine_Table $table) { $ret = array(); foreach ($table->getColumns() as $name => $column) { if (empty($column['primary'])) { $added = true; foreach ($table->getRelations() as $relation) { if ($relation instanceof Doctrine_Relation_LocalKey && $relation->getLocal() === $name) { $added = false; break; } } if ($added) { $ret[] = sprintf("%s (%s)", $name, $column['type']); } } } return $ret; }
/** * @return bool */ public function isValid() { $tableColumns = $this->_table->getColumns(); $dirtyColumns = $this->_data->getModified(); foreach ($dirtyColumns as $key => $value) { unset($dirtyColumns[$key]); $dirtyColumns[strtolower($key)] = $value; } #die(Zend_Debug::dump($tableColumns)); foreach ($tableColumns as $columnName => $columnStructure) { if (array_key_exists($columnName, $dirtyColumns)) { $validatorChain = new Zend_Validate(); // Notnull if (array_key_exists('notnull', $columnStructure)) { $validatorChain->addValidator(new Zend_Validate_NotEmpty(array('string' => true, 'empty_array' => true, 'null' => true, 'space' => true))); } // Email if (array_key_exists('email', $columnStructure)) { $validatorChain->addValidator(new Zend_Validate_EmailAddress()); } // Notblank if (array_key_exists('notblank', $columnStructure)) { $validatorChain->addValidator(new Kebab_Validate_NotBlank()); } // Nospace if (array_key_exists('nospace', $columnStructure)) { // check null $validatorChain->addValidator(new Zend_Validate_NotEmpty(array('null' => true))); // check space $validatorChain->addValidator(new Zend_Validate_Regex(array('pattern' => '/\\s/'))); } // Past // Future // Min Length if (array_key_exists('minlength', $columnStructure)) { $validatorChain->addValidator(new Zend_Validate_GreaterThan(array('min' => $columnStructure['minlength']))); } // Country // Ip if (array_key_exists('ip', $columnStructure)) { $validatorChain->addValidator(new Zend_Validate_Ip()); } // HtmlColor // Range if (array_key_exists('range', $columnStructure)) { $validatorChain->addValidator(new Zend_Validate_Between(array('min' => $columnStructure['range'][0], 'max' => $columnStructure['range'][1]))); } //Unique if (array_key_exists('unique', $columnStructure)) { $validatorChain->addValidator(new Kebab_Validate_Unique($columnName, $this->_data)); } // Regex if (array_key_exists('regexp', $columnStructure)) { $validatorChain->addValidator(new Zend_Validate_Regex(array('pattern' => $columnStructure['regexp']))); } // Digits if (array_key_exists('digits', $columnStructure)) { $validatorChain->addValidator(new Zend_Validate_Digits()); } // Date if (array_key_exists('date', $columnStructure)) { $validatorChain->addValidator(new Zend_Validate_Date()); } // CC if (array_key_exists('cc', $columnStructure)) { $validatorChain->addValidator(new Zend_Validate_CreditCard()); } // Unsigned // Check All if (!$validatorChain->isValid($dirtyColumns[$columnName])) { $translator = Zend_Registry::get('Zend_Translate'); Zend_Validate_Abstract::setDefaultTranslator($translator); $this->_errors[$columnName] = $validatorChain->getMessages(); } unset($validatorChain); } } if (count($this->_errors) > 0) { return false; } else { return true; } }