Dynamic get with arrays #474

Closed
opened 2019-09-09 08:40:30 +00:00 by jonasborneland · 13 comments
jonasborneland commented 2019-09-09 08:40:30 +00:00 (Migrated from github.com)

I tried following your youtube video about the dynamic get, but It´s not really walked trough how to use it with the multiple rows type?

I have a table containing the id´s of another table like: '{"0":"2","1":"3","2":"1"}'

I´ve then done a dynamic get with Join View Tables like this:
image

but in my model for the site view inside this generated function:
public function getJjdelIdJj_delDddb_B($jjdel)

I had to convert the array string into an actual array insted of the json string.
I did it like this:
$array = json_decode($array, true);
before it worked.
Every time i recompile, I have to open the file and insert the above json decoder.

What did I miss for the jcb to do this? :)

And, thank you for such an amazing tool for creating components.

I tried following your youtube video about the dynamic get, but It´s not really walked trough how to use it with the multiple rows type? I have a table containing the id´s of another table like: '{"0":"2","1":"3","2":"1"}' I´ve then done a dynamic get with Join View Tables like this: ![image](https://user-images.githubusercontent.com/6105278/64515601-29178480-d2ed-11e9-8755-fc6737226395.png) but in my model for the site view inside this generated function: `public function getJjdelIdJj_delDddb_B($jjdel)` I had to convert the array string into an actual array insted of the json string. I did it like this: `$array = json_decode($array, true);` before it worked. Every time i recompile, I have to open the file and insert the above json decoder. What did I miss for the jcb to do this? :) And, thank you for such an amazing tool for creating components.

Hmmm, I am not sure I follow. Sounds like you are trying to do something that JCB does not yet support, but with a little bit of custom coding can be done.

I need to see the code to understand more, and then screen shots of all the dynamic view tabs so I can see what you did in JCB an how JCB compiled it.

Hmmm, I am not sure I follow. Sounds like you are trying to do something that JCB does not yet support, but with a little bit of custom coding can be done. I need to see the code to understand more, and then screen shots of all the dynamic view tabs so I can see what you did in JCB an how JCB compiled it.
peterpetrov commented 2019-09-09 10:11:24 +00:00 (Migrated from github.com)

Hey Jonas, have you considered custom dynamic get? You should have to write the query on your own but the it will also be very flexible in adding more "outside of the box" functionalities.

Peter

Get Outlook for Androidhttps://aka.ms/ghei36


From: eweyn notifications@github.com
Sent: Monday, September 9, 2019 1:05:49 PM
To: vdm-io/Joomla-Component-Builder Joomla-Component-Builder@noreply.github.com
Cc: Subscribed subscribed@noreply.github.com
Subject: Re: [vdm-io/Joomla-Component-Builder] Dynamic get with arrays (#474)

Hmmm, I am not sure I follow. Sounds like you are trying to do something that JCB does not yet support, but with a little bit of custom coding can be done.

I need to see the code to understand more, and then screen shots of all the dynamic view tabs so I can see what you did in JCB an how JCB compiled it.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHubhttps://github.com/vdm-io/Joomla-Component-Builder/issues/474?email_source=notifications&email_token=AAVIL6UBAVCKD7PPHJ7C3LLQIYNX3A5CNFSM4IUYJY32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6G7NNA#issuecomment-529397428, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AAVIL6TRLP4SV7NMCGR3NE3QIYNX3ANCNFSM4IUYJY3Q.

Hey Jonas, have you considered custom dynamic get? You should have to write the query on your own but the it will also be very flexible in adding more "outside of the box" functionalities. Peter Get Outlook for Android<https://aka.ms/ghei36> ________________________________ From: [[ewe]]yn <notifications@github.com> Sent: Monday, September 9, 2019 1:05:49 PM To: vdm-io/Joomla-Component-Builder <Joomla-Component-Builder@noreply.github.com> Cc: Subscribed <subscribed@noreply.github.com> Subject: Re: [vdm-io/Joomla-Component-Builder] Dynamic get with arrays (#474) Hmmm, I am not sure I follow. Sounds like you are trying to do something that JCB does not yet support, but with a little bit of custom coding can be done. I need to see the code to understand more, and then screen shots of all the dynamic view tabs so I can see what you did in JCB an how JCB compiled it. — You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub<https://github.com/vdm-io/Joomla-Component-Builder/issues/474?email_source=notifications&email_token=AAVIL6UBAVCKD7PPHJ7C3LLQIYNX3A5CNFSM4IUYJY32YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6G7NNA#issuecomment-529397428>, or mute the thread<https://github.com/notifications/unsubscribe-auth/AAVIL6TRLP4SV7NMCGR3NE3QIYNX3ANCNFSM4IUYJY3Q>.
jonasborneland commented 2019-09-09 10:37:41 +00:00 (Migrated from github.com)

Thanks!

I got these two admin views
image

In the "jjpakker" admin view, I got a field to select rows form the jjdele view.
The custom field in "jjpakker" looks like:
image
In the database the selected rows is stored as the json string mentioned above "'{"0":"2","1":"3","2":"1"}'".

I then have a dynamic get like this in the "joint" tab. I have not edited the other tabs:
image

And the site view contains this:
image

That dosen´t work without the decode json I added in the model code.
But with the decode json added, i gives me this on the frontend:

image

Thanks! I got these two admin views ![image](https://user-images.githubusercontent.com/6105278/64523421-8ebf3d00-d2fc-11e9-8591-88b790ae2fd7.png) In the "jjpakker" admin view, I got a field to select rows form the jjdele view. The custom field in "jjpakker" looks like: ![image](https://user-images.githubusercontent.com/6105278/64523615-faa1a580-d2fc-11e9-99e2-1a1b9d87c98e.png) In the database the selected rows is stored as the json string mentioned above "'{"0":"2","1":"3","2":"1"}'". I then have a dynamic get like this in the "joint" tab. I have not edited the other tabs: ![image](https://user-images.githubusercontent.com/6105278/64523803-6a179500-d2fd-11e9-969d-7b7699832dd7.png) And the site view contains this: ![image](https://user-images.githubusercontent.com/6105278/64524319-8bc54c00-d2fe-11e9-8b7c-b180f966c324.png) That dosen´t work without the decode json I added in the model code. But with the decode json added, i gives me this on the frontend: ![image](https://user-images.githubusercontent.com/6105278/64524185-4dc82800-d2fe-11e9-9874-6695d7bff63d.png)
jonasborneland commented 2019-09-09 10:53:06 +00:00 (Migrated from github.com)

Hmmm, I am not sure I follow. Sounds like you are trying to do something that JCB does not yet support, but with a little bit of custom coding can be done.

I need to see the code to understand more, and then screen shots of all the dynamic view tabs so I can see what you did in JCB an how JCB compiled it.

I´m basicly trying to do the same as you do here https://youtu.be/OPuCoxPW35s?t=753 but just with multiple items insted of a single item

> Hmmm, I am not sure I follow. Sounds like you are trying to do something that JCB does not yet support, but with a little bit of custom coding can be done. > > I need to see the code to understand more, and then screen shots of all the dynamic view tabs so I can see what you did in JCB an how JCB compiled it. I´m basicly trying to do the same as you do here https://youtu.be/OPuCoxPW35s?t=753 but just with multiple items insted of a single item
jonasborneland commented 2019-09-10 12:22:57 +00:00 (Migrated from github.com)

After looking a lot at this. This seems to me to be an error.
Has anyone used the IN statement of the dynamic get?

Inside the model for my site view, this function gets generated public function getJjdelIdJj_delCebc_B($jjdel)
In that function you will find this line:

// Check if $jjdel is an array with values.
		$array = $jjdel;
		if (isset($array) && JjviewpakkerHelper::checkArray($array, true))
		{
			$query->where('b.id IN (' . implode(',', $array) . ')');
		}
		else
		{
			return false;
		}

Which (I guess) works as expected with single row. But with multiple rows:
image
You got an array that you need to convert to json like:
$array = json_decode($array, true);
instead of the "$array" above in: // Check if $jjdel is an array with values. $array = $jjdel;

After looking a lot at this. This seems to me to be an error. Has anyone used the IN statement of the dynamic get? Inside the model for my site view, this function gets generated `public function getJjdelIdJj_delCebc_B($jjdel)` In that function you will find this line: ``` // Check if $jjdel is an array with values. $array = $jjdel; if (isset($array) && JjviewpakkerHelper::checkArray($array, true)) { $query->where('b.id IN (' . implode(',', $array) . ')'); } else { return false; } ``` Which (I guess) works as expected with single row. But with multiple rows: ![image](https://user-images.githubusercontent.com/6105278/64613339-32c8e700-d3d6-11e9-9d1a-ef56df35b955.png) You got an array that you need to convert to json like: $array = json_decode($array, true); instead of the "$array" above in: `// Check if $jjdel is an array with values. $array = $jjdel;`

I have never tested it this way, I will try it out and let you know if it is an error or just a wrong setting.

Just to make sure I do this the same way... the jjdel field in the main a table is a custom field (of jjdel table) with multiple selection enabled. So you are trying to return all jjdel rows/items selected in your main a table inside the custom field called jjdel.

I have never tested it this way, I will try it out and let you know if it is an error or just a wrong setting. Just to make sure I do this the same way... the `jjdel` field in the main `a` table is a custom field (of jjdel table) with multiple selection enabled. So you are trying to return all jjdel rows/items selected in your main `a` table inside the custom field called `jjdel`.

Well I just tested the above, that I explained. So I think you just have to fix your custom field called jjdel since if it is setup correctly the json multi values in jjdel are automatically converted to an array, before passing it to the second function, unless it is not a json.

So on my side I do not get the same error/issue, maybe share a screen shot of the whole getItem method.

Well I just tested the above, that I explained. So I think you just have to fix your custom field called `jjdel` since if it is setup correctly the json multi values in `jjdel` are automatically converted to an array, before passing it to the second function, unless it is not a json. So on my side I do not get the same error/issue, maybe share a screen shot of the whole getItem method.
jonasborneland commented 2019-09-13 06:30:09 +00:00 (Migrated from github.com)

Thanks for the answer. I will upload screenshots :)

Thanks for the answer. I will upload screenshots :)
jonasborneland commented 2019-09-13 06:34:45 +00:00 (Migrated from github.com)

The Dynamic get "JJ pakker"

image
image
image
image

**The Dynamic get "JJ pakker"** ![image](https://user-images.githubusercontent.com/6105278/64842033-27a5cf00-d601-11e9-86b1-f720e1fdf9ee.png) ![image](https://user-images.githubusercontent.com/6105278/64842053-342a2780-d601-11e9-8176-70d9170622a2.png) ![image](https://user-images.githubusercontent.com/6105278/64842062-3be9cc00-d601-11e9-815b-80461760d2b1.png) ![image](https://user-images.githubusercontent.com/6105278/64842082-486e2480-d601-11e9-8d0c-9fcf1e106aa6.png)
jonasborneland commented 2019-09-13 06:40:15 +00:00 (Migrated from github.com)

Custom field JJ del (dynamic)

image
image
image
image
image

**Custom field JJ del (dynamic)** ![image](https://user-images.githubusercontent.com/6105278/64842250-e7931c00-d601-11e9-8924-a388368caf3a.png) ![image](https://user-images.githubusercontent.com/6105278/64842264-f548a180-d601-11e9-8839-45a783e94e63.png) ![image](https://user-images.githubusercontent.com/6105278/64842276-ff6aa000-d601-11e9-8f72-3033291d922c.png) ![image](https://user-images.githubusercontent.com/6105278/64842292-0e515280-d602-11e9-9ee6-99383460a2ea.png) ![image](https://user-images.githubusercontent.com/6105278/64842300-18735100-d602-11e9-8b56-ee9a76f2c2ea.png)
jonasborneland commented 2019-09-14 20:54:18 +00:00 (Migrated from github.com)

@Llewellynvdm What data type do you use for the json arrays?

@Llewellynvdm What data type do you use for the json arrays?

I use text most of the time unless I know it will be very small then I use varchar(265).

About what I asked for... :

maybe share a screen shot of the whole getItem method

That is the code of a method in the model called getItem or getItems not the GUI stuff but the code of the actual site-view model. So what you shared does not help me see the code I actually asked for.

I use `text` most of the time unless I know it will be very small then I use `varchar(265)`. About what I asked for... : > maybe share a screen shot of the whole getItem method That is the code of a method in the model called `getItem` or `getItems` not the GUI stuff but the code of the actual site-view model. So what you shared does not help me see the code I actually asked for.
jonasborneland commented 2019-09-16 13:29:42 +00:00 (Migrated from github.com)

Thanks @Llewellynvdm!

I made it all work out trying the suggestions here and on the Google forum.
Thank you all for helping med out!

I made it work using a custom get where I did the json_decode inside:

$filterDele = "";
foreach ($this->_item as $del) {
    $rawSubform = json_decode($del->subform, true);
    foreach ($rawSubform as $subformpart){
        $filterDele .= $subformpart['jjdel'].",";
    }
    
}
$filterDele = substr($filterDele, 0, -1);

// Get from #__pakker_jj_del as a
$query->select('a.*');
$query->from($db->quoteName('#__pakker_jj_del', 'a'));
$query->where('a.id IN ('.$filterDele.')');

I´m so glad it is working now, I really felt stuck. But with the help from you and Peter, and Jcodewalker and Peter on the google forum, it is now working perfectly.

I really admire your work on JCB, it´s truly a powerful and useful tool. Thanks!

Thanks @Llewellynvdm! I made it all work out trying the suggestions here and on the Google forum. Thank you all for helping med out! I made it work using a custom get where I did the json_decode inside: ``` $filterDele = ""; foreach ($this->_item as $del) { $rawSubform = json_decode($del->subform, true); foreach ($rawSubform as $subformpart){ $filterDele .= $subformpart['jjdel'].","; } } $filterDele = substr($filterDele, 0, -1); // Get from #__pakker_jj_del as a $query->select('a.*'); $query->from($db->quoteName('#__pakker_jj_del', 'a')); $query->where('a.id IN ('.$filterDele.')'); ``` I´m so glad it is working now, I really felt stuck. But with the help from you and Peter, and Jcodewalker and Peter on the google forum, it is now working perfectly. I really admire your work on JCB, it´s truly a powerful and useful tool. Thanks!
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#474
No description provided.