Welcome, Guest
Username: Password: Remember me

TOPIC: [SOLVED] Data inside one item from another item

[SOLVED] Data inside one item from another item 13 Feb 2013 14:07 #6730

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
Hi,

I would like to be able to add to my backend item form some readonly fields. I have read some posts in the forum, this in particular:

http://www.j-cook.pro/forum/9-coding-inside-your-component/1761-editing-multiple-tables-in-one-view#1882]

but I'm still a bit lost.

Let's take the tutorial "travel" component as an example, supposing that:

1) One can not use the Cook filters (they are still disabled).
2) The "Voyages" table has one additional field "Scope" filled by a textarea inside the "Voyages" backend item page (values could be "Job", "Holiday" or any other string value).

The user inserts these information using the "Voyages" item form:
Andrew - Lyon - Job
Andrew - Marseille - Holiday
Andrew - Bordeaux - Job

Then, he/she opens the "Voyageur" collection, selects "Andrew" to edit the data and, inside the item form, after the combo "Utilisateur -> Username", a field with label "Voyages" shows these readonly info:
Lyon, Job
Marseille, Holiday
Bordeax, Job

If no Voyages exist for Andrew, the field "Voyages" should appear empty.

GENERAL IDEAS

A - I thought a first step could be adding a textarea field inside admin/models/forms/voyageur.xml.

B - Then I need to add a function to the model (admin/models/voyageur.php) that executes the query (it could be a simple "select ... from Voyages where voyageur=$pk" being $pk the item id, similar to what happens in the function prepareQuery) and builds a multi-dimensional array containing the data from the query.

C - Finally in the form (admin/views/voyageur/tmpl/voyageur_form.php I should add, inside the "foreach($fieldSet as $field)" a sort of :
if ($field->name == 'my_field'):
	    ?>
	    <dt>
	        <?php echo $field->label; ?>
	    </dt>
	    	<?php foreach($array as $v1)  {
	    		echo "<dd>";
	    		foreach($v1 as $v2){
			  		echo $v2 . " ";		 
				}   				
   			echo "</dd>"; 
			}

Where $array should be the multidimensional array output of the query obtained in B.

I understand there are a lot of lacking points (first of all voyagur_form.php does not know what $array is), but could you point me to the right places/files so to obtain the result ?

Thanks a lot

Elena
Last Edit: 14 Feb 2013 15:02 by dieda1821.
The administrator has disabled public write access.

Re: Viewing data inside one item from another item tab 14 Feb 2013 09:16 #6741

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Elena,

I'm not sure if I've misunderstood what you want but, why not add the fields as per normal then in the downloaded component, add a readonly="readonly" to the XML?

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Viewing data inside one item from another item tab 14 Feb 2013 09:37 #6742

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
Hi Gez,

Because, correct me if I'm wrong, inside Cook I can add fields that corresponds to the same item table field, or to tables that are related to the item through a primary key.
E.g.:
table voyageur -> ville field
voyageur item layout -> ville field

If I want to add a field to the voyageur item layout, that shows multiple data from a query on the voyages table, then I don't think I can (from Cook)...in other words, everytime I add a field, I have to choose a single table value to which the field is linked.

In my case -> I don't want to use the field to input data inside a table field, but only show multiple data (let's say a grid of data) from a second table. Am I missing something with the interface ?

Thanks as usual for the assistance :-)
The administrator has disabled public write access.

Re: Viewing data inside one item from another item tab 14 Feb 2013 09:44 #6743

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
Hi Elena,

Sorry, don't think I totally understood your original post!!!

Ok, I believe what you're looking for is the loading of all related items (if any exist) which is also part of the tutorial... It's just a couple of small mods to your model(s).

Have you worked through that?

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Viewing data inside one item from another item tab 14 Feb 2013 10:12 #6744

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
Never mind !!!

Just to explain myself better (always working on Voyageur item form):

- Username form textarea field -> input to Voyageur username table field -> Ok inside Cook.

- [invented] Haircolor form combo field -> input to Voyageur haircolor table field, but input limited to some values recalled from a Color table, through a primary key -> Ok inside Cook.

- [desired] Voyages form textarea field -> no input involved. Only output some rows from the Voyages table (select on voyageur.id=voyages.voyager) -> Here I need some help.

I have read the tutorial, but I have two problems:
1) At the moment Cook still does not let me set the filters (unless now you tell me that this is not necessary and that the code:
$this->getState('filter.voyageur')
works despite no filter has been previously set in Cook...does it work anyway ?

2) The guide (always if I am not wrong) assumes to show the data inside the same context -> pictures of voyageurs that have travelled in a city are shown in the context 'voyageur.villes'.
This means that there is no need of a new function: prepareQuery has already a switch case in it and by creating a context that corresponds to our table context we can show data from our source table.
In my case, the context is always 'voyageur.voyageur' but I need to display data from the Voyages table.
I'm not sure I can modify the prepareQuery function to fulfill my need (can I ?), hence I thought a new function was required (eventually a new model).


Elena
The administrator has disabled public write access.

Re: Viewing data inside one item from another item tab 14 Feb 2013 10:54 #6748

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
I'm sure that you will be able to modify the prepareQuery for that... Sorry, mobile whilst looking after my daughter so not able to give this as much attention as is probably required!

G
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.

Re: Viewing data inside one item from another item tab 14 Feb 2013 11:06 #6749

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
Ah! I'm a Cook NEWBIE but an ADMIN PRO in multitasking involving kids/babies :-DDD

Anyhow, I'm afraid I'm a bit lost since I should change the prepareQuery not adding a list of values, but a grid of them (this also means that, when building the form, there will be a field that will not be loaded, and a simple <dd></dd> text will be shown -> this because inside a readonly textarea I can not use html tag to end lines or format the text).

Do you think I could have some support from admin ? (eventually I could build a little economic offer, as made by dyvel ;)

Elena
Last Edit: 14 Feb 2013 11:08 by dieda1821.
The administrator has disabled public write access.

Re: Viewing data inside one item from another item tab 14 Feb 2013 15:01 #6754

  • dieda1821
  • dieda1821's Avatar
  • Offline
  • Senior Member
  • Posts: 53
  • Thank you received: 2
  • Karma: 4
I DID IT !!!!

For some time the filters inside Cook became available, and I had the time to set one -> from that point it's been A LOT easier to customize the code inside the tutorial !!!!!!!!!!!!!!!!!!!!!!!!!!!!

Thanks for the assistance !
The administrator has disabled public write access.
The following user(s) said Thank You: JoomGuy

Re: Viewing data inside one item from another item tab 27 Feb 2013 09:25 #6846

  • JoomGuy
  • JoomGuy's Avatar
  • Offline
  • Moderator
  • Joomla Enthusiast, Lover of Cooking
  • Posts: 1115
  • Thank you received: 195
  • Karma: 64
dieda1821 wrote:
Ah! I'm a Cook NEWBIE but an ADMIN PRO in multitasking involving kids/babies :-DDD
Well, you know us men, we can't multi-task like women! :lol: I wish I could but I can't!!! :(

Gez
Need help with your Cook/Joomla Project? . PM me to find out what I can help with. NO time wasters please!!!
The administrator has disabled public write access.
Time to create page: 0.143 seconds

Get Started