コード例 #1
0
ファイル: start.php プロジェクト: socialweb/PiGo
/**
 * 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;
}
コード例 #2
0
ファイル: add.php プロジェクト: eokyere/elgg
action_gatekeeper();
admin_gatekeeper();
global $CONFIG;
$name = get_input("metadata_name");
$label = get_input("metadata_label");
$guid = get_input("guid");
$profile_types = get_input("profile_types");
if (!empty($name)) {
    if (!empty($guid)) {
        $object = get_entity($guid);
        if (!empty($object) && !$object instanceof ProfileManagerCustomFieldCategory) {
            $object = null;
        }
    }
    if (empty($object)) {
        $object = new ProfileManagerCustomFieldCategory();
        $object->save();
        $add = true;
    }
    if (!empty($object)) {
        $object->metadata_name = $name;
        if (!empty($label)) {
            $object->metadata_label = $label;
        } else {
            unset($object->metadata_label);
        }
        // add relationship
        remove_entity_relationships($object->guid, CUSTOM_PROFILE_FIELDS_PROFILE_TYPE_CATEGORY_RELATIONSHIP);
        if (!empty($profile_types) && is_array($profile_types)) {
            foreach ($profile_types as $type) {
                add_entity_relationship($type, CUSTOM_PROFILE_FIELDS_PROFILE_TYPE_CATEGORY_RELATIONSHIP, $object->guid);
コード例 #3
0
 */
admin_gatekeeper();
global $CONFIG;
$name = get_input("metadata_name");
$label = get_input("metadata_label");
$guid = get_input("guid");
$profile_types = get_input("profile_types");
if (!empty($name) && preg_match("/^[a-zA-Z0-9_]{1,}\$/", $name)) {
    if (!empty($guid)) {
        $entity = get_entity($guid);
        if (!empty($entity) && !$entity instanceof ProfileManagerCustomFieldCategory) {
            $entity = null;
        }
    }
    if (empty($entity)) {
        $entity = new ProfileManagerCustomFieldCategory();
        $entity->save();
        $add = true;
    }
    if (!empty($entity)) {
        $entity->metadata_name = $name;
        if (!empty($label)) {
            $entity->metadata_label = $label;
        } else {
            unset($entity->metadata_label);
        }
        // add relationship
        remove_entity_relationships($entity->guid, CUSTOM_PROFILE_FIELDS_PROFILE_TYPE_CATEGORY_RELATIONSHIP, true);
        if (!empty($profile_types) && is_array($profile_types)) {
            foreach ($profile_types as $type) {
                add_entity_relationship($type, CUSTOM_PROFILE_FIELDS_PROFILE_TYPE_CATEGORY_RELATIONSHIP, $entity->guid);