subcategories are displayed in the same line as category. I want them to display under category when that category is viewed. Say I have few categories like News, Sports, Entertainment. Also few subcategories like Football, Basketball etc under Sports.

Right now It is displaying all categories, subcategories in the header in one line. I want football, basketball etc to display when sports category is viewed.

Any help is appreciated. Thanks

Comments

mercmobily’s picture

Hi,

This is one of the feature requests I knew would come.
Right now, Drigg does not support sub-categories. I would like it to, but there are quite a few features which are waiting to be developed as well.

Right now, I am concentrating on bugs -- which is obviously much more important.

So yes, it will get done. I just don't know when.

Merc.

bflora’s picture

Can I pay you to work on this now?

mercmobily’s picture

Hi,

I have a paid feature scheduled for Sunday (the "empty URL field" one).

How much are you able to pay?

Bye,

Merc.

bflora’s picture

Check your inbox for more information. Let's talk!

-b

beata57’s picture

Merc,

Are you working on this? If not im going to start looking into it.

Beata

mercmobily’s picture

Beata,

I will *love you* forever if you do!
I will give you some hints by email if you make contact!

Merc.

mercmobily’s picture

Hi,

Beata, did you get my email?
Do you think you can work on it?

Bye!

Merc.

totaldrupal’s picture

Any time frame on sub categories yet?

I'm thinking about doing a work around on this issue unless the sub categories feature will be done soon.

mercmobily’s picture

Hi,

I am on holiday right now.
beata57 ...?

Merc.

beata57’s picture

Sorry I haven't been around as of late real life stuff has been pilling up. I don't think I will have time to work on this in the near future.

Beata

mercmobily’s picture

Hi,

OK no problem, at least I know :-D

Merc.

drupalina’s picture

hi,

are there any plans to implement these subcategories in the future (post-23+) developments of Drigg?

mercmobily’s picture

Hi,

Plans, yes.
But, without hurry. This is a very big feature to implement. It's not easy, and it's very time consuming.
I think I know how to do it, but it's a few hours' worth of work.

Merc.

drupalina’s picture

yeah, I would imagine that it would take a while. Just checking if it was on the roadmap. Thanks.

mercmobily’s picture

Hi,

This is a writeup I created for somebody who offered to create a patch (but then chickened out :-D )
It's better that it stays here, rather than in an email:

Now... sub-categories.
First of all, have a look at how Drupal stores "categories" --
Categories in Drupal are what then become "sections" in Drigg.

Go to admin/content/taxonomy , pick the category which sets what the "sections" are in your site, and pick "List terms". Hit "Edit category", and tick "Single" in the "Hierarchy:" field. This will enable hierarchical categories, which is what you want.
At this point, for each term you will be able to define a "parent". The relationship is set through the term_relation table. I actually *don't* know how Drupal stores this relationship precisely. term_relation only has two fields, tid1 and tid2. I assume tid1 is the parent. You will basically need to find out (it should be easy, by adding data and "seeing" what happens :-D )

Once you know what happens to the data, and have created a nice nested structure, keep reading :-D

Let's dive into Drigg.
The module that deals with all this (printing of menus, etc.) is drigg_ui.

The function you need to change is:

function drigg_ui_sections($print_rss_links=FALSE)

This function will need to output ALL of the sections. Right now, it
outputs:

<ul>
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
</ul>

The output will need to change. I assume if "Category 2" is picked, the
sub-categories if Category 2 will need to come out:

<ul>
<li>Category 1</li>
<li>Category 2</li>

<ul>
<li>Sub Category 2-1</li>
<li>Sub Category 2-2</li>
<li>Sub Category 2-3</li>
</ul>

<li>Category 3</li>
<ul>

HOWEVER, I *assume* that it would be a lot easier to do something like
this instead:

<ul class="root">
<li>Category 1</li>
<li>Category 2</li>
<li>Category 3</li>
<ul>
<ul class="sub-1">
<li>Sub Category 2-1</li>
<li>Sub Category 2-2</li>
<li>Sub Category 2-3</li>
</ul>

This would be easier from several points of view - one of them being the HTTML rendering. However, I am not 100000% sure.

drigg_section_list() is a crucial function is, because it's the function that generates the data which will then be read by
theme_drigg_sections() (amongst other functions).

Changing what is stored by drigg_section_list() is actually crucially important, because it will affect you radically. The easiest way of
storing things is to just have $cache['lookup'][$tid][$parent] variable there. So you would have something like:

      $cache['lookup'][$tid]['name']=$name;
      $cache['lookup'][$tid]['safe_name']=$safe_name;
      $cache['lookup'][$tid]['description']=$description;
      $cache['lookup'][$tid]['weight']=$weight;
      $cache['lookup'][$tid]['tid']=$tid;
      $cache['lookup'][$tid]['parent_tid']=$term->tid1; ## NEW ONE ADDED

($tid1 represents the father) To have that $tid1, you will obviously need to change the query and add a left join to find out the father of each term. So, from here:

$result_t = db_query('select * from {term_data} where vid=%d ORDER BY
weight',variable_get('drigg_section_vid', -1));

To:

$result_t = db_query('SELECT * FROM {term_data} td LEFT JOIN
{term_relation} tr ON td.tid = tr.tid2 WHERE td.vid=%d ORDER BY tr.tid2,
weight',variable_get('drigg_section_vid', -1));

(Note: this is a wild guess!)

And then for the weights:

$cache['by_weight'][$parent_tid]=$tid;

I *think* the weights should still be respected, because if you notice the query above, I ordered by parent_tid and then weight. However, this needs to be tested.

The way you change the functions that use drigg_section_list depends on the way you change the data structure.

The most important one is drigg_ui_sections(). I think the best way to do it, is to rewrite it so that it has a parameter: the parent tid
(which if "0" means "root level"). That way, the code could be recoursive: theme_drigg_sections() would be called every time you find
an "active" category. For example from WITHIN drigg_ui_sections($tid=NULL):

      // Case #1: it's just /Category (other than /All). Check that the
      // category is correct, and that there's nothing after the category's
      // name
      if( $category != 'All' && drigg_is_section_valid(arg(0)) && arg(1)
== ''){
        if($category == arg(0)) {
          $selected = $selected_string; }
          $result .= theme_drigg_sections($tid);
          $link="/$category";
      }

If you have done recoursive programming before, you know what I'm talking about :D
If you haven't... maybe that's not the best bug for you!

Jesus, no wonder the poor guy chickened out...

Who's brave enough for this?

Merc.

dutsi’s picture

Priority: Normal » Critical

Merc,
Have you actually tried this or are you throwing it out there and what kind of solution are you looking for ?

mercmobily’s picture

Priority: Critical » Minor

Hi,

Please do not change the severity of bugs like that. Changed to "low".
No, mine above is a preliminary analysis. If you are able to get it done, or paying something to do it, please do.

Merc.
(In a bad mood)

dutsi’s picture

I hope I did not get you into the bad mood and a far as the changing of priority, that was a simple mistake and not on purpose.

mercmobily’s picture

Priority: Minor » Normal

Hi,

No worries, all good.

Merc.

Richard_’s picture

Category: support » feature

Hi everyone, I just found that drigg is short on subcategories.
Pitty isnt it?

Did anybody got it working?
I am willing to chip-in for this to be working.

Not much, 150 USD (with timeframe)
Is there anyone else willing to chip-in and contribute?

I need this ASAP :( I have tested anyhing to set-up the site with drupal and drigg, but not hierarchy, since I knew Drupal can handle this perfectly and now I found that this is not possible :(

Thank you!!!

mercmobily’s picture

Hi,

I very much doubt anybody will be able to do it for $150, since it's quite few hours' worth of work and testing.
However, I wrote a very detailed explanation above. If anybody with good PHP skills wants to hand in a working, tested patch, I am all ears...

Merc.

Richard_’s picture

:)

I know Merc. that is why I encourage others to join this request with chip-in. If there is at least 2 of us, maybe it will be good leverage against the time.

mercmobily’s picture

Hi,

If that's the case, I am _all_ ears!
In fact: anybody?

Merc.

coolclu3’s picture

Heard of Drupal long ago, and Drigg is the first touch, a few days ago :). Seems so cool
I was looking around for this subcategory thing with drigg, with no result.
Now I've just decided to fix this myself. Hope to come up with an answer soon...

mercmobily’s picture

Hi,

coolclu3, are you a PHP programmer?
Please have a look at my analysis above... is that enough information to get you going?

Please let me know!

Merc.

coolclu3’s picture

Hi Merc,
Yes, I've been doing PHP a few years now. Also came to the point that you explained. I'm going that way too. Right now, I'm a bit busy. I will get this "beast" this weekend. I hope you will give some support along the way.
Cheers,

mercmobily’s picture

Hi,

Thank you for your help!
I am going to Boston ovr the week-end. Meeting Stallman amongst other things.
I will do my best to support you, but I am not sure about my connectivity!

Bye,

Merc.

Richard_’s picture

coolclu3 if you succeed and Merc will include this into drigg core, I will be happy to donate my $150 to you .-)

mercmobily’s picture

Hi,

I will chip in with $50 if this gets implemented properly and tested.
I've got to be the only maintainer to pay bounties for his own modules :-D

I invite others to offer money as well. Every bit helps.

Bye,

Merc.

Richard_’s picture

wow, thumbs up

coolclu3’s picture

Wow, you guys are real cool. Let's wait&see this weekend....

mercmobily’s picture

Hi,

Keeping my fingers crossed...

Merc.

mercmobily’s picture

Hi,

I have just landed to Boston (and slept a good 7 hours). I travelled with my fingers crossed... please let me know about this one :-D

Merc.

coolclu3’s picture

Hi Merc,
Good to hear from you. I hope you had a good trip.

Subcategories, it's exactly like you said. In terms of data, it's under control now. (The term relationship is actually stored in the {term_hierarchy} table).

Now, drigg_ui_sections($parent_id) also works now. You were absolutely right

So the GUI depends on the theme. What you proposed with the nested ul list probably will make it look like digg.com, with enough CSS (Just guessing, I don't know much about this)

However, I am trying to do make it look like http://news.yahoo.com. That is I will have a div id "header-categories" which will output drigg_ui_sections(0), and another div id "head-subcategories" which is right below "header-categories", which will be something like drigg_ui_sections($parent_id), where $parent_id is the currently selected category (modified in page.tpl.php). I don't know how to get this $parent_id yet. I could easily make it as a SESSION var, but I guess drigg must have a way to get this already. Looking...

And I'm fixing another bug: if click on one scoop, my URL looks like this
http://localhost/drigg5/node/15
where 15 is the drigg node id (dnid)

I want to make it look like this
http://localhost/dirgg5/technology/programming/15
or even better
http://localhost/dirgg5/technology/programming/15/drigg-is-so-cool/
(drigg-is-so-cool is the title)
(I'm not even sure if it's missing feature or I don't know enough drigg/drupal)

OK, this "bug" is somehow, but not entirely, related to the subcategories things, because from the URL, afaik, we can get the current category/subcategory, using {arg} variable.

Just an update, Merc.
Please let me know what you think and what should be done to suit Drigg's need.

Cheers,

mercmobily’s picture

Hi,

OK, here I am :-D
Glad to be able to help here.
I will answer every single point.

--------------------------------------------------------------
Good to hear from you. I hope you had a good trip.
--------------------------------------------------------------

It's great. I am still a little jet-lagged. I was riding my bike through Boston, and found myself in the middle of the gay pride show yesterday!

--------------------------------------------------------------
Subcategories, it's exactly like you said. In terms of data, it's under control now. (The term relationship is actually stored in the {term_hierarchy} table).
--------------------------------------------------------------

Alright, glad to hear this!

--------------------------------------------------------------
Now, drigg_ui_sections($parent_id) also works now. You were absolutely right
--------------------------------------------------------------
OK!

--------------------------------------------------------------
So the GUI depends on the theme. What you proposed with the nested ul list probably will make it look like digg.com, with enough CSS (Just guessing, I don't know much about this)
--------------------------------------------------------------

OK.

--------------------------------------------------------------
However, I am trying to do make it look like http://news.yahoo.com. That is I will have a div id "header-categories" which will output drigg_ui_sections(0), and another div id "head-subcategories" which is right below "header-categories", which will be something like drigg_ui_sections($parent_id), where $parent_id is the currently selected category (modified in page.tpl.php). I don't know how to get this $parent_id yet. I could easily make it as a SESSION var, but I guess drigg must have a way to get this already. Looking...
--------------------------------------------------------------

You are right, my original idea was quite silly.
But using the SESSION would be a _REALLY_ bad idea. Consider that you have the parent id right there, in the URL. So, you can just do a lookup on arg(0) and there you are. This way, the drigg_ui_sections() function doesn't need to know the parent_id, but simply what level you are dealing with. For example, if you do drigg_ui_sections(0), it will print the "root" categories. drigg_ui_sections(1) will print the level 1 subcategories, taking arg(0) as the parent one.
This is the best way to go about it.

--------------------------------------------------------------
And I'm fixing another bug: if click on one scoop, my URL looks like this
http://localhost/drigg5/node/15
where 15 is the drigg node id (dnid)

I want to make it look like this
http://localhost/dirgg5/technology/programming/15
or even better
http://localhost/dirgg5/technology/programming/15/drigg-is-so-cool/
(drigg-is-so-cool is the title)
(I'm not even sure if it's missing feature or I don't know enough drigg/drupal)
--------------------------------------------------------------

Watch out! Please make absolute sure you don't confuse the URLs handled by drigg_ui and the ones handled by Drupal directly.

Every node in Drupal is _always_ node/XXXX. In Drigg, the "trick" I use is this: pretty much every drigg site defines a custom_url_rewrite function in settings.php. At the beginning of custom_url_rewrite(), I have:

$term_list=variable_get("drigg_section_list",array());

This is because when custom_url_rewrite() is run, Drupal hasn't quite finished booting up yet, and you cannot access some important functions. This is _precisely_ why Drigg stores 'drigg_section_list' as a Drupal variable.

Look at custom_url_rewrite_function.php and you will see exactly what I do. The important bit is here:


  // Change the INCOMING links, so that people can view
    // Community/Embedded_Linux_pioneer_offers_webinar/ or even
    // /Community/Embedded_Linux_pioneer_offers_webinar/edit
    //
    if(preg_match('%^(.*?)/([^/]+)(.*)$%', $path, $matches)){
      $cat = $matches[1];
      $title_url = $matches[2];
      $rest = $matches[3];
      if( isset($term_list['by_safe_name'][$cat]) || $cat== 'All'){
        $res=drigg_settings_lookup_drigg_node_by_title_url($matches[2]);

This makes sure that any URL that starts with a category will work and that the right node will get looked up.

I guess the short answer is: just make sure the custom_url_rewrite() function is set in your Drigg installation. The function will probably need some adjustments since the data structure has changed a little. I suspect for some reason this is no longer working for you: "isset($term_list['by_safe_name'][$cat])" -- but it should! However, once the if() statement above is fixed, the paths as far as NODES are concerned will work.

--------------------------------------------------------------------------------
OK, this "bug" is somehow, but not entirely, related to the subcategories things, because from the URL, afaik, we can get the current category/subcategory, using {arg} variable.
--------------------------------------------------------------------------------

See my answer above. As I said, please make sure you don't confuse the NODES' path with the drigg_ui paths. Also, and this is IMPORTANT, it's best to keep paths to 1 level, even though they are logically nested (this is also what Digg does, and for good reasons). So for example, if you have:

Community (tid 3)
|- One (tid 4)
|- Two (tid 5)

Development (tid 6)
|- Three (tid 7)
|- Four (tid 8)

Then the path is always One/Title_of_the_node, rather than Community/One/Title_of_the_node

Another thought is that I think we will need to change drigg_ui so that the filtering system works with this new category hierarchy. So, if you pick "Development", you should see all stories belonging to Development, Three AND Four.
So, this bit will need to be mended in drigg_ui.php (drigg_ui_node_list):

  // This bit is true for every single case... so, here it is 
  // Populate the tid bit
  if($tid){
    $extra_join .= ' LEFT JOIN {term_node} t ON n.nid = t.nid ';
    $where_conditions.=" t.tid=%d AND ";
    $query_vars[]=$tid;
  }

This will need to become something like:

  // This bit is true for every single case... so, here it is 
  // Populate the tid bit
  if($tid){

    // NOTE: this function, which is NOT written yet, will have to return a
    // list of TIDs and SUB-tids for that particular category. So, if you
    // take the TIDs from the example categories above, if you pass it
    // "3" (Community), it should return  "(3, 4, 5)"  -- that is, the tids for 
    // "Community", "One" and "Two"  
    $tid_list=drigg_ui_get_all_tids($tid);

    $extra_join .= ' LEFT JOIN {term_node} t ON n.nid = t.nid ';
    $where_conditions.=" t.tid IN ($tid_list) AND ";
    $query_vars[]=$tid;
  }

Does all this make sense to you?
As you can see, you are making quite deep changes to Drigg. All this will also need extensive testing, to make sure we didn't break anything else (which is very possible).

-----------------------------------------------------
Just an update, Merc.
Please let me know what you think and what should be done to suit Drigg's need.
Cheers,
-------------------------------------------------------

I hope my post helped...

Merc.

coolclu3’s picture

Hi Merc,

Thanks for the quick reply :) I'll go straight to the point.

1. The subcategory
Before your post, I already I wrote a new function called drigg_ancestor_section_id($level, $tid) which return the $tid of the category $level down from root

For example if we have Java->OO->Programming->Technology->root, and tid of Java is 5
Then drigg_ancestor_section_id(1, 5) returns "Technology" tid, drigg_ancestor_section_id(2, 5) returns "Programming" tid, and so on...

And in page.tpl.php, under div "header-categories", I added:

       if (drigg_is_section_valid(arg(0)) )
       {
            $tid = drigg_section_id_by_safe_name(arg(0));
            $subcate_tid = drigg_ancestor_section_id(1, $tid);
            print drigg_ui_sections(FALSE, $subcate_tid); 
       }

I might have complex multilevel categories later, not just 2, so I needed drigg_ancestor_section_id()

2. Showing also nodes which are in the subcategories list, when selecting a category.
it's now FIXED& TESTED :)
drigg_ui_get_all_children_tids() was created

3. custom_rewrite_url()

Thanks for your hint. I was wondering where I should fix, drupal's node_menu() or drigg_ui_menu(), lol. Almost modified the code :P

Anyway, is it possible to enable custom_rewrite_url() after installation?

Cheers & hope you will enjoy the rest of the weekend

mercmobily’s picture

Hi,

This would be the most amazing patch I have ever received. You seem to be doing things right.
I don't think I can possibly thank you enough. I wish more people had chipped in more.

About your only question:

"Anyway, is it possible to enable custom_rewrite_url() after installation?"

I am afraid this really needs to be done manually by the person installing it -- that is, pasting the provided code in the user's site. Please have a look at the install procedure in http://ww.drigg-code.org.

AND...

THANK
YOU.

I hope you won't abandon Drigg after this, and will keep on helping if time allows.

Finally... please test the HELL out of this. It's really crucial... it's such a deep change!

Merc.

Thanks!

Merc.

coolclu3’s picture

Hi Merc,

It's my pleasure, I'm glad we kinda got it solved. The communication channel was real smooth :)

I will send you the patch once it's tested thoroughly. The earliest time would be next weekend, when I have the time to make the patch properly( I've modified few other things as well).

I need to check out the custom_rewrite_url() first.

OK, I gotta go now. See you around :)

Cheers,

Richard_’s picture

These are exiting news :)
Thank you!!!

bflora’s picture

AWESOME.

So what's the timeframe on getting this committed or ready to patch onto a Drigg install?

Richard_’s picture

Hi coolclu3, can we help with testing?

Thank you!!!

coolclu3’s picture

Thanks for the offer for help Richard_.

I've been away for a FOSS conference and forgetting/not having time to update this.
I will post the patch ASAP.

d0t101101’s picture

Awesome, I am really looking forward to this too.

Subscribing....

mercmobily’s picture

Hi,

I'd love this patch toooo!!!
Sicjoy: now, THIS is something that needs to be tested by 5 users at least, BEFORE committing it. This is a very dangerous patch... It touches the heart of Drigg.

I will want to review the codee personally carefully as well.

Merc.

Richard_’s picture

I would be happy to test it, but I am available until friday only, then I go off for 12 days :(

coolclu3’s picture

Hi Merc,
I'm trying to make the patch and there's only ONE problem left. Can you give me some pointer please?

When I'm trying to access the page (in teaser mode )
http://localhost/drigg/Technology/My-first-scoop
then in page.tpl.php, arg(0) is not "Technology", in stead it is "node". (I guess it was processing the http://localhost/drigg/node/5 url, in stead of the alias)
This makes all the subcategory stuff just work with the home page

If you have sometime, can you please tell me how to get "Technology" ?

Another aside question, I see the variable $head_title, but I couldn't find it in the whole drupal source code. How is this generated? Is it some sort of $A_B of Drupal that I don't know yet?

OK, Thank you & bye for now
Cheers

mercmobily’s picture

Hi,

OK, I am not entirely sure I am getting your question.
Why do you want to access the node's category from the node's template? Shouldn't your patch be completely independent of the theme?

Anyway, you can do this:

print drigg_section_name_by_safe_name($node->safe_section);

Also, head_title is defined in the phptemplate.engine file, line 202:

'head_title' => implode(' | ', $head_title),

Bye!

Merc.

coolclu3’s picture

Thank you Merc. That $node->safe_section is just what I needed :)
Now, this bug is FIXED. I've thoroughly tested it in my localhost. I will upload the patch and a setup my demo site for verification from someone. I will post it here within this week :)
Cheers guys

mercmobily’s picture

Hi,

What can I say...

I LOVE YOU
---------------

!!!

Merc.

mercmobily’s picture

Hi,

You still with us?

Merc.

coolclu3’s picture

Hi Merc,
Certainly, I'm still here, just a little busy. Sorry I couldn't deliver the patch on time as said before.
Please check out this site: http://matsang.com

If anyone want to have the admin access to this site, please PM me, I will give you admin access to this site to play around with it. I really hope I do receive PMs and comments on this implementation of the page.

I will upload the patch as soon as Merc says it's ok.
Cheers

mercmobily’s picture

Hi,

Before anything else, can you please tell me what will change to the current way of adding the category list to the template?

And yes, please send me the admin login/pass :-D

Merc.

coolclu3’s picture

Hi Merc,
I will send the patch for 2 things
1. Theme (page.tpl.php + css)
2. Drigg Code

Basically, with 1. Theme, I changed in the css the menu-header to double height, and a gray color as the background, so "subcategories" can be displayed.
And in page.tpl.php, inside div "head-categories" I have

          //print Categories, which is the children of root '0'
          print drigg_ui_sections(FALSE, 0); 

         //Newly added: print Subcategories
 	  if (drigg_is_section_valid(arg(0)) )
	  {
	 	$tid = drigg_section_id_by_safe_name(arg(0));
          	$tmp = drigg_ancestor_section_id(1, $tid);
    	 		print drigg_ui_sections(FALSE, $tmp); 
          }
	   else if (drigg_is_section_valid($node->safe_section))
	   {
	 	$tid = drigg_section_id_by_safe_name($node->safe_section);
          	$tmp = drigg_ancestor_section_id(1, $tid);
    		print drigg_ui_sections(FALSE, $tmp); 
	   }
     

The reason I have to have an {if,else} is that the if() (using arg(0) ) is used for URLs like
http://matsang.com/world-and-business or home page
and the else() (using $node->safe_section) is used for a real scoop node:
http://matsang.com/Embedded-Systems/Moblin_is_the_Moblized_network

2. The drigg code change is basically what we have been discussing throughout this thread. I have to run now. I will get back to this later.

Cheers

mercmobily’s picture

Hi,

Nice one!
Two things:

1)
There is way too much logic in the template. The rule is that there must be basically no logic there.
Can you please move that if() into a specific function in drigg_ui()? It's crucial that that function won't display anything if there are no sub-categories.

2)
The CSS... Cn you please make absolute sure that a site that doesn't use sub-categories looks 100% fine? (that is, it doesn't show a thick category bar)
If you don't know how to do it, I will get that fixed with Alan

Also, I had a ook at the test site (NICE ONE!) and I have another couple of requests...

3)
If there ARE sub-categories, and if none of them are selected, can you please create an artificial, selected "All" category in the list of sub-categories? Basically, when I click on "Technology and science", the list of sub categories should come up, and "All" should be selected

I think that's it. Oh, actually, there's more: I don't think I'll ever thank you enough for this work. It was a nasty task.

Merc.

mercmobily’s picture

Hi,

Just to clarify, I think the theme should read:

  //  print Categories, which is the children of root '0'
  print drigg_ui_sections(FALSE, 0); 
  print drigg_ui_sections(FALSE, drigg_ui_ancestor_section_id(1)    );

Two additional queries:

1) Do you really need " else if (drigg_is_section_valid($node->safe_section)) " ...? If you look at drigg_ui.module, line 589, you will see that it already checks if you're looking at a drigg node:

  // Case #3: it's viewing an article. In this case,
      // get the article's category
      if( arg(0) == 'node' && arg(1) != '' && is_numeric(arg(1))){
        $n=node_load(arg(1));

2) Finally... will this work for sub-sub categories as well?

Sorry to be a pain!!! This is such a fantastic patch, I really want to make sure we get this 10000% right. I say "we", but it's really all your work.

Merc.

coolclu3’s picture

Hi Merc,
So it turns out to a little different from what I had :)
I'll address every single point of yours :)

1. Move code inside Drigg code and leave the theme clean.
I have done that, with a few more changes like drigg_ui_sections() will return NULL if it should,
and now the theme looks like this, with subcategories

        <!-- Categories -->
        <div id="header_categories">
          <?php
            if (module_exists('drigg')) {
              print drigg_ui_submit_button();
            }
          ?>
          <?php 
          print drigg_ui_sections(FALSE, 0); 
          ?>
        </div>

        <!-- subcategories -->
        <?php 
             $subcates = drigg_ui_sections(FALSE, drigg_ui_ancestor_section_id(1));
        ?>
        <?php if ($subcates) {	?>
               <div id="header_subcategories">
               <?php print $subcates; ?>
               </div>
         <?php } ?>
	<!-- Sub-subcategories -->

2. The CSS
I have created a new div "header_subcategories" in base.css, so with the above code, it will look clean if there is no subcategories
If sub-subcategories is needed, the same div can be generated.
I have made my "header_subcategories" gray background, and "header_subcategories2" green background in the demo site (See under Technology-and-Science)

3. Sub-sub categories it works as well.

4. Fake 'All' in subcategories:
This is the code:

      // CASE "DEFAULT"
      // This is the default, in case another page is being seen
      if($category == 'All'){ 
        if ($parent_tid == 0)
           $link=drigg_ui_home_url();
       else 
           $link = "FIX-ME"; 
      } else { 
        $link="$category"; 
      }

As you can see, I don't know how to get the $link properly, if it's not the *home* 'All' . It should be something like
$link = generate_link_for_category_id($parent_tid)

5.node->$safe_section thingie
I need this for the function drigg_ui_ancestor_section_id($ancestor_depth) which is something like this

function drigg_ui_ancestor_section_id($ancestor_depth = 1){
  //get current section id
  if (drigg_is_section_valid(arg(0)) )
  { 
      $tid = drigg_section_id_by_safe_name(arg(0));
  }
  else if ( drigg_is_section_valid($node->safe_section))
  {
    	$tid = drigg_section_id_by_safe_name($node->safe_section);
  }
  // now get the ancestor id
  //........

Now, if there is a way to get the current section id, then it will be a lot simpler.
As you can also see, now that I've moved it into drigg_ui.module, the drigg_section_id_by_safe_name($node->safe_section) won't work any more, that's why, now viewing a scoop, the sub category menu is not displayed properly.

If you can please tell how to get the current section id inside drigg_ui.module, and address question mentioned in 4., I guess pretty much we are done :)

Otherwise, I will have to dig into this later to have this properly implemented...

6. A "feature"
Currently, if CMS is selected for example, then it's highlighted, but "Technology-and-Science" is not kinda selected....I'm not sure if this should be fixed....
Ok, it's rather long, I hope we're still following each other correctly :).

Cheers,

coolclu3’s picture

Uhm...somehow the scoops under Drupal (->CMS->Technology) doesn't get listed when selecting Technology-and-Science on the demo site
It works fine in my localhost though.....Weird...

mercmobily’s picture

Hi,

First of all, I want to make sure you realise that I am not being a pain for the sake of it... I feel a bit bad, asking you to improve your patch and generally bossing you around :-( However, this is such an important change that we need to be absolutely sure it's done perfectly...

Having said that:

1) Fantastic,

2) Perfect

3) Can you give me a code snipset of what it'd look like if there were 3 levels of subcategories? Can you please set them up on the test site? I am curious for example about what would happen if you select Level 1 -> Level 2 -> Level 3. Would Level 2's correct list come out?

4) Ugh, I wish I was smarter than I am, so that I would give you the right answer on the spot... I have to be honest, I am not 100000% sure I get how things are done. OK, I understand it 95%, but remember I have never seen the actual code!
That "All" should come out if the parent category of the menu *IS* the currently displayed category. So, the algorithm should be:

* Get the tid of the current category (from the URL)
* Get the tid of the menu being displayed.
* Run a query, and get the parent id of that menu
* If the parent of that menu IS the same as the currently displayed category, then HIGHLIGHT All
* The link simply $link_cat=$terms['lookup'][$PARENT_TID]['safe_name']; $link=$link_cat;

Does it make sense?

5) I am *very* confused. This confuses me:

function drigg_ui_ancestor_section_id($ancestor_depth = 1){

Especially because it refers to "node", but... there's a problem: the $node variable is empty there!
To get it, the "trick" i used elsewhere in drigg_ui.module is this:

  // Case #3: it's viewing an article. In this case,
      // get the article's category
      if( arg(0) == 'node' && arg(1) != '' && is_numeric(arg(1))){
        $n=node_load(arg(1));

There you have it: it works out if it's a node, and if it is, it gets the category. I *think* this answers your question!

6) Yes, this should be fixes. If you select technology->CMS, then both technology and CMS should be highlight. How do you do that? (crunching crunching) Any solution I can think of won't really work if pushed more than 2 levels.
OK, let me think. If "Joomla" is selected, then both Technology and CMS need to be highlighted. All the function knows, is this:

* It's displaying the section "joomla"
* It's displaying a menu which could be any one of them

The only possible thing I can think of is this. When displaying the menu, work out the $tid of the currently displayed section (Joomla). Then, create an array of parents - let's say maximum 3. So, the array would have [$tid_of_CMS,$tid_of_Technology].

Now, this means that in drigg_ui.module, in the drigg_ui_sections() function, rather than having the simple:

 if($category == arg(0)) {
    $selected = $selected_string;
 } 

It needs to be something like:

 if(in_array($category_tid,  $array_of_parents_tids) {
    $selected = $selected_string;
 } 

Basically, you need to make this change every time the variable $selected is mentioned in that function. Luckily, it only happens 3 times...

My goodness, this function is going to become a real monster, by the time we are done with it. The next stage will be to document the hell out of it, to make sure that we don't get lost in the code.

#57 )
About your latest post... that's the query world. I am going to leave it up to you :-D

*** THANK YOU ***

!!!

Merc.

coolclu3’s picture

Hi Merc,

First of all, I want to make sure you realise that I am not being a pain for the sake of it.

No, not at all. I'd myself love to contribute something to this module too. I'm a fan of OpenSource software, so you know what i mean...it doesn't take too much of my time anyway. Don't feel bad :)

Anyway, I've fixed the things, check this out
1. Subcategories and selected menus
http://matsang.com/Drupal :)

It should work for many more levels, but I haven't tested yet.
2. Fake 'All'
I don't think we should have this, as the parent menu is always highlighted, so it's not necessary is it

3. Comment number #57. Still present in the version deployed at the sever although, again, it works in my localhost perfectly well....
4. Now the code looks simple. I will explain & doc this tomorrow...
Cheers,

mercmobily’s picture

Hi,

* THANKS * !

OK. This is a _very_ important feature. Now... there is some news. Drigg is about to get ported to Druapl 6.
That's right!

Now, this is important. And from Monday, it will enter Code Freeze. I would _love_ to see this feature committed before the porting starts.

So... can I ask you to please test this as much as you possibly can? Especially, what happens if an existing site, with existing categories, upgrades?

If you give you your OK, I will just cross my fingers, commit the code, and ask as many people as possible to test it. There is no need to release a new version soon, luckily. So, this might be a good path to follow.

Please let me know!

And... please let me know if you're willing to help Drigg;s development once you've finished this patch :-D

BYE!

Merc.

ajayg’s picture

If you think this need to be commited before porting, If I were you, I would give atleast a few weeks between commiting this and code freeze so issues can be ironed out. Also I would create a new release to get it out and get tested.
If your idea is 5.x release version do not get subcategories but 6.x does, then what is the point of rushing in then code freeze? You might as well have code freeze now (because we know 5.x is stable so far) and add this only in 6.x. Basically I am not clear the benefit of rushing this in last minute without testing as it will create more headache for supporting it. Either do it properly or just add this in 6.x.

mercmobily’s picture

Hi,

Hummm what do you think coolclu3?

I think Drupal 5 will be with us for a while. So, it's either:

* We apply it now. Even if it doesn't work 1000000%, the important thing is that everything still works with SINGLE categories. We code freeze, the D6 version of Drigg is completed, and then we iron out problems with multiple categories if there are any

* We apply it later, both to the D5 and to the D6 branches.

It's a pain either way, really.

coolclu3, can you post the patch here so that I can at least review it?

Bye,

Merc.

coolclu3’s picture

OK,
I've tested with 4 level down. Pls check this out guys
http://matsang.com/Drigg/Drigg_is_Drupal_Digg

So, here is the code and the logic behind it. I will have a proper .diff file when I've
removed some of other things I've modified with my local copies later on.

FEATURE REQUIREMENT
1. Subcategories (as many level down as available) should be displayed and the appropriate
ancestor section must be highlighted in the top menu.
2. When choosing a section, all the scoops which are *offspring*, NOT just children of that
section must be displayed.

IMPLEMENTATION
1. helpers.inc.php: function drigg_section_list()

This function will return the list of all sections (terms) available, together with some
associated data. Previously, the data doesn't contain info on the term hierarchy. To have
this info available, we get the hierarchy info from 'term_hierarchy' table, and change the
query in drigg_section_list()
from

<?php
    $result_t = db_query('select * from {term_data} 
            WHERE vid=%d 
            ORDER BY weight',
            variable_get('drigg_section_vid', -1));
?>

to

<?php
    $result_t = db_query('SELECT * FROM {term_data} td 
            LEFT JOIN {term_hierarchy} th ON td.tid = th.tid 
            WHERE td.vid=%d 
            ORDER BY th.tid, weight',variable_get('drigg_section_vid', -1));
?>

Then, add the hierarchy info to the returned data of drigg_section_list()

<?php
      $parent_tid =  $term->parent;
      $cache['lookup'][$tid]['parent_tid']=$parent_tid; ## NEWLY ADDED for section hierarchy
?>

Now drigg_section_list() returns an array of terms with hierarchy info.

2. drigg_ui.module : The top menu
This module will use data from drigg_section_list() to build a proper top menu. The heart of
this is the function drigg_ui_sections(). For this patch, it NOW takes 2 params, in stead of 1

<?php
/** .....
 * @param $depth
 *   Only choose the sections that are '$depth' level deep
 *   counting from root, which has term_id of 0.
 *   For example, if we have
 *   root -> technology -> CMS -> Drupal -> Drigg
 *                             -> Joomla
 *        -> sports
 *   Then drigg_ui_sections(,0) will return the menu including 'technology' + 'sports'
 *   drigg_ui_sections(,1) will return 'CMS' if we are viewing content of 'Drupal', 'Joomla' or 'Drigg'
 *   and so on....
* @return
 *   The menu if there is a menu to display
 *   NULL if there is no sections available.
 */
function drigg_ui_sections($print_rss_links=FALSE, $depth = 0)
{

  $nr_of_sections = 0; //number of sections available.
  $output='';
 
  //section_id (term_id) array of all the ancestors of current 'term'
  //being viewed.
  $ancestor_arr = drigg_ui_ancestor_section_id_array();

  //Now find the parent term_id of the sections we are generating.

  if ($depth == 0)
      $parent_tid = 0;
  else
  {
     $idx = count($ancestor_arr) - $depth - 1;
     if ($idx >= 0)
         $parent_tid = $ancestor_arr[$idx];
     else 
         return null; //No sections available with this '$depth'
  }
         
  $terms=drigg_section_list();

  // You never know...
  if(count($terms)==0){
      return null;
  }

  // HTML class for selected items
  $selected_string=' class="active" ';
  $class_string=' class="drigg-categories" ';

  // This will make the following code prettier
  $p0=arg(0);
  $p1=arg(1);
  $p2=arg(2);


  // Little hack to have the "All" menu
  // This way, the database doesn't need to get dirty with
  // crap and it all "works"
  $terms['lookup'][ $parent_tid ]['name']=t('All');
  $terms['lookup'][ $parent_tid ]['safe_name']='All';
  $terms['lookup'][ $parent_tid ]['description']=t('All categories');
  $terms['lookup'][ $parent_tid ]['weight']=-100;
  $terms['lookup'][ $parent_tid ]['tid']=$tid;
  array_unshift($terms['by_weight'],0);
  $terms['by_safe_name']['All']=0;
  

  if($terms){
    foreach( $terms['by_weight'] as $tid ){
      //only checks for terms that are children of $parent_tid
      if ($terms['lookup'][$tid]['parent_tid'] != $parent_tid ) 
      {
          continue;
      }
      $category=$terms['lookup'][$tid]['safe_name'];
      $selected='';

      //if $tid is an ancestor of current term being viewed.
      // then it should be highlighted (i.e. 'selected')
      if ($ancestor_arr && in_array($tid, $ancestor_arr) && $tid != 0)
          $selected = $selected_string;
      
      
      // CASE "DEFAULT"
      // This is the default, in case another page is being seen
      if($category == 'All'){ 
          if ($parent_tid == 0) // Only have 'All' for the top categories, NOT subcategories
               $link=drigg_ui_home_url();
      } else { 
          $link="$category"; 
      }

      // Omitted code
      // Case #1: it's just /Category (other than /All). Check that the 
      // Case #2: it's just 'node' or 'drigg_home'. In this case,
      // Case #3: it's viewing an article. In this case,
      // Case #4: it's viewing a list. This is the most complex case.
      // Work out the links for the RSS feed for that category - if
      // present!
      //......
      // Finally shows the output 
      $output.='<li><a '.$selected.' href="'.url($link).'" title="'.t($terms['lookup'][$tid]['description']).'"><span>'.t($terms['lookup'][$tid]['name']).'</span></a>'.$rss_links .'</li>';

      $nr_of_sections ++;
   }
  }
 

  //return data only if there is some sections available
  if ($nr_of_sections >= 1)
  {
      return "<ul ".$class_string." >$output</ul>";
  }
  else 
      return null;
}
?>

Now the 'utility' functions

<?php
/**
 * Get all the ancestors of the currently viewed term
 * in an array, including the root '0' . 
 * If we have root (tid 0) -> Technology (tid 3)-> Programming (tid 7) -> OO (tid 11) -> PHP (tid 13) 
 * Then for example, we are viewing content under 'OO', the returned array will be
 *   ret[0] = 11; //OO
 *   ret[1] = 7; // Programming
 *   ret[2] = 3; //Technology
 *   ret[3] = 0; //root
 * 
 * @return 
 * Array of the section ids of ancestors if there are any
 * Null if there is no ancestor.
 */
function drigg_ui_ancestor_section_id_array(){

  $tid = get_term_id();
  if ( $tid == -1)
      return NULL; //we are not viewing any content under any term. E.g viewing homepage
    
  $terms=drigg_section_list();
  $i = 0;
  $tmp = array();
  $tmp[0] = $term_id = $tid;
  while ($terms['lookup'][$term_id]['parent_tid'] != 0)
  {
        $i ++;
        $term_id = $terms['lookup'][$term_id]['parent_tid'] ;
        $tmp[$i] = $term_id;
  }
  $tmp[$i + 1] = 0; //add root
  return $tmp;
  
}


/**
 * Get the current Term Id if there is one. 
 * Otherwise, return -1 
 * @return id of current term, or -1
 */
function get_term_id()
{
  $tid = -1;
  if (drigg_is_section_valid(arg(0)) && arg(1) == '' )
  { 
      $tid = drigg_section_id_by_safe_name(arg(0));
  }
  if( arg(0) == 'node' && arg(1) != '' && is_numeric(arg(1)))
  {
        $node=node_load(arg(1));
        if ( drigg_is_section_valid($node->safe_section))
        {
             $tid = drigg_section_id_by_safe_name($node->safe_section);
        }
  }
  if(arg(0) == 'published' || arg(0) == 'upcoming' || arg(0) == 'archived'){
        if ( drigg_is_section_valid(arg(2)) )
          {
              $tid = drigg_section_id_by_safe_name(arg(2));
          }
  }
  return $tid;
}
?>

3. drigg_ui.module : Viewing all offspring scoops under a certain section

When selecting a certain section, now that we have section hierarchy, we should display all
the scoops which are offspring of the selected section. To do that, we first need a list of
all the offspring section id of current term, called drigg_ui_get_all_offspring_tids($tid),
and a helper function drigg_ui_get_all_children_tids($tid) to accomplish that

<?php
/**
 * Return the list of all term_ids which are direct children of term $tid 
 *
 * @param $tid
 *   The term_id of the term.
 * @return: Array. order doesn't matter
*/

function drigg_ui_get_all_children_tids($tid)
{
  $ret = array();
  $result_t = db_query('SELECT * FROM {term_hierarchy}
                 WHERE parent=%d',
                 $tid);
  $i = 0;
  while ($term = db_fetch_object($result_t))
  {
      $ret[$i] = $term->tid;
      $i ++;
  }
  return $ret;
}


/**
 * Return the list of all term_ids which are offspring of term $tid 
 *
 * @param $tid
 *   The term_id of the term.
 * @return: Array. order doesn't matter
*/
function drigg_ui_get_all_offspring_tids($tid)
{
    $ret = drigg_ui_get_all_children_tids($tid);
    if ($ret)
        for ($i = 0; $i < count($ret);  $i ++ ){
            $tmp = drigg_ui_get_all_offspring_tids($ret[$i]);
            if ($tmp)
                $ret = array_merge($ret, $tmp);
        }
    return $ret;
}
?>

Now, in function drigg_ui_node_list(), the sql has to change from

<?php
    $extra_join .= ' LEFT JOIN {term_node} t ON n.nid = t.nid ';
    $where_conditions.=" t.tid=%d AND ";
    $query_vars[]=$tid;
?>

to

<?php
    $tid_list=listize_from_array(drigg_ui_get_all_offspring_tids($tid)); //string
    //now $tid_list = "12,13,14,16, ";
    $tid_list .= $tid;
    $extra_join .= ' LEFT JOIN {term_node} t ON n.nid = t.nid ';
    $where_conditions.=" t.tid IN ($tid_list) AND ";
    $query_vars[]=$tid;
?>

and the function listize_from_array looks like this

<?php
/**
 * Return a string representation of an array [1,2,4] 
 * of the form  "1, 2, 4, "
 *
 * @param array $arr
 */
function listize_from_array ($arr)
{
  $ret = "";  
  for( $i = 0; $i < count($arr);  $i ++) 
  {
    $ret .= $arr[$i];
    $ret .= ",";
  }
  return $ret;
}
?>

4. The theme: page.tpl.php
To print top-level categories, use

          <?php 
             print drigg_ui_sections(FALSE,0); 
         ?>

To print sub categories, use

        <?php 
             $subcates = drigg_ui_sections(FALSE,1);
        ?>
        <?php if ($subcates) {    ?>    
             <div id="header_subcategories">
                 <?php print $subcates; ?>
             </div>
         <?php } ?>

And similarly for sub-subcategories or any level down....

OK, I guess it'll do for now. Again, pls check out the site
http://matsang.com for testing...

Cheers & Bye for now

coolclu3’s picture

Hi Merc,
About your comment #62
If *it were me*, I'd go with patching it to Drigg 5 first, then porting to Drupal 6, if porting to Drupal 6 can be delayed . The time for this patch to be reviewed and tested, I would say, is another 2 weeks.

Otherwise, if someone's waiting to port Drigg 6 already on Monday, then like you said, Drigg can have another branch for porting and applying the patch later to both Drigg 5&6 is fine too. It's not really a pain I guess. The patch is not too complex so that should be OK.

Cheers

mercmobily’s picture

Hi,

cool: I look forward to the diff. It looks like you did things right, although a diff will help me more :-D

I will delay the roll-out of this patch, since work for D6 is about to start. But it's here, and it's:

** FANTASTIC **.

The best contribution I have _ever_ received.

In fact, for my peace of mind, please please please sendm e a diff as soon as possible so that I know :-D

Thanks,

Merc.

coolclu3’s picture

StatusFileSize
new12.51 KB
new137.47 KB

Hi Merc
Good news, comment #57 is now obsolete. The test site is now "fully" functional

The .diff for drigg-5.x-1.34 is in file drigg-5.x-1.34-bug207084.diff
And the patched package, I named it drigg-5.x-1.35.tar.gz

Note that version deployed on http://matsang.com is drigg-5.x-1.32, so this hasn't been tested. If someone is kind enough to take this package here drigg-5.x-1.35.tar.gz and follow intructions on http://www.drigg-code.org/pages/download_and_install to install & test, it would be lovely. I'll do it myself sometime towards the end of the week if I'm available then...

OK, cheers guys.

Richard_’s picture

Am I save to update my (DEV) site with this 1.35 version? Are there any db changes?

Thank you for this fix!!!

mercmobily’s picture

Hi,

No DB changes. Some testing would me _immensely_ appreciated!

Merc.

Richard_’s picture

Ok, I have upgraded from 1.34 to attached 1.35 from #66.

I have this error after clicking on category:
Fatal error: Call to undefined function listize_from_array() in /home/www/dddddd/modules/drigg/drigg_ui/drigg_ui.module on line 336

Along with upgrade I have followed last step from instruction in #66. and replaced that stuff in page.tpl.php

I have also created new 2nd level category and when I click on the node, correct category is highlighted (1st and 2nd level too). I just cant click top level category itself, because I am getting the fatal error (above).

coolclu3’s picture

StatusFileSize
new167.12 KB

Richard, Thanks for trying it out
I haven't even got 30 mins to try to setup this package in my localhost. I feel ashamed about posting it here having not tested it with this version yet.

Can you add this block of code into your file /home/www/dddddd/modules/drigg/drigg_ui/drigg_ui.module (end of file is ok). There is no need to reinstall the whole thing, just updating this file is enough.

<?php
/**
* Return a string representation of an array [1,2,4]
* of the form  "1, 2, 4, "
*
* @param array $arr
*/
function listize_from_array ($arr)
{
  $ret = ""; 
  for( $i = 0; $i < count($arr);  $i ++)
  {
    $ret .= $arr[$i];
    $ret .= ",";
  }
  return $ret;
}
?>
Richard_’s picture

Thank you coolclu3, now it works :)
Will keep you updated if anything goes wrong...

mercmobily’s picture

Hi,

Richard_: please please please test the hell out of this patch.
Does it do exactly what you expect it to? Does an existing site work after an upgrade?

Bye,

Merc.

Richard_’s picture

Hi coolclu3 and Merc.

I got something :)

NR1-----------------------
Bug? Weighting is not working, it did before (I can confirm on my 1.32 test server)

YTERM1(weight4)
ATERM2 (weight1)
GTerm3 (wieght2)
Are aligned like this: YTERM1, ATERM2, GTerm3 (they are aligned by the creation time probably).

NR2-------THIS IS DRIGG CORE BUG----------------
If you name TWO categories the same. Example "Cars" and "Cars".
A.You click the first category "Cars" it gives you correct results, but it highlite BOTH categories.
A.You click second category "Cars" it gives you INcorrect results from first category "Cars" and it highlites both categories too.

I use pathauto module along with categories, plus when you open vocabulary term list, you see taxonomy (or pathato) assigne different adress to each - like this: /cars and /cars-0. So taxonomy CAN differentiate between two categories with same names....

DRIGG MENU is giving "/Cars" path to both...

P.S. I got this combination by accident :-D
------------------------------------------------------------------------------

All the rest seems to be working so far .-)

mercmobily’s picture

Hi,

For the first problem: gosh, weights really should work. Any ideas about this one, coolclu3?

About the tro categories with the same name: "NO". This is by design -- each category MUST have a different name, end of story. If you have two categories with the same name, you're misusing Drigg.

Merc.

coolclu3’s picture

This is weird. The loop goes in the same fashion as before

    foreach( $terms['by_weight'] as $tid ){

so weights should be treated unchanged....thinking...

Richard_’s picture

Quote Merc.:
"If you have two categories with the same name, you're misusing Drigg."

:-))))

No problem, as I said I found it by accident, no plans to use two cats with same names....

Richard_’s picture

coolclu3 can you confirm this behaviour on your installation?
If you like you can email me admin pass so that I can test this behaviour on your installation too...

mercmobily’s picture

Hi,

Once the weight issue is sorted, I would like to apply this patch to the latest Drigg. It's just too important, and the port of Drigg to D6 has been delayed.

Bye,

Merc.

coolclu3’s picture

StatusFileSize
new167.13 KB

Hi
This is actually the bug I accidentally made.
In function drigg_section_list() (in helpers.inc) , when generating the list of terms, currently in my version -35, it is

	$result_t = db_query('SELECT * FROM {term_data} td 
			LEFT JOIN {term_hierarchy} th ON td.tid = th.tid 
			WHERE td.vid=%d 
			ORDER BY th.tid,weight',variable_get('drigg_section_vid', -1));

As you can see, the terms are ordered by 'tid' first, before 'weight'. (in the stable release drigg-5.x-1.34, there was no LEFT JOIN, so it was simply ordered by 'weight' only). So by changing this line (line 493 in helpers.inc of drigg-5.x-1.35.zip posted in comment #70) to

	$result_t = db_query('SELECT * FROM {term_data} td 
			LEFT JOIN {term_hierarchy} th ON td.tid = th.tid 
			WHERE td.vid=%d 
			ORDER BY weight,td.tid',variable_get('drigg_section_vid', -1));

we'll have the 'weight' problem sorted. Richard, can you please either modify this 'ORDER BY' line in modules/drigg/drigg/helpers.inc and test it? I've tried it on my site, and it works now
http://matsang.com (i'll email you the password shortly after this)

Or you can download this attached file where I named it drigg-5.x-1.35-2.zip, and fixed the error.
Cheers,

Richard_’s picture

Thank you coolclu3, now it works as desired :)

---------------------------------------------------

One more question. Have you considered to develop also "multiple select" functionality for this?

I have tested it and it works with 2 bugs:
A. It trigger error after edit
warning: Illegal offset type in /home/www/dev/modules/drigg/drigg/drigg.module on line 1016.

B. Category content disapear from "links section".

What is working within multiple-select category?
A. I can see node in those two categories where I assigned it.
B. It only trigger one node in "ALL SCOOP" mode (frontpage).

I also think that this functionality can be usefull although Merc. should evaluate its complexity... .-)

EDIT: Thank you for your testing access, I have tested mutliple select on your site, the same error there:
warning: Illegal offset type in ....all/modules/drigg/drigg/drigg.module on line 1008.

coolclu3’s picture

Hi Richard,
That's great news :)
I'm not sure what you're talking about. I first jumped in right away with drigg, but now I'm taking my time to read proper Drupal books to understand Drupal inside out. So I haven't been into drigg that much. (maybe in one month's time when I've read the books:) )

So if you could explain it in details your question (preferrably with steps), it'll be much easier to follow you.
Cheers

Richard_’s picture

:)
Ok I think that basic functinality works great. Your work is the biggest addition drigg needed :)
I needed this feature badly, so please email me your paypal account and I will transfer my promised "chip-in" to you. You are Godsend to this module :)
-----------------------------------------------
But if you are interested to develope this deeper, here is what it is about.

In categories setup (drigg vocabulary) you have an option "multiple select" which means that you can assign each scoop not only to one category but to multiple categories - for instance, you can post new scoop into "NEWS" and also into "TECHNOLOGY".
Without mutliple option you can only post each scoop into ONE category (NEWS) and that's it.
Between this is GREAT Drupal taxonomy feature.

:)

coolclu3’s picture

Richard, now i see what you mean. When i first installed drigg, I also asked myself the question why Multiselect wasn't allowed.

First of all, maybe this should be logged in a separate bug/request, because this bug is already long enough (80+, wow). (Excuse me if there's one already)

I had a quick look. In 'drigg_node' table, the 'safe_section' field is now only one section name.
And function drigg_insert_or_update() is only getting only one drigg_section_vid field.
$v=variable_get('drigg_section_vid', 0);

With my limited knowledge on Drupal learned so far, I think there are 4 things that need to be done:

1. Getting variables right, not just 1 category, but all of them.
2. Serialize safe_section(s) array to be inserted to 'safe_section' field (which will probably have to be extended to be more than just currently 128 chars
3. Unserialize safe_section(s) when getting the drigg node info
4. Displaying it.

So there's probably no need for DB change. Right now, I can't promise you that I will have time to implement this feature. I'm listing this here in case somebody's interested in realizing it. I really hope that Merc has time to confirm on this.

I will be able to clarify this after 2 weeks,when my understanding of Drupal is deeper.
And btw, thanks for chip-in. I'm glad this subcategory thing works :)
Cheers,

mercmobily’s picture

Hi,

Sorry, ONE category per node, by design. No real discussions about this -- and especially, not here.

** LET'S KEEP BUG REPORTS AND BUGS **SHARP** AND CLEAN

Adding requests and other notes to existing reports is messy. Let's keep everything focussed.

Bye,

Merc.

mercmobily’s picture

Hi,

So... we have a working patch!
Shall I apply it? Richard?

Is anybody else able to test it?

Bye!

Merc.

mercmobily’s picture

Hi,

Actually...

@coolclu3: please submit this as a proper patch, with the two bug fixes (the query and the missing function).

I will give it one last review, and will then commit it.

ONE IMPORTANT NOTE: I am going absolutely absolutely insane reformatting people's patches and modifications so that the formatting is right. PLEASE don't use tabs -- please indent with two spaces instead, like the rest of Drupal and drigg (and most of GNU code). This will save me tons of time!

I am very ready to submit this.

Bye!

Merc.

Richard_’s picture

Hi Merc,

I havent found any more issues, I am happy to use it.

Fantastic job coolclu3!!!! Congrats to your Drupal and Drigg contribution .-)

BIG THANK YOU!!!!

mercmobily’s picture

Hi,

@coolclu3: I don't mean to be a pain, but... please send me the patch as soon as you possibly can. I really, really want to get this in before the port to D6 starts, since it will be such a pain to forward port and Richard and Andrea have tested it and reported no problems.

Bye,

Merc.

coolclu3’s picture

StatusFileSize
new137.5 KB
new12.55 KB

Hi Merc,
So here is the patch for drigg-5.x-1.34 , I named it after the node # of this request.
And the packaged drigg-5.x-1.35-3.tar.gz

It's all following Drupal's coding standards. Now that I've read the book, I'd like to start digging and help Drigg :) I see potential in this module and need extra features too.

OK, Cheers

mercmobily’s picture

Status: Active » Fixed

Hi,

Checked, applied, tested, committed.

THANK YOU coolclu3!!!

Merc.

Richard_’s picture

Chip-in gladly transfered :)
I hope that next time there will be more chip-ins :-D

mercmobily’s picture

Richard, if you want any of the issues in the queue to get priority, please say so in the queue -- I am sure they will get done very quickly.

:-D

(They will get done ANYWAY... however, money will definitely speed up development)

invisible’s picture

Category: feature » support

First of all, thank you to those who worked so hard on the submenu feature.

Now that the patch has been created, can I just replace the current files with the new files from post #89 and hope the submenu works? Or are there more steps to follow in order to get the submenu feature to work? Could you please list the steps?

Also, above there was an issue with having two categories with the same name. Is this still an issue and if so, does it pertain to subcategories? I will be using multiple subcategories with the same name.

Thanks,
Tom

mercmobily’s picture

Hi,

You can't use subcategories with the same name. This is by design, and won't change -- sorry.

Yes you can replace the files. However, if you have customised your theme, then you will need to be careful. What I'd do, is look at the patch and see what the differences are.

Unfortunately this patch requires a slight theme change, which is a bit of a pain...

Bye!

Merc.

mercmobily’s picture

Status: Fixed » Closed (fixed)
Richard_’s picture

Hi Merc. I respect this is closed, I just wanted to say that "never say never" :)

Some people might use subcategory like "other" in each category, which might be needed...

mercmobily’s picture

Hi,

Richard, allowing two subcategories with the same name would require a huge amount of work -- AND it would break a lot of existing mechanisms in Drigg.

A *lot* of Drigg is based on the fact that a category name is unique. This include source code, URL structure, the way the menu system is stored, and so on.

So, I think this is going to be a hard-coded "never"...

Merc.

bflora’s picture

Question, so does the "Category" vocabulary now need to be set to single hierarchy? Have the drigg installation instructions changed?

mercmobily’s picture

Hi,

Adding a question to a closed, archived and hard-to-see bug is not a good idea.
Please open a new bug, for the "documentation" part of Drigg.

Bye,

Merc.