producing a list from entity annotations

Hi All,

I'm just chasing some help as to achieve a page that lists all entities by a specific annotation.

Initially I'm thinking i'd like to have a pulldown menu of all the annotation names to produce the list. I am struggling a bit with this; i have attempted to duplicate the widely used everyone.php for myplugin and call it bycity.php. But I find it hard to comprehend how to on the same page have an input that triggers a refresh and produces a list from the value of the input. Any help, or pointers to existing code/elgg source would be greatly appreciated.

Any help would be super super duper awesome and appreciated.

Here's where I'm up to or how I've gone about the bycity.php

<?php

    // Load Elgg engine
    require_once(dirname(dirname(dirname(__FILE__))) . "/engine/start.php");
   
    // Lets get the names of the annotations

    $mypluginposts = elgg_get_entities(array('type'=>'object','subtype'=>'myplugin'));

    $myplugincities = $mypluginposts->getAnnotations('city');
   
    // Lets create a pulldown at the top of the page to choose a city FROM all available, existing cities
   
         $area2 = "<div class=\"contentWrapper\"><label>" . elgg_echo("Choose a city: ") . "<br /></label>" ;
          $area2 .= "<label>". elgg_view('input/pulldown',array(

       !!!----> HOW do i create a for each as to provide the all the cities for the pulldown !!!
         
    // Get input
    $selectedcity = get_input('!!! as above !!!')


    $bycityposts = elgg_get_entities(array('type'=>'object' , 'subtype'=>'myplugin', 'city'=>$selectedcity ));

    foreach($bycityposts as $bycitypost) {
        $area2 .= "<br/><small>{$bycitypost} </small>";
       
    }    

// go on to draw the page

Any ideas?

Thanks for reading :D

  • If you want someone to select from a list and have the page update, you'll want to use ajax. jQuery makes this very easy. I would first get it working without ajax using a form that is submitted so that you can work out all the Elgg details and then move it to use ajax.

  • Thanks Cash - Ok form it is. Should be simple enough ;D

    I know i (and prob others) will need to generate pulldowns that are filled with object titles or other annotations. Is there an example anywhere or can you offer an insight into how to incorporate these into the elgg_view('input/pulldown',array(  ...foreach?

     

  • Each of the input views has documentation on its parameters at the top of the view file:

     * @uses $vars['value'] The current value, if any
     * @uses $vars['js'] Any Javascript to enter into the input tag
     * @uses $vars['internalname'] The name of the input field
     * @uses $vars['options'] An array of strings representing the options for the pulldown field
     * @uses $vars['options_values'] An associative array of "value" => "option" where "value" is an internal name and "option" is the value displayed on the button. Replaces $vars['options'] when defined.

    In this case:

    $city_names = array('London', 'Paris', ...);
    $params = array(
    'internalname' => 'city',
    'value' => 'default if any',
    'options' => $city_names
    );
    echo elgg_view('input/pulldown', $params);
  • exactly what I needed! :) Thanks heaps Cash.

    ...wish i'd got the getAnnotaions bit right though (at the top) so i have a list of cities produced from annotations on myplugin) -> I'll edit the 1st post so it's not misleading to anyone on the community searching for similar once I get it right!

    :D :D :D

     

  • I'm using the following to fill a pulldown menu in a form with cities from a plugin to be used to filter search results:

        $posts = elgg_get_entities(array('type'=>'object','subtype'=>'myplugin'));

        foreach ($posts as $post) {
            $value = $barspost->city;
            $city_names[] = $value;  //<-- This adds cities to the array
        }
          $city_count = count($city_names);
       
        $params = array(
            'internalname' => 'selectcity',
            'value' => 'default if any',
            'options' => $city_names
        );


    then the form:


              $form_body .= "<label><strong>".elgg_echo('Search by city: ')."</strong><br />" . "<br />". elgg_view('input/pulldown', $params) ."</label><br />";


    then the on the page for the search results:

           $citysearch = get_input('selectcity', 0);

    $posts = elgg_get_entities(array('type'=>'object','subtype'=>'myplugin'));

    foreach($posts as $post) {
                    if ($post->city == $citysearch) {  

    list the entities that match the city.

    This works fine with the exception of one problem. As myplugin objects get created by the community, users enter a variety of cities. As cities get duplicated they are also duplicated in the pulldown menu. Obviously as it is going thru each post and adding whatever city to the array it gets repetition. It would be great to be able to void already existing entries before the call to $city_names[] = $value; 

    and also to sort the pulldown output alphabetically....actually i just realised i can influence the order as the $post = elgg_get_entities_from_metadata is used.

    But any ideas on removing the duplications would be appreciated...?

    any problems, errors or bad code here. Please let me know - Seems to work for me :D