I have two customization that I need in my Omeka site. Maybe you guys can help :)

210 views
Skip to first unread message

CJ Obermaier

unread,
Mar 13, 2013, 1:56:44 PM3/13/13
to omek...@googlegroups.com
So I have two things that I need to do in my Omeka site.

The first is to hide elements when a certain user is not logged in. For example,

Item name - Photo 1
Date - 9-12-1998
Subject - Art
Creator - James A. Smith
Language - English

Lets say that for the public, I do not wish for Language to be viewable, but if a user logs in, like contributor, they will be able to see that field on the site. 

The second question i have is, is it possible to add a custom element to the existing Dublin Core set? I need to add the field 'price' (also the field that I need to hide from the public). I tried adding it several different way, none worked.

Thanks in advance to anyone who can help! I will be working on trying to figure this out today, so I will update when I can.

Jeremy Boggs

unread,
Mar 13, 2013, 2:32:56 PM3/13/13
to omek...@googlegroups.com
If you're specifically echoing these fields in your items/show.php template in your theme, you could wrap those calls with a check to see if there's an authenticated user:

<?php if (current_user()): ?>
…display metadata field;
<?php endif; ?>

If you're just relying on the default view helper to display all the item metadata, you could filter that list and only show those fields, using the 'display_elements' filter in Omeka 2.0. You could add something like the following to your theme's custom.php file:


There's probably a better way to write this (if so do fork the gist!), but it worked OK after a quick check on my local Omeka installation. There a variable defined in the function called $hiddenElements, which has an array of sets and elements in the set you'd want to hide from non-authenticated users.

As for your second question, it is technically possible to add a custom element set to the existing Dublin Core set (the Dublin Core Extended plugin does this), but I'm not sure the metadata standards folks on the list would advise you no to do so. You'd have to do it with a plugin, so if you do want to, looking over how the DC Extended plugin takes care of this would be a good place to start.

Hope this helps,
Jeremy

--
You received this message because you are subscribed to the Google Groups "Omeka Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to omeka-dev+...@googlegroups.com.
To post to this group, send email to omek...@googlegroups.com.
Visit this group at http://groups.google.com/group/omeka-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

CJ Obermaier

unread,
Mar 13, 2013, 6:21:32 PM3/13/13
to omek...@googlegroups.com
I am having trouble finding the location in my theme to use that code that you linked me. I amusing seasons theme. I'm looking around it, but I see nothing that stands out. I am not very familiar with PHP.

Thanks

Jeremy Boggs

unread,
Mar 14, 2013, 8:54:34 AM3/14/13
to omek...@googlegroups.com
You'll need to put that in your theme's custom.php file. You'll have to make that file if your theme doesn't already have one. This should be the path to it, assuming your omeka instance is 'your-omeka'

your-omeka/themes/seasons/custom.php

Jeremy

CJ Obermaier

unread,
Mar 14, 2013, 5:23:06 PM3/14/13
to omek...@googlegroups.com
Okay cool. I will start working on that. As for adding a field, could I edit the DC extender plug in before I install it to add those fields? That would seem to be the easiest?

Thanks for all of your help man. I really appreciate it. I'm a bit lost here

CJ Obermaier

unread,
Mar 14, 2013, 6:01:46 PM3/14/13
to omek...@googlegroups.com
Figured out how to edit the plug in :) Now I just need to figure out how to add more fields.

It's all coming together! 
Message has been deleted

CJ Obermaier

unread,
Apr 15, 2013, 9:46:52 AM4/15/13
to omek...@googlegroups.com
Hey Jeremy,

So I am adding a new element plug in (with the instructions that you had from another post) with 4 fields that I need hidden. As of now they are automatically called. How would I called them each specifically so I can put them in the if current user brackets that you have shown me below?

CJ Obermaier

unread,
Apr 15, 2013, 10:07:56 AM4/15/13
to omek...@googlegroups.com
I got your code to finally work! I was putting it in the wrong place. Thanks so much Jermey!!!


On Mon, Apr 15, 2013 at 8:46 AM, CJ Obermaier <cjobe...@gmail.com> wrote:
Hey Jeremy,

So I am adding a new element plug in (with the instructions that you had from another post) with 4 fields that I need hidden. As of now they are automatically called. How would I called them each specifically so I can put them in the if current user brackets that you have shown me below?

--
You received this message because you are subscribed to a topic in the Google Groups "Omeka Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/omeka-dev/7eHz2DFeNBA/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to omeka-dev+...@googlegroups.com.

To post to this group, send email to omek...@googlegroups.com.
Visit this group at http://groups.google.com/group/omeka-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
CJ Obermaier
CIS Major Drury University
Drury Catholics - Secretary 
Sigma Nu -  Epsilon Beta
Cell - 417-468-3433

CJ Obermaier

unread,
Apr 15, 2013, 10:29:33 AM4/15/13
to omek...@googlegroups.com
So it works for hiding my Dublin Core elements. How would I get it to hide my custom element set that I made using your element plug in?

John Flatness

unread,
Apr 15, 2013, 10:42:00 AM4/15/13
to omek...@googlegroups.com
You should be able to just add your set and the elements from it you want to hide to the $hiddenElements array of Jeremy's code.

CJ Obermaier

unread,
Apr 15, 2013, 11:04:41 AM4/15/13
to omek...@googlegroups.com
I tried. I kept all of the default information from the element plug in. In that code, there is the following

 $elementSetMetadata = array(
            'name'        => self::ELEMENT_SET_NAME, 
            'description' => self::ELEMENT_SET_DESCRIPTION
        );

So what i did is I took self::ELEMENT_SET_NAME and place it here from the hide element code
 $hiddenElements = array(
        'ELEMENT_SET_NAME' => array(
            'Description',
            'Creator',
            'Medium'
        )
    );


Is this not how I am supposed to do it?

John Flatness

unread,
Apr 15, 2013, 11:14:39 AM4/15/13
to omek...@googlegroups.com
Are these two pieces of code actually in the same class?

"self" refers to the current class, so if the filter code isn't in the
same class (or any class at all), you can't use self::ELEMENT_SET_NAME.

You can refer to it as TheClassName::ELEMENT_SET_NAME instead, where
TheClassName is the name of the class that contains the first of the two
code snippets you posted.

-John
> https://groups.google.com/d/__topic/omeka-dev/7eHz2DFeNBA/__unsubscribe?hl=en
> <https://groups.google.com/d/topic/omeka-dev/7eHz2DFeNBA/unsubscribe?hl=en>.
> To unsubscribe from this group and all its topics, send
> an email to omeka-dev+...@__googlegroups.com.
> To post to this group, send email to
> omek...@googlegroups.com.
>
> Visit this group at
> http://groups.google.com/__group/omeka-dev?hl=en
> <http://groups.google.com/group/omeka-dev?hl=en>.
> For more options, visit
> https://groups.google.com/__groups/opt_out
> <https://groups.google.com/groups/opt_out>.
>
>
>
>
>
> --
> CJ Obermaier
> CIS Major Drury University
> Drury Catholics - Secretary
> Sigma Nu - Epsilon Beta
> Cell - 417-468-3433
>
>
>
>
> --
> CJ Obermaier
> CIS Major Drury University
> Drury Catholics - Secretary
> Sigma Nu - Epsilon Beta
> Cell - 417-468-3433 <tel:417-468-3433>
>
> --
> You received this message because you are subscribed to a topic in
> the Google Groups "Omeka Dev" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/omeka-dev/7eHz2DFeNBA/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to
> omeka-dev+...@googlegroups.com
> <mailto:omeka-dev%2Bunsu...@googlegroups.com>.
> To post to this group, send email to omek...@googlegroups.com
> <mailto:omek...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/omeka-dev?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
>
>
> --
> CJ Obermaier
> CIS Major Drury University
> Drury Catholics - Secretary
> Sigma Nu - Epsilon Beta
> Cell - 417-468-3433
>
> --
> You received this message because you are subscribed to the Google
> Groups "Omeka Dev" group.
> To unsubscribe from this group and stop receiving emails from it, send

CJ Obermaier

unread,
Apr 15, 2013, 11:25:06 AM4/15/13
to omek...@googlegroups.com
I don't think they are in the same class. 

So I change the code to the following, but it still didn't work. Im almost positive CustomElementSet is the class that is in my plug in. 

$hiddenElements = array(
        'CustomElementSet::ELEMENT_SET_NAME' => array(

CJ Obermaier

unread,
Apr 15, 2013, 11:40:15 AM4/15/13
to omek...@googlegroups.com
It may help if I post more of my code. I think the issue is that the plug in calls the elements for me. I don't see the code for the custom elements like I do for the Dublin Core elements. Here is the top half of my show.php and I have the filter code already pasted in

<?php echo head(array('title' => metadata('item', array('Dublin Core', 'Title')),'bodyclass' => 'item show')); ?>

<h1><?php echo metadata('item', array('Dublin Core', 'Title')); ?></h1>

<?php
/**
 * Unset elements if there is not current authenticated user.
 */
function filter_elements($elementsBySet) {
 
    /* An array of elements in sets to be hidden from non-authenticated users. */
    $hiddenElements = array(
        'CustomElementSet' => array(
            'Description',
            'Creator',
            'Medium'
        )
    );
 
    if (!current_user()) {
        foreach ($hiddenElements as $setName => $elementNames) {
            foreach ($elementNames as $elementName) {
                unset($elementsBySet[$setName][$elementName]);
            }
        }
    }
 
    return $elementsBySet;
}
 
add_filter('display_elements', 'filter_elements');
?>
<div id="primary">
    
    <?php echo all_element_texts('item'); ?>


</div><!-- end primary -->


Now, here is some of the code from the custom elements plug in that Jeremey posted a while ago

class CustomElementSet
{
public static $elements = array(
        array(
            'name'           => 'Creator',
            'description'    => 'The creator',
            'record_type'    => 'Item',


CJ Obermaier

unread,
Apr 15, 2013, 11:41:58 AM4/15/13
to omek...@googlegroups.com
It may help if I post more of my code. I think the issue is that the plug in calls the elements for me. I don't see the code for the custom elements like I do for the Dublin Core elements. Here is the top half of my show.php and I have the filter code already pasted in
<?php echo head(array('title' => metadata('item', array('Dublin Core', 'Title')),'bodyclass' => 'item show')); ?>

<h1><?php echo metadata('item', array('Dublin Core', 'Title')); ?></h1>

<?php
/**
 * Unset elements if there is not current authenticated user.
 */
function filter_elements($elementsBySet) {
 
    /* An array of elements in sets to be hidden from non-authenticated users. */
    $hiddenElements = array(
        'CustomElementSet' => array(
            'Description',
            'Creator',
            'Medium'
        )
    );
 
    if (!current_user()) {
        foreach ($hiddenElements as $setName => $elementNames) {
            foreach ($elementNames as $elementName) {
                unset($elementsBySet[$setName][$elementName]);
            }
        }
    }
 
    return $elementsBySet;
}
 
add_filter('display_elements', 'filter_elements');
?>
<div id="primary">
    
    <?php echo all_element_texts('item'); ?>


</div><!-- end primary -->

Now, here is some of the code from the custom elements plug in that Jeremey posted a while ago

class CustomElementSet
{
public static $elements = array(
        array(
            'name'           => 'Creator',
            'description'    => 'The creator',
            'record_type'    => 'Item',
),

     /**
         * Use our class constants to create an array of element set metadata,
         * for use in the insert_elmement_set() function later.
         */
        $elementSetMetadata = array(
            'name'        => self::ELEMENT_SET_NAME, 
            'description' => self::ELEMENT_SET_DESCRIPTION
        );

Jeremy Boggs

unread,
Apr 16, 2013, 9:38:38 AM4/16/13
to omek...@googlegroups.com
You'll need to add the code I provided in that gist to a file named 'custom.php' in the root of your theme, not in the items/show.php file. It won't work in the show.php file. If you don't have a custom.php file, just create one, and copy/paste my gist into there.

Jeremy

CJ Obermaier

unread,
Apr 16, 2013, 10:51:43 AM4/16/13
to omek...@googlegroups.com
I got it working! Thanks guys!!


--
You received this message because you are subscribed to a topic in the Google Groups "Omeka Dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/omeka-dev/7eHz2DFeNBA/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to omeka-dev+...@googlegroups.com.

To post to this group, send email to omek...@googlegroups.com.
Visit this group at http://groups.google.com/group/omeka-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 
Reply all
Reply to author
Forward
0 new messages