Welcome Guest, Not a member yet? Register   Sign In
Mahana Hierarchy library
#1

[eluser]jmadsen[/eluser]
A small library based on the technique outlined here: http://ferdychristant.com/blog//archive/DOMM-7QJPM7

Stores & retrieves parent/child data without having to do recursive db hits. Comments in library file are pretty self-explanatory.

Output can either come in the form:

Record 1
Record 1.1
Record 1.2
Record 1.2.3
Record 2
...

or as a multi-dimensional array

https://github.com/jrmadsen67/mahana-hierarchy

All comments or recommendations welcomed.
#2

[eluser]jmadsen[/eluser]
Often threatened, rarely made good on...

a short tut on how to use this to create nested comments, etc without needing recursive functions:

http://codebyjeff.com/blog/2012/10/neste...hy-library

library has a couple of additions to make it a little easier to work with, as well
#3

[eluser]NeoArc[/eluser]
I'll use this library in a recent project for a welfare organization. Thanks a lot!
#4

[eluser]Noobigniter[/eluser]
I had a little time this morning, I took the opportunity to have a look there as I had said.
However, I have a question.
After multiple answers, I get this lineage:
Code:
00001-00002-00003-00006-00011-00012-00013-00014-00015-00016-00017
Why not just (less in db):
Code:
1-2-3-5-11-12-13-14-15-16-17

Otherwise, it happens when you post the 100000th post?


#5

[eluser]NeoArc[/eluser]
For forums and CMS's you can try this too (I'm not really sure about the performance, but I guess it's good since they use it in Prestashop):

http://mikehillyer.com/articles/managing...-in-mysql/
#6

[eluser]jmadsen[/eluser]
[quote author="Noobigniter" date="1350918671"]I had a little time this morning, I took the opportunity to have a look there as I had said.
However, I have a question.
After multiple answers, I get this lineage:
Code:
00001-00002-00003-00006-00011-00012-00013-00014-00015-00016-00017
Why not just (less in db):
Code:
1-2-3-5-11-12-13-14-15-16-17

Otherwise, it happens when you post the 100000th post?


[/quote]

the trick is to do a simple orderby on the lineage - if you don't pad, you get

1-11-111-2-...
#7

[eluser]jmadsen[/eluser]
[quote author="NeoArc" date="1350917098"]I'll use this library in a recent project for a welfare organization. Thanks a lot![/quote]

cool! let me know if you run into difficulties or have suggestions after using it
#8

[eluser]Noobigniter[/eluser]
A suggestion, I do not know if is is one, but I immediately changed one little thing in the class, so you can use it on several tables (pages, category, comments, etc ...)

I commented :
Code:
//protected $_table = 'hierarchy';
and added this
Code:
public function __construct($_table = '')
{
    $this->_table = $_table;
Then it only remains to choose the table to use.
Code:
$this->test = new Mahana_hierarchy('comments');
$comments = $this->test->get(0);

It's not much, but pretty handy.

Otherwise, nothing to report at this time.

PS: thank you
#9

[eluser]jmadsen[/eluser]
yes, not a bad idea. I think I might actually add a full $config in instead, so later we can config other things as well (like padding size, for example)

glad it's working out :-)
#10

[eluser]Noobigniter[/eluser]
Me again ^^
I noticed that it is easy to work on 1 table, however, and after creating a function like
Code:
get_where($top_id = 0, $where = false, $join = false)
, working on several tables becomes "dangerous ", even impossible if multiple identical fields in different tables (ie: id, user_id,..)
So I have to abandon much of the library, unfortunately.
I'll just use the system of "lineage" on insert, which I had not thought of.




Theme © iAndrew 2016 - Forum software by © MyBB