Attaching the diff from my first attempt. Basically, I added a number of tests to the JUser::get() method to detect for the
special attributes such as 'aid', 'admin', etc.... I think this provides some useful functionality in the J 1.0 sense of things.
The diff is based on revision 6221. I tested using PHP 5.1.something. ???
To test the code, I used the following code.
Code:
$user1 = JFactory::getUser();
$id = $user1->get('id');
$name = $user1->get('name');
$aid = $user1->get('aid');
$group = $user1->get('gid');
$guest = $user1->get('guest');
$admin = $user1->get('admin');
$type = $user1->get('usertype');
$message= $guest ? 'Visitor' : ( $admin ? 'Admin' : 'Somebody' );
echo "User1 $name ($id) is $message: gid($group), access($aid), type($type)<br/>";
$user2 = new JUser();
$user2->load(63);
$id = $user2->get('id');
$name = $user2->get('name');
$aid = $user2->get('aid');
$group = $user2->get('gid');
$guest = $user2->get('guest');
$admin = $user2->get('admin');
$type = $user2->get('usertype');
$message= $guest ? 'Visitor' : ( $admin ? 'Admin' : 'Somebody' );
echo "User2 $name ($id) is $message: gid($group), access($aid), type($type)<br/>";
$user3 = new JUser();
$user3->load(62);
$id = $user3->get('id');
$name = $user3->get('name');
$aid = $user3->get('aid');
$group = $user3->get('gid');
$guest = $user3->get('guest');
$admin = $user3->get('admin');
$type = $user3->get('usertype');
$message= $guest ? 'Visitor' : ( $admin ? 'Admin' : 'Somebody' );
echo "User3 $name ($id) is $message: gid($group), access($aid), type($type)<br/>";
It produces the results that I would expect.
Code:
User1 (0) is Visitor: gid(0), access(0), type(Public Frontend)
User2 tcp (63) is Somebody: gid(19), access(2), type(Author)
User3 Administrator (62) is Admin: gid(25), access(2), type(Super Administrator)
After looking at and working with the code, I can say that there is still a lot of work to do and it should be interesting to see an ACL implementation in J 1.6. In the meantime, the current framework is excellent.
Feedback always appreciated.
tcp
Edit: Forgot to mention that I added a method named getGroupData() which returns a Stdclass object with group information ( basically jinx's code from the user plugin). Although this can work ok as a protected method, what I would really like to see is a simple method ( eg, JUser::getGroup() ) that returns group information for the given user. The information returned could be an object of JTableAroGroup or "JGroup". Even an initial implementation may be out of the scope for 1.5, but it would be nice to have an interface to JAuthorization where I could code something like the following.
Code:
$user = new Juser();
$user->load(#);
$group1 = $user->getGroup();
$group2 = $group1->getParentGroup();
$name = $group2->get('name');
Probably a can of worms. Well, food for thought.