Unable to display all data from mysql json column - laravel-5

I am retrieving a single row of data from several joined tabled using first(), this includes a json column called properties. I am able to display all the non json data as expected in my blade template.
However for the json column called properties I am pulling my hair out, spend endless hours googling, looking on her but to no avail.
Appreciate if someone could point out the blindingly obvious (as I'm sure it will be)
I have tried also and reached a point where I can access anything in the root of the object but nothing that is nested.
So pretty version of dd($quote->properties) returns;
"{
"mode": 1,
"service": 1,
"rates": {
"DAP": 825.22
},
"detail": {
"weights": {
"actual": 111.00,
"volume": 0,
"chargeable": 111.00
}
}
}"
I Appreciate the leading and trailing "s are only added to render in the browser and don't exist in the actual column.
Using {{ json_decode($quote->properties,true)['mode'] }}
Result = 1 which is as desired output.
However {{ json_decode($quote->properties,true)['rates']['DAP'] }}
Result = Undefined index: DAP
Desired = 825.22
{{ var_dump(json_decode($quote->properties,true)) }}
array (size=4)
'mode' => int 1
'service' => int 1
'rates' =>
array (size=1)
'DAP' => float 825.22
'detail' =>
array (size=1)
'weights' =>
array (size=3)
'actual' => string '111.00' (length=6)
'volume' => int 0
'chargeable' => string '111.00' (length=6)

Thanks all, I have no idea why working....
Perhaps I had a typo and re-adding fixed or cleared view cache??
Thank you all for responding.

Related

Why do inline/IRRE records get sys_language_uid=0?

When creating a tt_content record in sys_language_uid = 2 (no translation/l10n_parent = 0) in backend and inserting fields in a type => 'inline' column tx_foo_slider_slides (definition below), the newly created records in tx_foo_domain_model_slide are created with sys_language_uid = 0. Adding an image to the slide's image field creates a sys_file_reference with sys_language_uid = 2. Is this correct? If not, how do I change this? I would expected to have all records (tt_content, tx_foo_slider_slides, sys_file_reference) created with sys_language_uid = 2. It seems that records created before the update do have sys_language_uid set to 2, but I am not sure what has changed between 8 and 9: is it a core change? Or my site/language configuration? sys_language_uid had a default of 0 in TCA, but removing that and creating additional records did not show any different behaviour.
When trying to load records through an ExtBase repository where I seemingly have to use setRespectSysLanguage(false):
I do get no results with setLanguageOverlayMode(false)
I do get results with setLanguageOverlayMode(true), but the image field is NULL.
... but if I also manually change the tx_foo_domain_model_slide.sys_language_uid to 2 it looks fine in BE and FE/ExtBase (image is a working FileReference)
What could be going wrong? What might need to be changed? I think creating records in non-default languages is a supported case? For me, the root cause seems to be that records are created with the wrong language set.
My configuration:
TYPO3 9.5.5 (updated from 8)
config.tx_extbase.features.consistentTranslationOverlayHandling = 1 (but tested 0, too)
config.sys_language_overlay = 0 (I don't think 1 or hideNonTranslated changed any behaviour)
Sites (and multi-site). This specific site comes with two languages:
Language 1, German (languageId: '0') is disabled.
Language 2, English (languageId: '2') is enabled; fallbackType: strict
A custom table tx_foo_domain_model_slide including language fields and an image column:
'image' => [
'label' => $ll.'tx_foo_domain_model_slide.image',
'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
'image',
[
'appearance' => [
'createNewRelationLinkTitle' => 'LLL:EXT:cms/locallang_ttc.xlf:images.addFileReference',
],
'overrideChildTca' => [
// types ...
],
'minitems' => 1,
'maxitems' => 1,
],
$GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'] .',m4v,mp4v,mp4'
),
],
A column tx_foo_slider_slides in tt_content:
[
'label' => $ll . 'slider.slides',
'config' => [
'type' => 'inline',
'appearance' => [
'collapseAll' => true,
'expandSingle' => true,
],
'foreign_field' => 'slider',
'foreign_sortby' => 'sorting',
'foreign_table' => 'tx_foo_domain_model_slide',
'maxitems' => 100,
'minitems' => 0,
],
],
The problem in this case is, that tx_foo_domain_model_slide.sys_language_uid is defined as:
'sys_language_uid' => [
'config' => [
'type' => 'passthrough',
'default' => '',
],
],
According to the TCA docs:
FormEngine does not render anything for passthrough types by default. But it can be combined with a custom renderType to make it render something. A user type is better suited for such use cases, though.
Type passthrough field values are usually also not rendered at other places in the backend.
This leads to sys_language_uid not being set (and staying at 0). So, sys_language_uid has to be defined as 'type => 'select'` or similar. To hide it, one can put it in a hidden palette, as described here.

Add/modify text between parentheses

I'm trying to make a classified text, and I'm having problem turning
(class1 (subclass1) (subclass2 item1 item2))
To
(class1 (subclass1 item1) (subclass2 item1 item2))
I have no idea to turn text above to below one, without caching subclass1 in memory. I'm using Perl on Linux, so any solution using shell script or Perl is welcome.
Edit: I've tried using grep, saving whole subclass1 in a variable, then modify and exporting it to the list; but the list may get larger and that way will use a lot of memory.
I have no idea to turn text above to below one
The general approach:
Parse the text.
You appear to have lists of space-separated lists and atoms. If so, the result could look like the following:
{
type => 'list',
value => [
{
type => 'atom',
value => 'class1',
},
{
type => 'list',
value => [
{
type => 'atom',
value => 'subclass1',
},
]
},
{
type => 'list',
value => [
{
type => 'atom',
value => 'subclass2',
},
{
type => 'atom',
value => 'item1',
},
{
type => 'atom',
value => 'item2',
},
],
}
],
}
It's possible that something far simpler could be generated, but you were light on details about the format.
Extract the necessary information from the tree.
You were light on details about the data format, but it could be as simple as the following if the above data structure was created by the parser:
my $item = $tree->{value}[2]{value}[1]{value};
Perform the required modifications.
You were light on details about the data format, but it could be as simple as the following if the above data structure was created by the parser:
my $new_atom = { type => 'atom', value => $item };
push #{ $tree->{value}[1]{value} }, $new_atom;
Serialize the data structure.
For the above data structure, you could use the following:
sub serialize {
my ($node) = #_;
return $node->{type} eq 'list'
? "(".join(" ", map { serialize($_) } #{ $node->{value} }).")"
: $node->{value};
}
Other approaches could be available depending on the specifics.

Ruby Loop Array and Create Hash for Each Array Object

I'd like to loop through an array and create a hash for each object in the array, then group all those hashes into an array of hashes.
Here's an example starting array for me:
urls = ["http://stackoverflow.com", "http://example.com", "http://foobar.com"]
Now let's say I'd like to have a hash for each of those URLs into an array like this:
urls =[ {
'url' => "http://stackoverflow.com",
'dns_status' => "200",
'title' => "Stack Overflow"
},
{
'url' => "http://example.com",
'dns_status'=> "200",
'title' => "Example"
}
]
Leaving aside where I get the values for the dns_status and title keys in the example, I guess what I'm missing is how to loop through the original array and create a hash for each object...
I've played around with inject, collect, map and each and read through the docs but can't quite make sense of it or get anything to work.
Any recommendation? Will this be easier to accomplish with a class?
EDIT:
Thanks for your help everyone. Figured this out and got it working. Cheers!
Do something with each element of something enumerable and store the result in an array: that is what map does. Specify what you want in the block, like this:
urls = ["http://stackoverflow.com", "http://example.com", "http://foobar.com"]
p res = urls.map{|url| {"url"=>url, "dns_status"=>200, "title"=>url[7..-5]} }
#=> [{"url"=>"http://stackoverflow.com", "dns_status"=>200, "title"=>"stackoverflow"}, {"url"=>"http://example.com", "dns_status"=>200, "title"=>"example"}, {"url"=>"http://foobar.com", "dns_status"=>200, "title"=>"foobar"}]
"what I'm missing is how to loop through the original array and create a hash for each object..."
urls = [
"http://stackoverflow.com",
"http://example.com",
"http://foobar.com"
]
urls.each {|entry|
puts entry
}
You could use .map! for instance. But I am still not sure what your target result ought to be. How about this?
urls.map! {|entry|
{ 'url' => entry, 'dns_status' => "200", 'title' => "Stack Overflow"}
}
urls # => [{"url"=>"http://stackoverflow.com", "dns_status"=>"200", "title"=>"Stack Overflow"}, {"url"=>"http://example.com", "dns_status"=>"200", "title"=>"Stack Overflow"}, {"url"=>"http://foobar.com", "dns_status"=>"200", "title"=>"Stack Overflow"}]
Yikes, the result is hard to see. It is this:
[
{
"url"=>"http://stackoverflow.com",
"dns_status"=>"200",
"title"=>"Stack Overflow"
},
{
"url"=>"http://example.com",
"dns_status"=>"200",
"title"=>"Stack Overflow"
},
{
"url"=>"http://foobar.com",
"dns_status"=>"200",
"title"=>"Stack Overflow"
}
]
Obviously, you need to still supply the proper content for title,
but you did not give this in your original question so I could not
fill it in.

The merge tags in mandrill don't work in codeigniter

I use Mandrill plugin for Codeigniter.
I created HTML template through Mandrill account, named fess1 with merge tag FNAME, after I published it.
Example:
...
<p>
<span>Hi *|FNAME|*,<br></span>
</p>
....
Now I try to send mail from codeigniter like:
private function sendMailMandrill($owner_name,$business_name,$owner_email){
$message = array('dest_mail' => $owner_email);
$message['to'] = array(array('email' => 'mim#wefi.com'));
$mergeVars[] = array(
'rcpt' => array(array('email' => 'mim#wefi.com')),
'vars' => array(
array(
'name' => 'FNAME',
'content' => 'Fessy'
)
)
);
$message['merge'] = true;
$template_name = 'fess1';
$template_content = array( // I don't know what I need to provide here, left it empty
array(
'name' => 'example name',
'content' => 'example content'
)
);
$message['merge_vars'] = $mergeVars;
return $this->mandrill->messages_send_template($template_name, $template_content, $message);
}
The result:
I get the mail, based on fess1 template, but with the tag *|FNAME|*.
Sounds like Mandrill didn't recognize the merge tag.
I used mandrill->messages_send_template but since my template stored into Mandrill account I have no clue what I need to provide for $template_content.
So I wrote dummy info there.
Did I miss something?
Thank you,
[EDIT]
From logs this is what I send:
{
"template_name": "fess1",
"template_content": [
{
"name": "example name",
"content": "example content"
}
],
"message": {
"owner_name": "עידו",
"business_name": "פלאפל מוסקו",
"dest_mail": "maxim#wifi.com",
"to": [
{
"email": "maxim#wifi.com"
}
],
"merge": "true",
"merge_vars": [
{
"rcpt": [
{
"email": "maxim#wifi.com"
}
],
"vars": [
{
"name": "FNAME",
"content": "Fessy"
}
]
}
]
},
"key": "xxxxxxxxxxxxxxxx"
}
You can provide blank information for the template_content parameter. That parameter allows you to use mc:edit regions in your template. It is a required parameter, but a blank array will suffice if all of the content is in your template in Mandrill.
As for whether the merge_vars were recognized, the first thing we recommend is inspecting the API Logs for your account (Settings > API Logs) since that will show you the JSON that Mandrill received. You can then compare that to the expected JSON format from the Mandrill API docs: https://mandrillapp.com/api/docs/messages.JSON.html#method=send-template
It looks like your arrays may not be nested as expected. Once you view the JSON that's being generated as compared with the expected format, you can also view the PHP documentation for the Mandrill PHP client. It may not be identical to the CodeIgniter plugin, but should give you an idea of how the merge_vars parameter would be structured in PHP: https://mandrillapp.com/api/docs/messages.php.html
In mergeVars you created array instead key:value. Change it to:
'rcpt' => 'mim#wefi.com',

Extra field in Json using $.ajax with Zend

I'm trying to use Ajax with Zend framework. I followed this tutorial and it works. I used following code to fetch the data:
$('#button').click(function() {
$.ajax({
url: './ajax/review/format/json',
dataType: 'json',
success: function(json_data){
alert('....');
}
});
});
The data parsed was like below:
Array ( [reviews] => Array ( [0] => Array ( [reviewid] => 3 [userid] => 1 [locationid]
=> 3 ) [1] => Array ( [reviewid] => 2 [userid] => 2 [locationid] => 2 ) [2] => Array (
[reviewid] => 1 [userid] => 1 [locationid] => 1 ) ) )
The Json I got was something like following:
{
"data": {
"reviews": [
{
"reviewid": 3,
"userid": 1,
"locationid": 3
},
{
"reviewid": 2,
"userid": 2,
"locationid": 2
}
]
}
}
I don't know where the "data" field comes from. I guess it relates to the way Zend parse data from controller to view, e.g. $this->view->data = array(...)
Hope I explained clearly, please help me to remove the extra "data" field.
I prefer to use JSON action helper to post data - like this:
// in controller
$this->_helper->json($dataToSend);
It will remove layout, disable view rendering and send proper headers.
Edit: You can also assign a variable to the view that has the key you desire - eg:
$this->view->reviews = $data;
It will remove the "data" from JSON you don't want...
You can not remove the data field if Zend does not provide a configuration for that. But you can look into that view's code and try either inheriting from it and changing functionality or writing you own view, such that it JSONifies data object itself.
Other way is to put all of your data attributes in the model directly instead of data object. But then there must be some kind of error object inside your model that would conflict.

Resources