Different categories of entries in one database

Different categories of entries in one database

by Martin Mastny -
Number of replies: 12
Picture of Core developers Picture of Peer reviewers Picture of Testers

Hi everyone, I'd like to ask you for a little bit of advice. I need to create a database of samples in moodle. Each sample has a common fields like name, id, color etc. but there are 4 different kinds of samples and each of these 4 kinds has 2 or 3 category specific fields, which are only in this category. Since all samples belong to one set, I'd like to avoid creating 4 different database modules.

How can I achieve this in one database activity?  

Thanks for suggestions

Martin

Average of ratings: -
In reply to Martin Mastny

Re: Different categories of entries in one database

by William Lu -
Picture of Particularly helpful Moodlers

Hi Martin,

I am not exactly sure what you really want to do. I just guess that you would like users to select a category first, then fill out other fields,

This post may be helpful:

https://moodle.org/mod/forum/discuss.php?d=314893#p1264489

In reply to William Lu

Re: Different categories of entries in one database

by Martin Mastny -
Picture of Core developers Picture of Peer reviewers Picture of Testers

Hi William,

thanks for your reply, I tried to look at the post you suggested, but unfortunately it did not help. I'll try to be more specific:

I need to create a database(database activity module) of materials in moodle. Since those are only materials it makes sense to keep them in a single module to make searches easier etc.

Every material has 2 common fields - name and price per kg. I'll start with two material wood and steel. 

No problem so far smile

But there are some properties of each material that the other does not have. For example steel has a conductivity index and wood has combustion heat.

My question is how to deal with this when creating a template. I'd like only those fields, which are relevant to each material to be displayed to students:


material wood
price per kg 20
combustion heat  5

materialsteel
price per kg35
conductivity 0,8

In fact there's going to be more 'different' fields (4 or 5), so "not applicable" approach is not a good solution I believe.
I hope it's clearer now smile

Thank you

Martin


In reply to Martin Mastny

Re: Different categories of entries in one database

by Itamar Tzadok -

If you can use add-ons you may want to consider the Dataform module. It has originated from the Database module but is much richer and more flexible. You can create multiple view templates and filters to display different subsets of entries and/or add/edit entries of particular types (e.g. the view for wood entry and the view for steel entry will display different subsets of fields).

hth smile

Average of ratings: Useful (1)
In reply to Itamar Tzadok

Re: Different categories of entries in one database

by Martin Mastny -
Picture of Core developers Picture of Peer reviewers Picture of Testers

Hi Itamar, great module, thanks. I have only one difficulty. I dont see a way how to connect view to a template. Can you suggest something? I was looking at filters, but the purpose seems to be different.

Thanks 

Martin

In reply to Martin Mastny

Re: Different categories of entries in one database

by Itamar Tzadok -

Not sure I follow what you're trying to do. If you could give more details that would be great. But as this is a Dataform specific query, let's continue this discussion in the Dataform forum. smile

In reply to Martin Mastny

Re: Different categories of entries in one database

by Martin Mastny -
Picture of Core developers Picture of Peer reviewers Picture of Testers
As I investigated further, the module seems even greater smile I found the way how to do this. It's just the learning curve is pretty "perpendicular", but I wasn't expecting it to be different, so thanks for the module Itamar 
In reply to Martin Mastny

Re: Different categories of entries in one database

by Robert Brenstein -
If there are only 4-5 property fields, you may just have all fields listed for each item, those which are not applicable being empty. You will need all in the list view anyway. If you have a reliable entry person, you could also go to the other extreme and have a single field for all properties.
In reply to Martin Mastny

Re: Different categories of entries in one database

by William Lu -
Picture of Particularly helpful Moodlers

Hi Matin,

Look like you want to hide 'Empty' fields in 'Single view'.

If so, you need one line of Javascript like this: 

if ('density' == '') {
       document.getElementById('density').style.display='none';
}

If this what you need, you can download the attached preset, which is my rough mockup.

Credit: Code copied from this forum, but forgot which post. My thanks go to that Moodler smile

Disclaimer:

1. If users disabled the JS in their browser, it won't work.

2. Templates need more fine tune to make them looking good.

3. The number in those screenshots below are not scientifically correct, just my dummy content.

4. Created on Moodle2.6, will be better if combine the new 'Compulsory field' in Moodle2.9. 

5. Haven't tested it in different browsers nor other Moodle versions yet. 

6. Please let me know if it works for you.

Add

V1

v2

list


(Please Rate... if this useful for someone smile)

Average of ratings: Useful (1)
In reply to Martin Mastny

Re: Different categories of entries in one database

by William Lu -
Picture of Particularly helpful Moodlers

Hi Martin,

Here is another example, without the need of Javascript, can be used in any version of Moodle.

As Robert said,  If you have a reliable entry person, and he/she doesn't mind of doing one more click on Hide/Show radio button, then it will be more robust than the JS version.

addd

s1

s2

l2

I designed this last year when I haven't learnt JS yet.

Yo can found my detailed instruction from here: https://moodle.net/mod/data/view.php?d=1&rid=93


HTH

Average of ratings: Useful (1)
In reply to Martin Mastny

Re: Different categories of entries in one database

by Martin Mastny -
Picture of Core developers Picture of Peer reviewers Picture of Testers

Thank you all for your help. I'll go thru all solutions and decide, which suits the best

Cheers Martin