Re: [Catalyst] Retrieve all users belong to a category and all its sub categories

2010-12-10 Thread Emmanuel Otton

Le 09/12/2010 09:37, linuxsupport a écrit :
I have 3 tables, users, user_cat, and cat, table structure and 
relationship are setup as follows.

User.pm
__PACKAGE__-add_columns(
  id, { data_type = integer, is_nullable = 0 },
  username,{ data_type = text, is_nullable = 1 },
  password,  { data_type = text, is_nullable = 1 },
  email_address,  { data_type = text, is_nullable = 1 },
  first_name,  { data_type = text, is_nullable = 1 },
  last_name,  { data_type = text, is_nullable = 1 },
  active,  { data_type = integer, is_nullable = 1 },
);
__PACKAGE__-set_primary_key(id);
__PACKAGE__-has_many(usercats, Example::Schema::Result::UserCat,{ 
foreign.user_id = self.id http://self.id/ },);

__PACKAGE__-many_to_many(cats = 'usercats', 'cat');

UserCat.pm
__PACKAGE__-add_columns(
  user_id,  { data_type = integer, is_nullable = 0 },
  cat_id,  { data_type = integer, default_value = 0, is_nullable 
= 0 },

);
__PACKAGE__-set_primary_key(user_id, cat_id);
__PACKAGE__-belongs_to(user, Example::Schema::Result::User, { id 
= user_id },{ join_type = LEFT },);
__PACKAGE__-belongs_to(cat, Example::Schema::Result::Cat, { id = 
cat_id },{ join_type = LEFT },);


Cat.pm
__PACKAGE__-add_columns(
  id,  { data_type = integer, is_nullable = 0 },
  cat_name,  { data_type = text, is_nullable = 0 },
 parent_id,  { data_type = integer, is_nullable = 0 },
);
__PACKAGE__-set_primary_key(id,parent_id);
__PACKAGE__-has_many(usercat,Example::Schema::Result::UserCat,{ 
foreign.cat_id = self.id http://self.id/ },);

__PACKAGE__many_to_many(allcat, usercat', cat);

I am able to retrieve all users in any particular category using 
allcat many_to_many relationship.

Are you, really ?
The navigation path you indicate in your allcat many_to_many 
relationship does not seem to lead from Cat to Users but from Cat to Cat 
itself, which seems of no practical use.


I rather would have written:
__PACKAGE__-many_to_many(users,usercat,user);

So that I can get the users in any category this way:
my $cat = $schema-resultset(Cat)-find($my_cat_id);
my @users_belonging_directly_to_that_category = $cat-users;

In cat table I have both category and sub category, if a row have 
parent_id  0 then it is sub category.

How can I get all users belong to one category and its sub categories?
Now to get recursively all users belonging to this category AND all 
sub-categories is another problem.


The procedural/Perlish/DBIx::Classish solution would be:
# first, add to Cat.pm an accessor to the sub-categories
__PACKAGE__-has_many(subcats,Example::Schema::Result::Cat,{ 
foreign.parent_id = self.id http://self.id/ });


# then, in your program:
my $cat = $schema-resultset(Cat)-find($my_cat_id);
my @users_belonging_to_that_category_and_its_subcats = $cat-users;

my @subcats = $cat-subcats;
for my $subcat (@subcats)
push @users_belonging_to_that_category_and_its_subcats , $cat-users;
}
# assuming the reflexive relationship is one level only
# i.e. no sub-sub-..etc..-categories


A (better in my -humble- opinion) solution would be more SQL-oriented 
(after all, isn't the declarative SQL way the reason why we all use 
RDBMSes ?)


First of all, create a view giving what you want:

create view users_by_cat_and_subcats as
select cat.id cat_id, user.*
  from cat join usercat on usercat.cat_id = cat.id
  join user on user.id = usercat.user_id
union select parent.cat.id cat_id , user.*
  from cat parent_cat join cat child_cat on child_cat.parent_id = 
parent_cat.cat_id

  join usercat on usercat.cat_id = child_cat.id
  join user on user.id = usercat.user_id ;

Then create (automatically, by make_schema_at) a UsersByCatAndSubcat.pm 
to map this table to a DBIx::Class and just use it:

my @users_belonging_to_that_category_and_its_subcats =
   $schema-resultset('UsersByCatAndSubcat')-search( { cat_id = 
$my_category } )-all;


It's always difficult to use the right tool, and I've seen ugly things 
like simple left joins replaced by 15 lines of while, if defined, 
push,etc...
RDBMSes have dominated our domain for nearly forty years for a reason, 
which is the expressive power of SQL, itself based on strong theoretical 
mathematical background.
My advice is: don't forget you have a RDBMS, and thus the full power of 
SQL, at your disposal.


Sorry for this answer to a slightly off-catalyst-topic question; I will 
subscribe to the DBIx::Class list right away.


--
Emmanuel Otton - Ecole des mines d'Albi-Carmaux - département informatique - 
Tél: 05 63 49 30 86

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] Authentication using OpenID

2010-12-10 Thread Blaine Everingham

Currently Facebook is not part of OpenID. Therefore you would need to have two 
different authentication credential modules. 

OpenID
Catalyst::Authentication::Credential::OpenID

Facebook
Catalyst::Authentication::Credential::FBConnect


Date: Fri, 10 Dec 2010 00:11:46 +0530
From: vi...@chhikara.org
To: catalyst@lists.scsys.co.uk
Subject: [Catalyst] Authentication using OpenID

Hi,

I want to have my users authenticated using openid. If users are logging in for 
the first time, I want to get the details, provided by say facebook, to be 
saved in my DB.

Which Catalyst authentication Plug-in should be used in order to achieve this 
goal.


Vivek










 
 

















 






 



 
 
 









 

















 




 






















 




 




 











RE: [Catalyst] Authentication using OpenID

2010-12-10 Thread Vivek Chhikara


OK. 

I am able to use
Catalyst::Authentication::Credential::OpenID, and after authenticating
with google, I get 

Catalyst::Plugin::Authentication::User::Hash
object, but when i try to get the user details, 

 $c-user-url

$c-user-display

I am getting exceptions related to method not found.


Can we access used details say Name , Email etc using
Catalyst::Authentication::Credential::OpenID or  

we have to use
something else say oAuth to get details. 

Basically, I want to simplify
the user registration to my app when somebody logs in for the first
time. 

Vivek 

On Fri, 10 Dec 2010 14:14:38 +, Blaine Everingham 
wrote:  Currently Facebook is not part of OpenID. Therefore you would
need to have two different authentication credential modules.


OpenID
Catalyst::Authentication::Credential::OpenID

Facebook
Catalyst::Authentication::Credential::FBConnect

-

Date: Fri, 10 Dec 2010 00:11:46 +0530
From: vi...@chhikara.org
To:
catalyst@lists.scsys.co.uk
Subject: [Catalyst] Authentication using
OpenID

Hi,

I want to have my users authenticated using openid. If
users are logging in for the first time, I want to get the details,
provided by say facebook, to be saved in my DB.

Which Catalyst
authentication Plug-in should be used in order to achieve this
goal.

Vivek

___ List:
Catalyst@lists.scsys.co.uk Listinfo:
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable
archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev
site: http://dev.catalyst.perl.org/ 

-- 

Vivek Chhikara [1]



Links:
--
[1] http://www.chhikara.org/wordpress
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Transferring control via root/auto

2010-12-10 Thread Tomas Doran


On 9 Dec 2010, at 14:41, Thompson wrote:

How would you use a chained dispatch to solve a problem like this?   
Something that needs to be checked before allowing anything else  
(besides logging in) to happen and if so force them to a specific  
page?  A simple example would help.


The simplest example I can think of - CatalystX::SimpleLogin provides / 
login/required and /login/not_required as chain bases.


Anything chained from /login/required requires login :)

Obviously, displaying the login page is _not_ chained from /login/ 
required (as otherwise you have the same issue as here)


I'm still have it in my head that this logic should be done in the  
root controller since it would supersede any action in my other  
controllers.


There is nothing special about the root controller that implies this.

It's just generally people put the start of their chains in the Root  
controller.


As demonstrated by the above example (with the chain starts in the  
Login controller), this isn't mandatory.


Does this help clarify?

Cheers
t0m


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


RE: [Catalyst] Authentication using OpenID

2010-12-10 Thread Blaine Everingham

If you want to grab other user data then you have to use an extension
 openid = {  credential = {  
class = OpenID,  store = {  
class = OpenID,  },  consumer_secret 
= Don't bother setting,  ua_class = LWP::UserAgent,   
   # whitelist is only relevant for LWPx::ParanoidAgent 
 ua_args = {  whitelisted_hosts = [qw/ 
127.0.0.1 localhost /],  },  extensions 
= [  
'http://openid.net/srv/ax/1.0' = {mode = 
'fetch_request','type.nickname' = 
'http://axschema.org/namePerson/friendly','type.email' = 
'http://axschema.org/contact/email','type.fullname' = 
'http://axschema.org/namePerson','type.firstname' = 
'http://axschema.org/namePerson/first','type.lastname' = 
'http://axschema.org/namePerson/last','type.dob' = 
'http://axschema.org/birthDate','type.gender' = 
'http://axschema.org/person/gender','type.country' = 
'http://axschema.org/contact/country/home','type.language' 
= 'http://axschema.org/pref/language','type.timezone' = 
'http://axschema.org/pref/timezone',required = 
'nickname,fullname,email,firstname,lastname',if_available 
= 'dob,gender,country,language,timezone',}
  ],  },
To: catalyst@lists.scsys.co.uk
Subject: RE: [Catalyst] Authentication using OpenID
Date: Fri, 10 Dec 2010 20:01:20 +0530
From: vi...@chhikara.org

OK.
I am able to use Catalyst::Authentication::Credential::OpenID, and after 
authenticating with google, I get
Catalyst::Plugin::Authentication::User::Hash object, but when i try to get the 
user details,
   $c-user-url
   $c-user-display
I am getting exceptions related to method not found.
Can we access used details say Name , Email etc using 
Catalyst::Authentication::Credential::OpenID or 
we have to use something else say oAuth to get details.
Basically, I want to simplify the user registration  to my app when somebody 
logs in for the first time.
 
Vivek
 
On Fri, 10 Dec 2010 14:14:38 +, Blaine Everingham 
grandmasterbla...@hotmail.com wrote:
 Currently Facebook is not part of OpenID. Therefore you would need to have two 
different authentication credential modules. 

OpenID
Catalyst::Authentication::Credential::OpenID

Facebook
Catalyst::Authentication::Credential::FBConnect




Date: Fri, 10 Dec 2010 00:11:46 +0530
From: vi...@chhikara.org
To: catalyst@lists.scsys.co.uk
Subject: [Catalyst] Authentication using OpenID

Hi,

I want to have my users authenticated using openid. If users are logging in for 
the first time, I want to get the details, provided by say facebook, to be 
saved in my DB.

Which Catalyst authentication Plug-in should be used in order to achieve this 
goal.

Vivek



















 
 

















 





 

 
 
 

































 


 






























































 











































___ List: 
Catalyst@lists.scsys.co.uk Listinfo: 
http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: 
http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: 
http://dev.catalyst.perl.org/
 
-- 

Vivek Chhikara

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/ 
  ___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Static MultiViews?

2010-12-10 Thread Tomas Doran


On 9 Dec 2010, at 09:31, Dorian Taylor (Lists) wrote:


Hello,

I'm trying to find an a plugin or something that does some  
rudimentary content negotiation, i.e. multiviews, i.e. serving  
static files without their extensions. Can't seem to find anything  
despite having scoured for hours. Clearly my search-fu is not up to  
snuff. Pointers?


I'm very confused by this question..

MultiViews is an apache feature for language customisation, and has  
nothing to do with not having extensions on files.


It's entirely possible to serve static files without extensions if you  
want to...


What are you _actaully_ trying to do?

Cheers
t0m


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] FormHandler -- pro or con?

2010-12-10 Thread Sir Robert Burbridge

On 12/10/2010 01:33 PM, Erez Schatz wrote:

On 9 December 2010 16:32, Sir Robert Burbridgerburb...@cisco.com  wrote:

   

Ideally, the web designers that don't know Perl at all should be able to
change the design of the forms at least.


Maybe I'm being naive, but what does the HFH form have to do with the
design?  If you give them meaningful ids and class names, the designers can
do whatever they need with CSS and the templates, right?
 

That's the main issue with these html generators, the programmers
create the code in a nice Perl class, and then the generator does its
magic, which includes a lot of stuff the designer later have to
handle, but can't, unless you're willing to make everything
display:absolute with fixed locations. The only way to force a layout
on the generator is to override it and manually write the html, which
is somewhat silly considering the purpose of using a generator in the
first place.
   
Fair enough.  I guess I just never ran into this problem.  We've tended 
to try to make the html purely semantic, which has gone a long way.  On 
the other hand, we have (semantically meaningful) manual renderings of 
our forms in templates, then just [% INCLUDE 
form/whatever/do_something.tt %] whenever we need it (sometimes with 
context-specific params), so it's not really HFH rendering, but TT.


-Sir


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Static MultiViews?

2010-12-10 Thread Dorian Taylor (Lists)


On 10-Dec-10, at 7:59 AM, Tomas Doran wrote:



On 9 Dec 2010, at 09:31, Dorian Taylor (Lists) wrote:


Hello,

I'm trying to find an a plugin or something that does some  
rudimentary content negotiation, i.e. multiviews, i.e. serving  
static files without their extensions. Can't seem to find anything  
despite having scoured for hours. Clearly my search-fu is not up to  
snuff. Pointers?


I'm very confused by this question..

MultiViews is an apache feature for language customisation, and has  
nothing to do with not having extensions on files.


Language, mime type, charset and content encoding, actually. I was  
looking for similar behaviour but implemented in Catalyst (i.e.  
presumably using HTTP::Negotiate).




It's entirely possible to serve static files without extensions if  
you want to...


What are you _actaully_ trying to do?



Content negotiation like I said above. Sorry for the confusion. It's  
OK anyway, I wrote my own.


Thanks,

--
Dorian Taylor
Make things. Make sense.
http://doriantaylor.com


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Re: Static MultiViews?

2010-12-10 Thread Aristotle Pagaltzis
* Tomas Doran bobtf...@bobtfish.net [2010-12-10 17:05]:
 MultiViews is an apache feature for language customisation, and
 has nothing to do with not having extensions on files.

No it isn’t (just), and yes it does. MultiViews allows you to put

directory.png
directory.gif
directory.ico

in `/icon/`, then use the URI `/icon/directory` (notice the lack
of extension) to let Apache decide which of these files to serve
to the browser, based on the `Accept` header sent by the browser
and the MIME type ↔ filename extension mapping from the Apache
configuration.

I don’t think such a thing exists for Catalyst.

Regards,
-- 
Aristotle Pagaltzis // http://plasmasturm.org/

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/