midgard_sitegroup

Posted on 2007-04-12 14:42:02 EEST.

I have already created midgard database and tables so now it's high time to create new sitegroup. New , installed database has already "built-in" Midgard Administrator account. It's done automagically so nothing to worry about at this point.

Log in to Midgard framework:

$user = midgard_user::auth('admin', 'password');

You can check if logged in user is root. But it's not mandatory as midgard-core will do it for you.

if($user->is_root()) { /* do something */ }

$sg = new midgard_sitegroup();
$sg->name = "My Test Sitegroup";
$sg->realm = "My Test Sitegroup Realm";

At this point we are ready to create new sitegroup , but this sitegroup will be private one. By "private" I mean it's not public so anonymous user can not see it or use. To make it public set its 'public' property to TRUE.

$sg->public = TRUE;

Create it.

$sg->create();

Sitegrup is created. We defined it as public so you can use it for example with login screen well known from Aegir. To list all sitegroups you can use list method.

$sitegroups = midgard_sitegroup::list();

This method returns array of sitegroup names. If you are anonymous user you get only names. Guid, realm and other data are completely hidden for you. But if you are logged in as root, you can get sitegroup object using it's name.

$new_sg = new midgard_sitegroup($sitegroups[0]);

Now, you can create new group and define it as sitegroup's administrator group.

$grp = new midgard_group();
$grp->name = $sg->name ."administrators group";

Keep in mind that it's last chance to set group sitegroup! As long as you are logged in as root, you can do this.

$grp->sitegroup = $sg->id;
$created = $grp->create();

if($created) {
    $sg->group = $grp->guid;
    $sg->update();
}

Stay tuned ( for a while only ) to learn more about "how to create midgard person account".

Back

Layout Copyright © 2006 Finnish Teleservice Center Ltd Oy - Site Powered by Midgard CMS