assign value from attribute_view_gui from select attribute - ezpublish

I have an attribute if type select. When i try to get value from this attribute content it gives the identification number instead of the value. I call like
$node.data_map.my_attribute_identifier.content
This is expected behaviour. https://doc.ez.no/eZ-Publish/Technical-manual/4.x/Reference/Datatypes/Selection
Raw output
The ".content" of an ezcontentobjectattribute object using this datatype returns an array of the identification numbers (as strings) of the selected options.
I want the value not the identification number. I can get that using attribute_view_gui like
attribute_view_gui attribute=$node.data_map.my_attribute_identifier
But i can't assign value to a variable this way. How can i assign value from a select attribute?

First of all i recommend you to always check default templates in your ezpublish to figure out how should template look...
Maybe this example will help:
<input
id="whatever_id_you_like"
type="text" size="50"
name="ContentObjectAttribute_ezstring_data_text_{$node.object.data_map.YOUR_ATTRIBUTE_SHORT_NAME.id}"
value="{$YOUR_VAR}"
/>
or u can use default view for attribute like this:
{attribute_view_gui attribute=$node.data_map.YOUR_ATTRIBUTE_SHORT_NAME}
also might be helpful - way to find correct path (sometimes you need add ".data_int" or ".data_text" on the end of the path to display data):
{$path|attribute(show,depth)} example:
{$node|attribute(show,2)}
or
{$YOUR_FANCY_VAR.content|attribute(show,2)}

You may want to take a look at the view template of ezselection:
ezselection.tpl
This is the code that eZ Publish uses to view the data type.
content of ezselection.tpl:
{let selected_id_array=$attribute.content}
{section var=Options loop=$attribute.class_content.options}
{section-exclude match=$selected_id_array|contains( $Options.item.id )|not}
{$Options.item.name|wash( xhtml )}{delimiter}<br/>{/delimiter}{/section}
{/let}

Related

XPath expression to pluck out attribute value

I have the following XML:
<envelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="vendor">
<fizz buzz="3"/>
</payload>
</envelope>
I am trying to write an XPath expression that will pluck out vendor (value for the payload's class attribute) or whatever its value is.
My best attempts are:
/dataEnvelope/payload[#class="vendor"]#class
But this requires the expression to already know that vendor is the value of the attribute. But if the XML is:
<dataEnvelope>
<action>INSERT</action>
<auditId>123</auditId>
<payload class="foobar">
<fizz buzz="3"/>
</payload>
</dataEnvelope>
Then I want the expression to pluck out the foobar. Any ideas where I'm going awry?
If you need #class value from payload node, you can use
/dataEnvelope/payload[#class]/#class
or just
/dataEnvelope/payload/#class
At first, your two XML files are out-of-sync - one references envelope and the other references dataEnvelope. So exchange one for the other, if necessary.
So, to get the attribute value of payload, you can use an XPath expression like this which uses a child's attribute value to be more specific:
/envelope/payload[fizz[#buzz='3']]/#class
Output is:
vendor
If the document element can/will change, then you can keep the XPath more generic and select the value of the class attribute from the payload element that is a child of any element:
/*/payload/#class
If you know that it will always be a child of envelope, then this would be more specific(but the above would still work):
/envelope/payload/#class

How to display selected numeric values in a comboBox

I have a numeric field in a Notes form connected to a combobox in the xpage. the values from the combobox is a list of decimal values, 1,02, 1,03 etc but they are stored as text in the keyword documents
The combobox is of type "string" (no converters) but it doesn't seem to matter if I change it to a "decimal" using converters.
comma is a decimal separator in Sweden
I fetch the keyword values using a #dbLookup
something like this.
#DbLookup(db,"vwLookupCat","BONUS","KeyWord")
When I save the document the values from the keyword document is saved as a numric value as it should. but the combobox is no longer showing the correct selected value (in edit mode) and displayes a validation error when I change it because the value is now numeric and not text as in the combobox keyword values.
or because the field was initially a text field, but when saved it is a numeric field.
<xp:comboBox id="comboBox7" value="#{doc.bonus}">
<xp:this.converter>
<xp:convertNumber type="number"></xp:convertNumber>
</xp:this.converter>
<xp:eventHandler event="onchange" submit="true" refreshMode="partial" refreshId="tbl"></xp:eventHandler>
<xp:selectItem itemLabel="Välj Bonus" itemValue="0"></xp:selectItem>
<xp:selectItems>
<xp:this.value><![CDATA[#{javascript:#DbLookup(db,"vwLookupCat","BONUS","KeyWord")}]]></xp:this.value>
</xp:selectItems>
</xp:comboBox>
Note that I am not using any validators on the combobox
I can't change the keyword field type to numeric as this is used on many other places
if doesn't help to use #Text (#Text(#DbLookup(db,"vwLookupCat","BONUS","KeyWord")))
How should I tackle this problem?
thanks in advance
Thomas
Seem to be a similar question here without solution
I can think of 2 ways you can go about it, both of which require you to make use of beans, hopefully you should already be familiar with the concept.
The conceptually righteous
The converter stays where it is. After all you want to deal with a number, you are saving a number. The converter instructs the framework to convert the returning string value from the POST into a number, and that is what you want, since also the destination field bound with the component is saved as a number.
The problem is matching such value with the list of values used to populated the options. Why? Those values are not numbers.
The solution is custom building the options rather than letting the framework doing the autoboxing from the array of string values returned from dblookup.
It pains me to write ssjs+formula but the call should be something like this:
<xp:selectItems
value="${javascript:myBeanName.getSelectItems(#DbLookup(db,"vwLookupCat","BONUS","KeyWord"))}">
</xp:selectItems>
The bean method:
public List<SelectItem> getSelectItems(String[] values) {
List<SelectItem> options = new ArrayList<SelectItem>();
for (String value : values) {
options.add(new SelectItem(Double.valueOf(value), value));
}
return options;
}
By doing this you are creating options with comparable values.
The only problem remaining is the utterly counterintuitive converter provided by IBM. Because you don't know what choosing 'number' does internally, whether it will be a Integer, a Double, a BigDecimal etc... you're stuck with more uncertainties than certainties. I have my own number converter but since I know how the IBM one works I think you can get away with the problem by specifying an additional param to the converter.
<xp:this.converter>
<xp:convertNumber type="number" integerOnly="true" />
</xp:this.converter>
I know, I know, integerOnly makes you think it will convert the value to Integer. It doesn't, it converts to Double. Lucky you! Imagine you needed an Integer!
The conceptually crappy
The other approach is to bind the combobox to a view scoped variable.
You would initialize the variable with the string converted doc value at page load and then work with that. At save time you would read the view scoped variable, convert it back to number and push the number to the doc field before saving it.

Is it possible to instruct a `Gtk::TreeView` to display a custom type?

There is something I don't understand how to do with Gtkmm 3.
I have a custom business type that I have declared like this:
enum class Eurocents : int {};
I would like to render this type into a Gtk::TreeView which has a Gtk::ListStore as model. So I declare a Gtk::TreeModelColumn<Eurocents>, and add it to the model. I then append_column this model column to the Gtk::TreeView with an appropriate title.
I then append_row to the model and set the value corresponding to the column to (Eurocents)100.
The result I get is that the cell is displayed empty. Understandably so, because I would not expect Gtkmm to know how to render my arbitrary type.
I would like to instruct Gtkmm on how to render my type.
I already know how to display Glib types like Glib::ustring and formatting to Glib::ustring for display is possible, but it is not the subject of the question.
Is it possible to code columns that can display arbitrary types like this? And if so, how? What is required for sorting to work?
The most common, and easiest way, is to use a cell_data_func callback. For instance, you can create your own instance of a Gtk::TreeView::Column (the view column), pack a cell renderer (or more) into your Gtk::TreeView::Column, append your Gtk::TreeView::Column to the TreeView with Gtk::TreeView::append_column(), and call set_cell_data_func() on your Gtk::TreeView::Column():
https://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeViewColumn.html#a3469e1adf42e5932ea123ec33e4ce4e1
You callback would then get the value(s) from the model and set the appropriate values of the properties of the renderer(s).
Here is an example that shows the use of set_cell_data_func(), as well as showing other stuff:
https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview-examples.html.en#sec-editable-cells-example
This link should also be useful:
https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview.html.en#treeview-cellrenderer-details
If you like, Gtk::TreeView::insert_column_with_data_func() makes this a little more concise: https://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeView.html#a595dcc0b503a7c1004c296b82c51ac54
As for the sorting, you should be able to just call set_sort_func() to specify how the column is sorted: https://developer.gnome.org/gtkmm/stable/classGtk_1_1TreeSortable.html#a3a6454bd0a285324c71edb73e403cb1c
Then this regular sorting advice should apply: https://developer.gnome.org/gtkmm-tutorial/stable/sec-treeview-sort.html.en

eZPublish - how to get Selection value?

I created (in admin) a selection field called color. Now I can't access it. When I run {$note.data_map.color.content|attribute(show)} it prints value. But I can't access it without attribute(show). What can I do?
eZSelection's content is an array, access the 0 key on content to get the value.
{$node.data_map.email_option.content.0}
don't forget you always have attribute_view_gui* which can help you quite a lot in these cases.
you can set the attribute to be information collector and collect that information from user.
*{attribute_view_gui attribute=$node.data_map.color}
You need to match the option array defined in your class attribute with the id of the selected option in order to get the value of it.
$node.data_map.color.class_content.options will contain all the options available (associative array with id and name values)
$node.data_map.color.content is an array containing the ids of the selected options (because this field can handle multiple selection).
Even if the {section} function is deprecated I'll suggested that you have a look at the default template rendering an ezselection attribute : design/standard/templates/content/datatype/view/ezselection.tpl
If you have "Multiple choice" type than you can do it like this:
{if $node.data_map.color.has_content}
{foreach $node.data_map.color.content as $colorID}
{foreach $node.data_map.color.class_content.options as $opt}
{cond($opt.id|eq($colorID), $opt.name, '')}
{/foreach}
{/foreach}
{/if}

Magento: how do I access custom variables in PHP?

I am aware of 'Custom Variables' and how they can be used with {{ }} brackets in email templates as well as in static blocks.
However, I want to use them in template code i.e. view.phtml.
I want to be able to access 'variable plain value' to retrieve a conversion value, i.e. a number/string as number for a given 'variable code'.
Been doing this for some time to create various messages that are editable through the admin interface so I don't have to go code digging when the flavor of the moment changes.
To access the plain value of the custom variable with code custom_variable_code use this:
Mage::getModel('core/variable')->loadByCode('custom_variable_code')->getValue('plain');
NOTE: Single store doesn't show the store select dropdown for the variable scope. This answer is not technically correct, in order to future-proof yourself in case of having multiple stores --> Please see #Mark van der Sanden answer below and give him an upvote.
Unfortunately, all other answers are not 100% correct. Use it like this (note the setStoreId() to get the value for the correct store view):
$value = Mage::getModel('core/variable')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCode('variable_code')
->getValue('text');
Or to get the html value:
$value = Mage::getModel('core/variable')
->setStoreId(Mage::app()->getStore()->getId())
->loadByCode('variable_code')
->getValue('html');
If no html value is defined, getValue() returns the text value if you request the html value.
Stackoverflow almost to the rescue again. Thought this would be it:
Setting a global variable in Magento, the GUI way?
But it wasn't, this was:
$angle = Mage::getModel('core/variable')->loadByCode('angle')->getData('store_plain_value');
The only way I see you can acheive this by having a method in the templates block, that will output the needed result.
For instance say in the template view.phtml you have the following code:
<div id="title_container">
<h2><?= $this->getTitle(); ?></h2>
</div>
The function can represent your variable code and any logic that has to do with what gets displayed in the title should be placed in the block.
Just for clarification sake the block is the variable $this
If you are unsure what is the actual class name of your block you can do something like:
Mage::log(get_class($this));
in the var/log/system.log you will print the class of the block of that template.
That is the best way.
HTH :)
// To get the TEXT value of the custom variable:
Mage::getModel('core/variable')->setStoreId(Mage::app()->getStore()->getId())->loadByCode('custom_variable_code')->getValue('text');
// To get the HTML value of the custom variable:
Mage::getModel('core/variable')->setStoreId(Mage::app()->getStore()->getId())->loadByCode('custom_variable_code')->getValue('html');
// The store id is set as Custom Variables can be edited for multiple stores
Note: A custom variable might have different values for different stores.
So to access store specific value for the custom variable with the code custom_variable_code
Use this:
$storeId = Mage::app()->getStore()->getId();
$custom_variable_text = Mage::getModel('core/variable')->setStoreId($storeId)
->loadByCode('custom_variable_code')
->getValue('text');
$custom_variable_plain_value = Mage::getModel('core/variable')->setStoreId($storeId)
->loadByCode('custom_variable_code')
->getValue('plain');
$custom_variable_html_value = Mage::getModel('core/variable')->setStoreId($storeId)
->loadByCode('custom_variable_code')
->getValue('html');

Resources