Fork me on GitHub

Page alphabetically?  Bottom

  • I have a lot of lists, and they're sorted alphabetically, but currently they're separated into lists of 10, and it's hard to figure out where the letter you're looking for is. What I'd like to do is maybe put an alphabet on top so they can click on a letter and have it bring up a page with the first entry being the first starting with that letter. Is there a way to do this without complicated programming hoop-jumping? :)
  • Hey jedi have you taken a look at the pnEmployee module ( and advanced contacts module ) it has a function like that though it uses the old pnHTML methods rather than pnrender it might be able to give you an idea since you are better at reading and understanding the code than the likes of myself.



    -SUNADMN
  • Where would I find these modules? I always have a hard time finding modules, for some reason. There's probably a scientific name for it. :D
  • If you would like I can just send it to you I have them all stored on my system just PM me a place to send it and I will ( I forgot where I got it from myself ).
  • Thanks! I'll take a look and see what I can figure out.
  • For pnRender there's a companion to the pager plugin called pagerabc that can create an alphabetic filter. For an example see the members list module on my site (now running .760RC1).

    -Mark

    --
    Visit My homepage and Zikula themes.
  • After quite a lot of poking, I think I have this solved.

    I had to pass a new variable, which is the first letter of the page I want to look at. So I picked $startlet. I then re-did my SQL so that it returned only things LIKE $startlet%, then just did Execute, rather than SelectLimit for the query. Worked a treat. :)

    Here's my code, if you're interested.

    API

    Code

    function projects_userapi_getall_projects($args)
    {
        // Get arguments from argument array
        extract($args);
       
        // Optional arguments.
        if (!isset($startlet)) {
            $startlet= 'A';
        }

        $items = array();

        // Security check - important to do this as early on as possible to
        // avoid potential security holes or just too much wasted processing
        if (!pnSecAuthAction(0, 'projects::', '::', ACCESS_OVERVIEW)) {
            return $items;
        }

        // Get datbase setup
        $dbconn =& pnDBGetConn(true);
        $pntable =& pnDBGetTables();
       
        $projecttable = $pntable['project_projects'];
        $projectcolumn = &$pntable['project_projects_column'];

        // Get items
        $sql = "SELECT $projectcolumn[projid],
                    $projectcolumn[givennum],
                    $projectcolumn[title],
                    $projectcolumn[summary],
                    $projectcolumn[budget],
                    $projectcolumn[length],
                    $projectcolumn[status],
                    $projectcolumn[startdate],
                    $projectcolumn[enddate],
                    $projectcolumn[updated]
                FROM $projecttable
                WHERE $projectcolumn[title] LIKE '"
    .$startlet."%'
                ORDER BY $projectcolumn[title]"
    ;
                                       
        $result = $dbconn->Execute($sql);

        // Check for an error with the database code, and if so set an appropriate
        // error message and return
        if ($dbconn->ErrorNo() != 0) {
            pnSessionSetVar('errormsg', _GETFAILED);
            return false;
        }

        // Put items into result array.  Note that each item is checked
        // individually to ensure that the user is allowed access to it before it
        // is added to the results array
        for (; !$result->EOF; $result->MoveNext()) {
            list($projid, $givennum, $title, $summary, $budget, $length, $status,  $startdate, $enddate, $updated) = $result->fields;
            if (pnSecAuthAction(0, 'projects::', "$title::$projid", ACCESS_OVERVIEW)) {
                $items[] = array('projid' => $projid,
                                 'givennum' => $givennum,
                                 'title' => $title,
                                 'summary' => $summary,
                                 'budget' => $budget,
                                 'length' => $length,
                                 'status' => $status,
                                 'startdate' => $startdate,
                                 'enddate' => $enddate,
                                 'updated' => $updated);
            }
        }

        // All successful database queries produce a result set, and that result
        // set should be closed when it has been finished with
        $result->Close();

        // Return the items
        return $items;
    }


    Relevant pnuser code:

    Code

    function projects_user_view_projects($args)
    {
        // Security check
        if (!pnSecAuthAction(0, 'projects::', '::', ACCESS_OVERVIEW)) {
            return pnVarPrepHTMLDisplay(_MODULENOAUTH);
        }

        // Get parameters from whatever input we need.
        $startlet = pnVarCleanFromInput('startlet');
        if (!isset($startlet)) {
            $startlet = 'A';
        }

        // Load API.  
        if (!pnModAPILoad('projects', 'user')) {
            return pnVarPrepHTMLDisplay(_LOADFAILED);
        }

        // The API function is called.  
        $items = pnModAPIFunc('projects',
                              'user',
                              'getall_projects',
                              array('startlet' => $startlet));
    ...


    $pnRender->assign('items', $projectitems);

        // assign the values for the smarty plugin to produce a pager in case of there
        // being many items to display.
       
        $pnRender->assign('pagerabc', array('numitems'     => pnModAPIFunc('projects',
                                                                        'user',
                                                                        'countitems_projects'),
                                         'itemsperpage' => $itemsperpage));
        // Let any hooks know that we are displaying the overview.
        $pnRender->assign('hooks' ,pnModCallHooks('category',
                                                  'display',
                                                  $startlet,
                                                  pnModURL('projects',
                                                           'user',
                                                           'view_projects',
                                                           array('startlet' => $startlet))));

    }


    htm template code:

    Code

    <!--[pagerabc  show="page"
                    posvar="module=Projects&type=admin&func=view_projects&startlet"
                    separator=" &nbsp;-&nbsp; "
                    names="A;B;C;D;E;F;G;H;I;J;K;L;M;N;O;P;Q;R;S;T;U;V;W;X;Y;Z"]-->
  • markwest

    For pnRender there's a companion to the pager plugin called pagerabc that can create an alphabetic filter. For an example see the members list module on my site (now running .760RC1).

    -Mark


    \i see you have a new theme installed - quite nice. I also notice that your memberslist URL comes up like this:

    http://www.markwest.me.uk/index.php?&module=Members_List&func=main&letter=H

    just curious, whats with the ampersand straight after the question mark? is this something for mod rewrite shorturl stuff?

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • Lobos,

    Thanks for comments on the theme - Not mine however.... It's a port of a drupal port of a wordpress template (see the link at the bottom). Still I think it looks really nice and clean - it also gives me the oppurtunity to show a few of the simpler things you can do with .760 and the starting of full templating of modules.

    The extra ampersand is a 'feature' of the alpha pager that i've yet to fix properly. In the template you tell the plugin what variables to pass back on. So in this case the vars module, type & func get added in addition to the letter in the pager urls. The plugin doesn't quite spot which one is the first var hence the extra ampersand.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • markwest

    Lobos,

    The extra ampersand is a 'feature' of the alpha pager that i've yet to fix properly. In the template you tell the plugin what variables to pass back on. So in this case the vars module, type & func get added in addition to the letter in the pager urls. The plugin doesn't quite spot which one is the first var hence the extra ampersand.


    Ah I thought this may have been the case, it´s a loop thing, correct? It is at times vexing when you have things that come up like this - every thing is identical but the first variable / item / thing - infact they should have just made these urls without the ? and just started with plain ole & (i guess they need to know when the URL stops though...).

    --
    -Lobos
    Professional PHP Framework Services: Concept, Development and Deployment
  • I get the extra &, too. I called the position variable the whole module call plus the variable name in order to get it to work right. Glad to know I'm not the only one! :D
  • I've fixed this little bug in cvs. The urls still work so it's not really major problem. However grab a an updated version of the plugin from cvs to fix the problem.

    -Mark

    --
    Visit My homepage and Zikula themes.
  • Is there anything else I should change in addition? I seem to still be getting the &, but that might just be because my code is off somewhere.
  • Hi there...I've been trying to figure out how to do an alphabetical pager. I'm working on translating a language, and I have a list of translated words that I'd like to be able to sort alphabetically...I noticed that the "Modules" module has an alphabetical pager...I was wondering if i could scoop the pager code from there and tweak it to work on the list.

    Some background...I'm running the most recent release of Zikula, and my language list is incorporated into a module called EckDec that I developed by tweaking the example module

    Any feedback is welcome!!!


    P.S. in case you wanted to take a look... here is the URL to my test site

    http://bennukhepera.…type=user&func=view



    edited by: BennuKhepera, Sep 09, 2008 - 09:45 PM
  • 0 users

This list is based on users active over the last 60 minutes.