1
tzvook
Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/2/24 8:52

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Hi All

Quite long ago I needed alphabetic sorting for the Xdir, with help from riaanvdb I got it to work.
I didn't used it for a while, but now I found out it acts weirdly!!! very weirdly

Sometimes it gives the right list in the right letter, sometimes it don't (clicking "a" or "b" or "c" or "d" gives the "a" list all the time, but clicking on "g" gives the "g" list all the time - it acts badly ... but in a constant manner , and I really don't see the logic in it.

It comes originaly (I think ... don't remember) from the WF downloads alphanetic sorting - looks almost the same

I post the codes here for someone to take a look, changed from Hebrew to English .....

file: include/functions.php (eof - at the end of it add this function)

function letters()
{
    global 
$xoopsModule;

    
$letterchoice .= "[  ";
    
$alphabet = array ("0""1""2""3""4""5""6""7""8""9""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");
    
$num count($alphabet) - 1;
    
$counter 0;
    while (list(, 
$ltr) = each($alphabet))
    {
        
$letterchoice .= "$ltr' style='font-size: 11px;'>$ltr";
        if (
$counter == round($num 2))
            
$letterchoice .= " ][ ";
        elseif (
$counter != $num)
            
$letterchoice .= " | ";
        
$counter++;
    } 
    
$letterchoice .= " ]";
    return 
$letterchoice;
}


viewlist.php (complete) looks like this:
include "header.php";
$myts =& MyTextSanitizer::getInstance(); // MyTextSanitizer object
include_once XOOPS_ROOT_PATH."/class/xoopstree.php";
$mytree = new XoopsTree($xoopsDB->prefix("xdir_cat"),"cid","pid");
$xoopsOption['template_main'] = 'xdir_viewlist.html';
include 
XOOPS_ROOT_PATH."/header.php";
//generates top 10 charts by rating and hits for each main category

$list $HTTP_GET_VARS['list'];
$rate $HTTP_GET_VARS['rate'];

// Tzvook //
$letters letters();
$xoopsTpl->assign('letters'$letters);
$xoopsTpl->assign('xmid'$xoopsModule->getVar('mid'));

if(isset(
$rate)){
    
$sort _MD_RATING;
    
$sortDB "rating";
}else{
    
$sort _MD_HITS;
    
$sortDB "hits";
}
$xoopsTpl->assign('lang_sortby' ,$sort);
$xoopsTpl->assign('lang_rank' _MD_RANK);
$xoopsTpl->assign('lang_phone'_MD_BUSPHONE);
$xoopsTpl->assign('lang_title' _MD_TITLE);
$xoopsTpl->assign('lang_category' _MD_CATEGORY);
$xoopsTpl->assign('lang_hits' _MD_HITS);
$xoopsTpl->assign('lang_rating' _MD_RATING);
$xoopsTpl->assign('lang_vote' _MD_VOTE);
$arr=array();
$result=$xoopsDB->query("select cid, title from ".$xoopsDB->prefix("xdir_cat")." where pid=0");
$e 0;
$rankings = array();
while(list(
$cid$ctitle)=$xoopsDB->fetchRow($result)){
    
$rankings[$e]['title'] = sprintf(_MD_TOP10$myts->htmlSpecialChars($ctitle));
    
$query "select lid, cid, title, phone, hits, rating, votes from ".$xoopsDB->prefix("xdir_links")." where status>0 and (title LIKE '$list%'";
    
// get all child cat ids for a given cat id
    
$arr=$mytree->getAllChildId($cid);
    
$size count($arr);
    for(
$i=0;$i<$size;$i++){
        
$query .= " or cid=".$arr[$i]."";
    }
    
$query .= ") order by ".$sortDB." DESC";
    
$result2 $xoopsDB->query($query,50,0);
    
$rank 1;
    while(list(
$lid,$lcid,$ltitle,$phone,$hits,$rating,$votes)=$xoopsDB->fetchRow($result2)){
        
$catpath $mytree->getPathFromId($lcid"title");
        
$catpathsubstr($catpath1);
        
$catpath str_replace("/",» "
,$catpath);
        
$rankings[$e]['links'][] = array('id' => $lid'cid' => $cid'rank' => $rank'title' => $myts->htmlSpecialChars($ltitle), 'category' => $catpath'hits' => $hits'rating' => number_format($rating2), 'votes' => $votes'phone' => $phone);
        
$rank++;
    }
    
$e++;
}
$xoopsTpl->assign('rankings'$rankings);
include 
XOOPS_ROOT_PATH.'/footer.php';
?>


in each file I want the Alphabetic order - I call the function ( files: index.php , viewcat.php , singlelink.php ) and in it's templates acordingly I call it:
<{$letters}>

(the template is full of hebrew hardcoded Chars - so I can't post it in full, but you need to add this wherever you want the alpabetic line to be) ...

Thsi hack is almost working good ... exept of what I mentioned above.
I wonder if somebody (from all those who asked me before about it) finds the fix for that
I am realy lost with it ... need fresh eyes on that one !!!!

2
Catzwolf
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/2/24 9:48

  • Catzwolf

  • Home away from home

  • Posts: 1392

  • Since: 2007/9/30


@Tzvook:

Some other people have pointed out similiar problems with WF-Downloads and I never been able to put my finger on it yet (due to the fact that it sometimes works abd sometimes doesn't)

If we find a solution to this issue we will let you know =)

Scott

3
Wheeler
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/2/25 4:46

  • Wheeler

  • Not too shy to talk

  • Posts: 145

  • Since: 2004/10/29


I only use the alphabet menu on the module index page. I think it mixes up when you are on 'Page 2, 3, 4, etc'. I have noticed the 'Sort by' menu mixes up too.

Example:
- Sort by 'A'
- shows first 5 listings
- click 'Page 2'
- listings show page 2 of default 'sort by' order

The letters and Sort By orders do not carry over to next page.

This is alternate code, mostly just for printing the alphabet menu in your template.
https://xoops.org/modules/newbb/viewtopic.php?topic_id=31259&forum=15&post_id=136504#forumpost136504


Please if anybody has a solution, please post it here too
https://xoops.org/modules/newbb/viewtopic.php?topic_id=31771&start=10
It is needed for the exciting myEdito module.

4
tzvook
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/2/25 7:59

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Hello Wheeler ... All

Like wheeler said - this Alphabetic hack is needed for almost each Module (as a hack for your choice for bigger sites) and especialy for a few modules like: myEdito/homepages , Xdirectory , mydownloads (a fixed one) and Mylinks.
but, yes, is most required for the promising myEdito module
I also hacked the Xdirectory for a phonebook (with Alphabetic panel (which works bad) and a searh, so if it'll be fixed I'll probably put it in xoops.org (if I'll have the Xdir auther permition).

The problem is not just that it shows b+c+d in the "a" page - but that it don't show the "b" in the "b" page

5
Wheeler
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/2/26 3:30

  • Wheeler

  • Not too shy to talk

  • Posts: 145

  • Since: 2004/10/29


Yeah, that sounds like a completely messed up function.

I did not explain enough above, I have not encountered as big of a problem as you. The example I show should have been with the Sort By feature not Alphabets. The reason I do not use alphabets on category pages is because the listings show from all categories, making it pointless to place the menu on a category. Where as the sort by does not carry over to page 2. Half a solution, you could increase the number of Items in Sort By listing.

I have only been messing around with the alphabets from the new release of WF-Downloads (great module!). Download the new WF-Downloads, open include/functions.php, search for: letters, the first result is the function.

Try to re-integrate this feature to you module. If this is fixed you will release it? cool

6
tzvook
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/3/3 15:17

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Hi Wheeler
10x, but it's not working better, as you see above the WFsection too knows about the problem...

A bit hard to belive that nobody found a solution for that, or implement another alphabetic sort panel...

7
Wheeler
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/3/8 2:27

  • Wheeler

  • Not too shy to talk

  • Posts: 145

  • Since: 2004/10/29


I think I have a solution. Let me try to gather my notes for changes, then I'll post it.

I have done alot of work on wf-downloads, which I am going to submit all my hacks and bugfixes to the wf-sections team.

Unlike... https://xoops.org/modules/news/article.php?storyid=2102 ... and no, I didn't get any code from the pd guys.

Be back in a bit.

8
Wheeler
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes
  • 2005/3/8 4:46

  • Wheeler

  • Not too shy to talk

  • Posts: 145

  • Since: 2004/10/29


Here it is, I hope it works for you.
Alphabetical Order Bugfix

9
tzvook
Alphabetic Order still nothing in the air
  • 2005/3/18 9:37

  • tzvook

  • Just can't stay away

  • Posts: 875

  • Since: 2003/2/1 2


Since it's not a fix for the alpha problem, I wonder if anybody saw an alphabetic sorting panel that actually works in Xoops, or knows how to find the first letter in MySql field ...

I need it badly, and no answere yet ..... though I read and read MySql & PHP manuals

10
wtravel
Re: Xdirectory Alphabetic Order Hack ... need fresh eyes

tzvook,

It should be possible to get all first letters of data in a column from the query results, but that would still require the query to get all results.

What I would do is create an extra column with the first letter of the category or title or whatever column you would like to use to filter on alphabet. Update the column with the first letters of the already existing data, and adjust the insert and update queries to fill this column based on the data entry.

Then you can adjust the query to only select records that match the letter in the "alphabetical" parameter in your url. This will not only speed up queries, it will also save calculation time.

Martijn

Login

Who's Online

468 user(s) are online (338 user(s) are browsing Support Forums)


Members: 0


Guests: 468


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: Nov 30
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits