/** * Create a profile type and a default profile type category for a new role */ function roles_pm_event_create($event, $type, $entity) { if (!elgg_instanceof($entity, 'object', 'role')) { return true; } $profile_types = elgg_get_entities_from_relationship(array('relationship_guid' => $entity->guid, 'relationship' => 'roles_profile_type', 'count' => true)); if ($profile_types > 0) { return true; } // Create a profile type for the role $profile_type = new ProfileManagerCustomProfileType(); if ($profile_type->save()) { $profile_type->metadata_name = "{$entity->name}_profile"; $profile_type->metadata_label = elgg_echo('roles:pm:profile_type_label', array(elgg_echo($entity->title))); // Store profile type as a relationship to role add_entity_relationship($entity->guid, 'roles_profile_type', $profile_type->guid); // Create a default category for the role specific profile_type $category = new ProfileManagerCustomFieldCategory(); if ($category->save()) { $category->metadata_name = "{$entity->name}_profile_cat"; $category->metadata_label = elgg_echo('roles:pm:profile_type_cat_label', array(elgg_echo($entity->title))); $options = array("type" => "object", "subtype" => CUSTOM_PROFILE_FIELDS_CATEGORY_SUBTYPE, "count" => true, "owner_guid" => elgg_get_site_entity()->getGUID()); $count = elgg_get_entities($options); $category->order = $count; // Store profile type default category as a relationship to role add_entity_relationship($entity->guid, 'roles_profile_type_cat', $category->guid); add_entity_relationship($profile_type->guid, CUSTOM_PROFILE_FIELDS_PROFILE_TYPE_CATEGORY_RELATIONSHIP, $category->guid); } // Assign created profile type to users with the current role $users = $entity->getUsers(array()); if ($users) { foreach ($users as $user) { $user->custom_profile_type = $profile_type->guid; } } } return true; }
admin_gatekeeper(); $guid = get_input("guid"); $name = get_input("metadata_name"); $label = get_input("metadata_label"); $description = get_input("metadata_description"); $show_on_members = get_input("show_on_members", "no"); $categories = get_input("categories"); if (!empty($name) && preg_match("/^[a-zA-Z0-9_]{1,}\$/", $name)) { if (!empty($guid)) { $object = get_entity($guid); if (!empty($object) && !$object instanceof ProfileManagerCustomProfileType) { $object = null; } } if (empty($object)) { $object = new ProfileManagerCustomProfileType(); $object->save(); } if (!empty($object)) { $object->metadata_name = $name; if (!empty($label)) { $object->metadata_label = $label; } else { unset($object->metadata_label); } if (!empty($description)) { $object->metadata_description = $description; } else { unset($object->metadata_description); } $object->show_on_members = $show_on_members;