Re: [Catalyst] Users hierarchy

2008-06-06 Thread Andrew Rodland
On Friday 06 June 2008 10:46:53 pm Jonathan Rockway wrote: > * On Fri, Jun 06 2008, [EMAIL PROTECTED] wrote: > > Gulp, that should have been 0 :) > > Actually, it should have been "!" as in "if(!$found ...)". Perl has a > variety of "false" values including 0, undef, and the empty string. > Perl's

Re: [Catalyst] Users hierarchy

2008-06-06 Thread Jonathan Rockway
* On Fri, Jun 06 2008, [EMAIL PROTECTED] wrote: > Gulp, that should have been 0 :) Actually, it should have been "!" as in "if(!$found ...)". Perl has a variety of "false" values including 0, undef, and the empty string. Perl's built-in boolean operators return "undef" or "1" as false or true, bu

Re: [Catalyst] Users hierarchy

2008-06-06 Thread sindharta_tanuwijaya
Gulp, that should have been 0 :) Sindharta Jonathan Rockway <[EMAIL PROTECTED]> wrote: * On Tue, Jun 03 2008, [EMAIL PROTECTED] wrote: > while ($found==false && $ancestor) { Perl does not have a "false" operator. Regards, Jonathan Rockway -- print just => another => perl => hacker => if $,=$

Re: [Catalyst] Users hierarchy

2008-06-04 Thread Jonathan Rockway
* On Tue, Jun 03 2008, [EMAIL PROTECTED] wrote: > while ($found==false && $ancestor) { Perl does not have a "false" operator. Regards, Jonathan Rockway -- print just => another => perl => hacker => if $,=$" ___ List: Catalyst@lists.scsys.co.uk Listin

Re: [Catalyst] Users hierarchy

2008-06-04 Thread Jonathan Rockway
* On Wed, Jun 04 2008, jakac wrote: > I checked out DBIx::OO::Tree also but using this module would mean > that I would have to change my table schema (add columns parent,lft,rgt,mvg).. > I don't see why this is necessary since the whole thing needs only two colums > - > user_id and parent_id ...?

Re: [Catalyst] Users hierarchy

2008-06-04 Thread jakac
I checked out DBIx::OO::Tree also but using this module would mean that I would have to change my table schema (add columns parent,lft,rgt,mvg).. I don't see why this is necessary since the whole thing needs only two colums - user_id and parent_id ...? If I know a user_id then I can always get

Re: [Catalyst] Users hierarchy

2008-06-04 Thread vb
perhaps DBIx::OO::Tree could help you? On Wed, Jun 4, 2008 at 1:53 PM, jakac <[EMAIL PROTECTED]> wrote: > I also discovered DBIx::Class::Tree::AdjacencyList > Using this module I can define my parent_id in my Users.pm schema like: > > __PACKAGE__->parent_column('parent_id'); > > > And then I c

Re: [Catalyst] Users hierarchy

2008-06-04 Thread jakac
I also discovered DBIx::Class::Tree::AdjacencyList Using this module I can define my parent_id in my Users.pm schema like: __PACKAGE__->parent_column('parent_id'); And then I can get all children of one user like: my $user_id = 7; my $thisuser = $c->model('MyDB::Users')->find({ user_id=> $use

Re: [Catalyst] Users hierarchy

2008-06-04 Thread jakac
Hi, Ok, I understand the concept of walking through this DB::User model but another question is - where should I put this function and how should I call it from my controllers? Until now I only used basic integrated functions that are integrated in catalyst & its plugins so I am not familiar with

Re: [Catalyst] Users hierarchy

2008-06-03 Thread sindharta_tanuwijaya
Hi, Haven't tried it yet, but I think the code in Catalyst should look like: my $edited = $c->model('DB::User')->find({id=>$target_user_id}); my $ancestor = $c->model('DB::User')->find({id=>$edited->{parent_id}}); my $found = 0; while ($found==false && $ancestor) { if ($ancestor == $c.user.user

Re: [Catalyst] Users hierarchy

2008-06-03 Thread jakac
Yes this seems fine but how to code this in Catalyst? :) And another thing - if I want to list users that certain this_user can edit, I would need to go through the whole list and check for each user if "this_user" is one of the (grand)parents. Your approach is bottom-to-top and I now I am also l

Re: [Catalyst] Users hierarchy

2008-06-03 Thread John Tate
Check out Nested Trees, Joe Celko has some articles about them. Mojomojo has a pretty complete implementation of one in dbix:class if I remember. Along the same lines, you could look at "modified pre-order tree traversal". There's a nice sitepoint article about the method: http://www.sit

Re: [Catalyst] Users hierarchy

2008-06-02 Thread sindharta_tanuwijaya
Hi, Maybe an algorithmic approach ? -- ancestor = edited.parent; found = false; while (found==false and ancestor!=null) { if (ancestor == current_user) found= true; ancestor = ancestor.parent } return found; -- I came from C++ background rather than Perl, so I am sorry if it looks more

Re: [Catalyst] Users hierarchy

2008-06-02 Thread Wade . Stuart
jakac <[EMAIL PROTECTED]> wrote on 06/02/2008 09:59:37 AM: > Hello! > > I need a help on building a model for user that has a permission to edit > other users that were created by this user or any of his children, > grandchildren etc. > (difficult sentence, I know) > > To make this a little more

Re: [Catalyst] Users hierarchy

2008-06-02 Thread Jonathan Hall
I make no claim at being an expert, but here's what we do... If there's a better way, I'm all ears! We use two tables. A Users table, and a Parents table that acts as a map between users and all of their possible parents. CREATE TABLE users ( user_id SERIAL PRIMARY KEY, par

Re: [Catalyst] Users hierarchy

2008-06-02 Thread Gabriel Vieira
I usually use a subid to identify child's parent as you do. So I run bottom to top to get to the major user. With this I can see if the some ID have access to other. This may be slow. Let's see what gurus have to say. :) 2008/6/2 jakac <[EMAIL PROTECTED]>: > Hello! > > I need a help on building a

[Catalyst] Users hierarchy

2008-06-02 Thread jakac
Hello! I need a help on building a model for user that has a permission to edit other users that were created by this user or any of his children, grandchildren etc. (difficult sentence, I know) To make this a little more understandable here's my database table: - user_id - username - passwor