delete($user->id); } /** * Called when admin is adding a user */ static function user_add_form_admin($user, $form) { $form->add_user->dropdown("user_chroot") ->label(t("Root Album")) ->options(self::createGalleryArray()) ->selected(0); } /** * Called after a user has been added */ static function user_add_form_admin_completed($user, $form) { $user_chroot = ORM::factory("user_chroot")->where("id", "=", $user->id)->find(); $user_chroot->id = $user->id; $user_chroot->album_id = $form->add_user->user_chroot->value; $user_chroot->save(); } /** * Called when admin is editing a user */ static function user_edit_form_admin($user, $form) { $user_chroot = ORM::factory("user_chroot")->where("id", "=", $user->id)->find(); if ($user_chroot->loaded()) { $selected = $user_chroot->album_id; } else { $selected = 0; } $form->edit_user->dropdown("user_chroot") ->label(t("Root Album")) ->options(self::createGalleryArray()) ->selected($selected); } /** * Called after a user had been edited by the admin */ static function user_edit_form_admin_completed($user, $form) { $user_chroot = ORM::factory("user_chroot")->where("id", "=", $user->id)->find(); if ($user_chroot->loaded()) { $user_chroot->album_id = $form->edit_user->user_chroot->value; } else { $user_chroot->id = $user->id; $user_chroot->album_id = $form->edit_user->user_chroot->value; } $user_chroot->save(); } /** * Creates an array of galleries */ static function createGalleryArray() { $array[0] = "none"; $root = ORM::factory("item", 1); self::tree($root, "", $array); return $array; } /** * recursive function to build array for drop down list */ static function tree($parent, $dashes, &$array) { if ($parent->id == "1") { $array[$parent->id] = ORM::factory("item", 1)->title; } else { $array[$parent->id] = "$dashes $parent->name"; } $albums = ORM::factory("item") ->where("parent_id", "=", $parent->id) ->where("type", "=", "album") ->order_by("title", "ASC") ->find_all(); foreach ($albums as $album) { self::tree($album, "-$dashes", $array); } return; } }