本文整理汇总了PHP中Doctrine\ORM\Mapping\ClassMetadata::getFieldMapping方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::getFieldMapping方法的具体用法?PHP ClassMetadata::getFieldMapping怎么用?PHP ClassMetadata::getFieldMapping使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::getFieldMapping方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFieldMapping
/** {@inheritdoc} */
public function getFieldMapping($fieldName)
{
if (!$this->hasField($fieldName)) {
throw new MetadataException("Field '{$fieldName}' not found in class '{$this->getClass()}'.");
}
return $this->classMetadata->getFieldMapping($fieldName);
}
示例2: insert
/**
* @param object $entity
* @return int
* @throws \Doctrine\ORM\Mapping\MappingException
*/
public function insert($entity)
{
$data = [];
$types = [];
$idColumn = false;
foreach ($this->metaData->getColumnNames() as $columnName) {
$fieldName = $this->metaData->getFieldForColumn($columnName);
$mapping = $this->metaData->getFieldMapping($fieldName);
if (isset($mapping['id'])) {
if (isset($mapping['nullable']) && $mapping['nullable']) {
continue;
}
if (!$entity->{$fieldName}) {
$idColumn = $fieldName;
}
}
$typeName = $this->metaData->getTypeOfColumn($fieldName);
$type = \Doctrine\DBAL\Types\Type::getType($typeName);
$value = $type->convertToDatabaseValue($entity->{$fieldName}, $this->em->getConnection()->getDatabasePlatform());
$types[$columnName] = $type->getBindingType();
$data[$columnName] = $value;
}
$result = $this->em->getConnection()->insert($this->metaData->getTableName(), $data, $types);
if ($result) {
if ($idColumn) {
return $this->em->getConnection()->lastInsertId($this->metaData->getTableName() . '_id_seq');
}
return $result;
}
return false;
}
示例3: configure
/**
* funkcja zwraca domyslną konfiguracje dla pola formularza
*
* @param $fieldName
* @param array $properties
* @return array
* @throws \Doctrine\ORM\Mapping\MappingException
*/
protected function configure($fieldName, array $properties = array())
{
/**
* informacje o encji
*/
if (null === $this->metadata) {
$this->metadata = $this->getEntityManager()->getClassMetadata(get_class($this->getObject()));
}
$fieldMeta = (object) $this->metadata->getFieldMapping($fieldName);
return array_replace_recursive(array('required' => true, 'filters' => array(array('name' => 'StringTrim'), array('name' => 'StripTags')), 'properties' => array('required' => true), 'validators' => array('NotEmpty' => array('name' => 'NotEmpty', 'options' => array('messages' => array(Validator\NotEmpty::IS_EMPTY => 'FieldCannotBeEmpty'))), 'StringLength' => array('name' => 'StringLength', 'options' => array('encoding' => 'UTF-8', 'max' => $fieldMeta->length, 'messages' => array('stringLengthTooLong' => 'StringLengthTooLong'))))), $properties);
}
示例4: loadMeta
/**
* @param Builder\Metadata $meta
* @param \Doctrine\ORM\Mapping\ClassMetadata $cm
*/
private function loadMeta(Builder\Metadata $meta, \Doctrine\ORM\Mapping\ClassMetadata $cm)
{
$type = null;
if ($cm->hasField($meta->name)) {
$map = $cm->getFieldMapping($meta->name);
$type = $map['type'];
switch ($type) {
case 'smallint':
case 'bigint':
$type = 'integer';
break;
default:
break;
}
if (!isset($map['nullable']) || $map['nullable'] === false && !isset($meta->conditions['required'])) {
$meta->conditions['required'] = true;
}
if (isset($map['length']) && $map['length'] && !isset($meta->conditions['maxLenght'])) {
$meta->conditions['maxLength'] = $map['length'];
}
if ($type === 'decimal' && isset($map['scale'])) {
$type = 'float';
$meta->custom['step'] = pow(10, -$map['scale']);
}
} elseif ($cm->hasAssociation($meta->name)) {
$map = $cm->getAssociationMapping($meta->name);
$type = $map['targetEntity'];
}
if (!$meta->type) {
$meta->type = $type;
}
}
示例5: addDoctrineFields
/**
* @param EntityMetadata $entityMetadata
* @param ClassMetadata $classMetadata
*/
protected function addDoctrineFields(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
{
$fields = array_diff($classMetadata->getFieldNames(), $classMetadata->getIdentifierFieldNames(), $this->getDeletedFields($classMetadata->name));
foreach ($fields as $fieldName) {
$fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $fieldName), $classMetadata->getFieldMapping($fieldName));
$entityMetadata->addFieldMetadata($fieldMetadata);
}
}
示例6: addDoctrineFields
/**
* @param EntityMetadata $entityMetadata
* @param ClassMetadata $classMetadata
*/
protected function addDoctrineFields(EntityMetadata $entityMetadata, ClassMetadata $classMetadata)
{
$identifierFields = $classMetadata->getIdentifierFieldNames();
foreach ($classMetadata->getFieldNames() as $fieldName) {
if (in_array($fieldName, $identifierFields)) {
continue;
}
$fieldMetadata = $this->metadataFactory->createFieldMetadata(array('field_name' => $fieldName), $classMetadata->getFieldMapping($fieldName));
$entityMetadata->addFieldMetadata($fieldMetadata);
}
}
示例7: handle
public function handle($name, array $options, ClassMetadata $classMetadata, Configuration $configuration)
{
if (!$classMetadata->hasField($name)) {
return NULL;
}
$mapping = $classMetadata->getFieldMapping($name);
$controlName = empty($options['control']) ? $this->getControlByType($mapping['type']) : $options['control'];
$control = ControlFactory::create($controlName, ['\\Nette\\Forms\\Controls\\BaseControl'], ControlFactory::TEXT_INPUT);
if (empty($options['caption'])) {
$control->caption = $configuration->getLabelingStrategy()->getControlLabel($name, $classMetadata);
} else {
$control->caption = $options['caption'];
}
return new ControlBuilder($control);
}
示例8: getFieldsMetadata
public function getFieldsMetadata($class, $group = 'default')
{
$result = array();
foreach ($this->ormMetadata->getFieldNames() as $name) {
$mapping = $this->ormMetadata->getFieldMapping($name);
// $mapping['isAssociation']=false;
$values = array('title' => $name, 'source' => true);
if (isset($mapping['fieldName'])) {
$values['field'] = $mapping['fieldName'];
$values['id'] = $mapping['fieldName'];
}
if (isset($mapping['id']) && $mapping['id'] == 'id') {
$values['primary'] = true;
}
switch ($mapping['type']) {
case 'string':
case 'text':
$values['type'] = 'text';
break;
case 'integer':
case 'smallint':
case 'bigint':
case 'float':
case 'decimal':
$values['type'] = 'number';
break;
case 'boolean':
$values['type'] = 'boolean';
break;
case 'date':
$values['type'] = 'date';
break;
case 'datetime':
$values['type'] = 'datetime';
break;
case 'time':
$values['type'] = 'time';
break;
case 'array':
case 'object':
$values['type'] = 'array';
break;
}
$result[$name] = $values;
}
return $result;
}
示例9: __invoke
/**
* Truncate input text
*
* @param AbstractEntity $entity
* @param string $field
* @param
* @return mixed
*/
public function __invoke(AbstractEntity $entity, $field, ClassMetadata $metadata = null)
{
if (strpos($field, '.')) {
list($Assoc, $field) = explode('.', $field, 2);
if (!property_exists($entity, $Assoc)) {
throw new \RuntimeException('Invalid Association found: ' . get_class($entity) . '#' . $Assoc);
} else {
if ($entity->{$Assoc} != null) {
return $this->__invoke($entity->{$Assoc}, $field);
}
}
return null;
} else {
if (property_exists('__isInitialised__', $entity) && $entity->__isInitialized__) {
// entity is an uninitialised proxy, lets load it
$entity->load();
}
if (!property_exists($entity, $field)) {
throw new \RuntimeException('Field "' . $field . '" not found in Entity: ' . get_class($entity));
}
$value = $entity->{$field};
if ($metadata) {
if ($column = $metadata->getFieldMapping($field)) {
switch (strtolower($column['type'])) {
case "money":
$value = $this->getView()->currencyFormat($value, 'GBP');
break;
case "datetime":
$value = $this->getView()->dateFormat($value, \IntlDateFormatter::SHORT, \IntlDateFormatter::SHORT);
break;
case "date":
$value = $this->getView()->dateFormat($value, \IntlDateFormatter::SHORT, \IntlDateFormatter::NONE);
break;
case "time":
$value = $this->getView()->dateFormat($value, \IntlDateFormatter::NONE, \IntlDateFormatter::SHORT);
break;
case 'boolean':
$value = $value ? '<span class="true">yes</span>' : '<span class="false">no</span>';
break;
}
}
}
}
return $value;
}
示例10: createField
/**
* @param string $fieldName
* @param ClassMetadata $classMetadata
* @return ForestField
*/
protected function createField($fieldName, ClassMetadata $classMetadata)
{
return new ForestField($fieldName, $classMetadata->getFieldMapping($fieldName)['type']);
}
示例11: getSimpleTypeOptions
/**
* @param ClassMetadata $metaData
* @param $fieldName
*
* @return array
*
* @throws MappingException
*/
protected function getSimpleTypeOptions(ClassMetadata $metaData, $fieldName)
{
$fieldInfo = $metaData->getFieldMapping($fieldName);
$data = ['type' => $fieldInfo['type']];
return $data;
}
示例12: getPropertyDoctrineFieldMapping
public function getPropertyDoctrineFieldMapping($property)
{
if ($this->orm_metadata->hasField($property)) {
return $this->orm_metadata->getFieldMapping($property);
}
}
示例13: getDatabaseFieldMappings
/**
* Returns database field mappings
*
* @param ClassMetadata $cm
*
* @return array
* @throws \Doctrine\ORM\Mapping\MappingException
*/
protected function getDatabaseFieldMappings(ClassMetadata $cm)
{
$fieldMappings = array();
$fields = $cm->getFieldNames();
foreach ($fields as $field) {
$currentMapping = $cm->getFieldMapping($field);
if ($currentMapping["fieldName"] == "id") {
$currentMapping["fieldName"] = "@id";
$currentMapping["type"] = "string";
}
$fieldMappings[] = array("name" => $currentMapping["fieldName"], "type" => $this->getExtJSFieldMapping($currentMapping["type"]));
}
return $fieldMappings;
}
示例14: getMappings
/**
* Get mappings.
*
* @param ClassMetadata $metadata
* @param array $fields
*
* @return array
* @throws MappingException
*/
protected function getMappings(ClassMetadata $metadata, array $fields)
{
$mappings = array();
foreach ($fields as $field) {
try {
// Gets the mapping of a regular field
$mappings[$field] = $metadata->getFieldMapping($field);
} catch (MappingException $e) {
// Gets the mapping of an association
$mappings[$field] = $metadata->getAssociationMapping($field);
}
}
return $mappings;
}
示例15: fieldFilter
/**
* @author Franlin Rivero Grcia <frrivero@uci.cu>
* @param string $key
* @param type $fields
* @param \Doctrine\ORM\Mapping\ClassMetadata $meta
* @param QueryBuilder $qb
* @param type $asoc
*/
public static function fieldFilter($class, &$filters, &$fields, &$asoc, &$meta, &$qb)
{
if (array_key_exists('select', $filters)) {
$qb->select($filters['select']);
unset($filters['select']);
}
$fTemp = json_decode(UtilRepository2::getContainer()->get('request')->get('filters'));
if (is_array($fTemp)) {
if (!(is_array($filters) && count($filters) > 0 || !is_array($filters) && $filters != null)) {
$filters = $fTemp;
}
}
if ($filters == null) {
$filters = array();
}
if (!is_array($filters)) {
$filters = array($filters);
}
foreach ($filters as $key => $value) {
if ($value !== null && $value !== '') {
if (in_array($key, $fields)) {
$map = $meta->getFieldMapping($key);
if ($map['type'] == 'string' || $map['type'] == 'text' || $map['type'] == 'varchar') {
if (UtilRepository2Config::$defaultStringComparer == 'like') {
$qb->andWhere("lower({$class}.{$key}) like :{$key}");
if (strpos($value, '%') === false) {
$qb->setParameter($key, "%" . strtolower($value) . "%");
} else {
$qb->setParameter($key, strtolower($value));
}
} else {
if (is_array($value)) {
$op = $value[0];
$qb->andWhere("lower({$class}.{$key}) {$op} :{$key}");
$qb->setParameter($key, strtolower($value[1]));
} else {
$qb->andWhere("lower({$class}.{$key}) = :{$key}");
$qb->setParameter($key, strtolower($value));
}
}
} else {
if (is_array($value)) {
$op = $value[0];
if ($op == 'in') {
$qb->andWhere("{$class}.{$key} {$op} (:{$key})");
$qb->setParameter($key, $value[1]);
} elseif ($op == 'is') {
$qb->andWhere("{$class}.{$key} is null");
} else {
$qb->andWhere("{$class}.{$key} {$op} :{$key}");
$qb->setParameter($key, strtolower($value[1]));
}
} else {
$qb->andWhere("{$class}.{$key} = :{$key}");
$qb->setParameter($key, $value);
}
}
} elseif (in_array($key, $asoc)) {
if (is_array($value)) {
$op = $value[0];
if ($op == 'is') {
$qb->andWhere("{$class}.{$key} is null");
}
} else {
$qb->andWhere("{$class}.{$key} = :{$key}");
$qb->setParameter($key, $value);
}
} else {
$op = UtilRepository2Config::$defaultForeignCompareOperator;
$param = str_replace(".", '', $key);
if (!is_array($value)) {
if ($op == 'like') {
$qb->andWhere("lower({$key}) {$op} :{$param}");
} else {
$qb->andWhere("{$key} {$op} :{$param}");
}
if ($op == 'like') {
if (strpos($value, '%') === false) {
$qb->setParameter($param, "%" . strtolower($value) . "%");
} else {
$qb->setParameter($param, strtolower($value));
}
} else {
$qb->setParameter($param, $value);
}
} else {
if ($value[0] == 'like') {
$qb->andWhere("lower({$key}) {$value['0']} :{$param}");
} elseif ($value[0] == 'in') {
$qb->andWhere("{$key} {$value['0']} (:{$param})");
} else {
$qb->andWhere("{$key} {$value['0']} :{$param}");
//.........这里部分代码省略.........