• Resolved Pyrolobus

    (@pyrolobus)


    Hi,

    I’m setting up a database for my lab with two complete different types of items (primers and chemicals). I didn’t have problem to make two separated pages to display them as if they were in two different databases. This two categories only have in common two fields: one for the type of the item which is only shown when a new item is registered, and the name (I left this field with a very generic name to be able to link both subsets of the database without problem)

    However, the remaining fields are either for chemicals or for primers, resulting in a page containing the pdb_single shortcode that has one or another half of the info in blank.

    So, there is any way to have two different outputs? Like a conditional command in the shortcode or having two subsets of code… I almost don’t know anything about PHP

    And congratulations for the great plugin.

    https://www.ads-software.com/extend/plugins/participants-database/

Viewing 11 replies - 1 through 11 (of 11 total)
  • Plugin Author xnau webdesign

    (@xnau)

    You can list the fields to show in the shortcode: [pdb_single fields=”field1,field2″]

    Thread Starter Pyrolobus

    (@pyrolobus)

    If I had just a one single type of item that would work.

    Maybe I didn’t explain properly.

    Item type 1 has: field0, field1, field2, field3
    Item type 2 has: field0, field4, field5, field6

    So when I see the single record for item type 1 I want a page with [pdb_single fields=”field0,field1,field2,field3]
    and for records of item type 2: [pdb_single fields=”field0,field4,field5,field6]

    Can be done this?

    Plugin Author xnau webdesign

    (@xnau)

    Yes, that is exactly what you would do. Put each shortcode on it’s own page, and it will only show those fields.

    There is another way, as you suggest: If you create a custom template (instructions here) for the record shortcode, you can determine which set of fields is displayed depending on the value of a field. You have to work it backwards because the template will exclude fields from displaying according to the $exclude array. Let’s say your determining field is named ‘type’ you’d do something like this in your template….where you have the line “$exclude = array()” replace that with:

    if ($this->record->participant_values->type == 'typeA') {
    $exclude = array('typeB_field1','tpyeB_field2');
    } else {
    $exclude = array('typeA_field1','typeB_field2');
    }

    `

    Thread Starter Pyrolobus

    (@pyrolobus)

    Regarding the first suggestion, I tried but I don’t know how to make the links for one or other item to redirect to a different page. Users will need to access the data after search the item they want.

    About the second option, it doesn’t seem to work. Do I have to modify any other file to tell the plugin where is the template?

    Plugin Author xnau webdesign

    (@xnau)

    Well, there are several ways it could be not working. When the shortcode runs, it will first look in your theme directory for “templates/pdb-single-default.php” That is where your custom template should be.

    It is possible to specify a template in the shortcode, but if you don’t it will look for one with the name I gave above.

    If you’re unsure if the custom template is being used, you can add some kind of text to the HTML that will display if it’s being used. The code I gave you must go at the top of the template, where the $exclude array is defined, replacing that definition.

    Thread Starter Pyrolobus

    (@pyrolobus)

    I had a problem with the repository so the file was not being placed in the server.

    Anyway, now it seems that it is being processed but not as it should

    if ($this->record->participant_values->item_type == 'Chemical') {
    $exclude = array('target','sequence','size','designer','project','labbook','box');
    } else {
    $exclude = array('product_id','manufacturer','supplier','original_quantity','location','number_of_items','hazards');
    }

    So this is the code introduced. For some reason, the first group of excluded fields (target,sequence, etc) are not really being excluded whatever the item type is, and the others (product_id, manufacturer, etc) are being excluded always. I don’t know if there is a spelling or code mistake… I just copy/paste the code you gave me and replace the necessary fields. Can you check if there is something wrong?

    Thank you

    Plugin Author xnau webdesign

    (@xnau)

    Oops, gave you the wring variable name… the first line of the mod should be:

    if ($this->participant_values['item_type'] == 'Chemical') {

    Thread Starter Pyrolobus

    (@pyrolobus)

    It works!!
    Thanks a lot!!

    Just one thing, is it possible to exclude e.g. a group of fields? I have the fields organised in groups and when excluded the titles of the groups of field keep showing

    Plugin Author xnau webdesign

    (@xnau)

    If you want to exclude a whole group, you have two options: either uncheck the “display” checkbox for that group, or edit a custom template to skip over the group. This works pretty much exactly as the “exclude” array for fields, only the code goes just after the “$this->the_group()” statement.

    Thread Starter Pyrolobus

    (@pyrolobus)

    But if I uncheck the “display” option it won’t show in any other place, isn’t it?

    In case of editing the pdb-single, it would work as conditional statement as with the fields?

    By the way, the previous piece of code

    if ($this->participant_values['item_type'] == 'Chemical') {
    $exclude = array('target','sequence','size','designer','project','labbook','box');
    } else {
    $exclude = array('product_id','manufacturer','supplier','original_quantity','location','number_of_items','hazards');
    }

    Could be used somehow for more than 2 groups? Or would I need something else? I saw a post using groups of arrays but I don’t have it clear…

    Plugin Author xnau webdesign

    (@xnau)

    OK I’ll explain. Yes, unchecking “display” will hide the group everywhere…if that’s not what you want, then you need to do it in the template.

    I’d do something like this in the template…after the line with “$this->the_group()” Since you asked about more than one group I’ll show you that…

    <?php if (in_array($this->group->name, array('group1', 'group2') ) ) continue ?>

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘two types of pdb_single outputs’ is closed to new replies.