mirror of
https://github.com/kvazar-network/webapp.git
synced 2025-03-12 05:31:09 +00:00
add formatType filter
This commit is contained in:
parent
326866e6d7
commit
335f4e8fcd
@ -17,6 +17,13 @@ class AppExtension extends AbstractExtension
|
||||
$this,
|
||||
'jIdenticon'
|
||||
]
|
||||
),
|
||||
new TwigFilter(
|
||||
'format_type',
|
||||
[
|
||||
$this,
|
||||
'formatType'
|
||||
]
|
||||
)
|
||||
];
|
||||
}
|
||||
@ -50,4 +57,71 @@ class AppExtension extends AbstractExtension
|
||||
$format
|
||||
);
|
||||
}
|
||||
|
||||
public function formatType(
|
||||
mixed $value,
|
||||
int $code
|
||||
): string
|
||||
{
|
||||
switch ($code)
|
||||
{
|
||||
case \Kvazar\Index\Manticore::TYPE_NULL:
|
||||
|
||||
return '[null]';
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_BOOL:
|
||||
|
||||
return sprintf(
|
||||
'[bool:%s]',
|
||||
$value ? 'true' : 'false'
|
||||
);
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_INT:
|
||||
|
||||
return sprintf(
|
||||
'[int:%d]',
|
||||
$value
|
||||
);
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_FLOAT:
|
||||
|
||||
return sprintf(
|
||||
'[float:%s]',
|
||||
$value
|
||||
);
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_STRING:
|
||||
|
||||
return (string) nl2br(
|
||||
$value
|
||||
);
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_BIN:
|
||||
|
||||
return '[binary]';
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_JSON:
|
||||
|
||||
return '[json]';
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_XML:
|
||||
|
||||
return '[xml]';
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_BASE_64:
|
||||
|
||||
return '[base64]';
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_ARRAY:
|
||||
|
||||
return '[array]';
|
||||
|
||||
case \Kvazar\Index\Manticore::TYPE_OBJECT:
|
||||
|
||||
return '[array]';
|
||||
|
||||
default:
|
||||
return '[undefined]';
|
||||
}
|
||||
}
|
||||
}
|
@ -24,10 +24,10 @@
|
||||
</div>
|
||||
<a class="d-block" href="{{ path('main_transaction',{'transaction':record.transaction}) }}">
|
||||
<div class="f-s-16 mb-16 of-a">
|
||||
{{ record.key }}
|
||||
{{ record.key | format_type(record.type.key) }}
|
||||
</div>
|
||||
<div class="mb-20 of-a">
|
||||
{{ record.value | nl2br }}
|
||||
{{ record.value | format_type(record.type.value) }}
|
||||
</div>
|
||||
<div class="f-s-12">
|
||||
{{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<link>{{ url('main_index') }}</link>
|
||||
{% for record in records %}
|
||||
<item>
|
||||
<title>{{ record.key }}</title>
|
||||
<title>{{ record.key | format_type(record.type.key) }}</title>
|
||||
<author>{{ record.namespace }}</author>
|
||||
<pubDate>{{ record.time | date('D, d M Y h:i:s O') }}</pubDate>
|
||||
<guid>{{ url('main_transaction',{'transaction':record.transaction}) }}</guid>
|
||||
|
@ -25,10 +25,10 @@
|
||||
<div class="mx-a mw-560 px-16">
|
||||
<a class="d-block" href="{{ path('main_transaction',{'transaction':record.transaction}) }}">
|
||||
<div class="f-s-16 mb-16 of-a">
|
||||
{{ record.key }}
|
||||
{{ record.key | format_type(record.type.key) }}
|
||||
</div>
|
||||
<div class="mb-20 of-a">
|
||||
{{ record.value | nl2br }}
|
||||
{{ record.value | format_type(record.type.value) }}
|
||||
</div>
|
||||
<div class="f-s-12">
|
||||
{{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<link>{{ url('main_namespace',{'namespace':request.get('namespace')}) }}</link>
|
||||
{% for record in records %}
|
||||
<item>
|
||||
<title>{{ record.key }}</title>
|
||||
<title>{{ record.key | format_type(record.type.key) }}</title>
|
||||
<author>{{ record.namespace }}</author>
|
||||
<pubDate>{{ record.time | date('D, d M Y h:i:s O') }}</pubDate>
|
||||
<guid>{{ url('main_transaction',{'transaction':record.transaction}) }}</guid>
|
||||
|
@ -25,10 +25,10 @@
|
||||
<div class="t-center px-16">
|
||||
<div class="mx-a mw-560 px-16">
|
||||
<div class="f-s-16 mb-16 of-a">
|
||||
{{ record.key }}
|
||||
{{ record.key | format_type(record.type.key) }}
|
||||
</div>
|
||||
<div class="mb-20 of-a">
|
||||
{{ record.value | nl2br }}
|
||||
{{ record.value | format_type(record.type.value) }}
|
||||
</div>
|
||||
<div class="f-s-12">
|
||||
{{ record.time | format_date }} {{ 'in' | trans }} {{ record.block }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user