Ejemplo n.º 1
0
/**
 * Registers the buttons for title area of the group profile page
 *
 * @param ElggGroup $group
 */
function groups_register_profile_buttons($group)
{
    $actions = array();
    // group owners
    if ($group->canEdit()) {
        // edit and invite
        $url = elgg_get_site_url() . "groups/edit/{$group->getGUID()}";
        $actions[$url] = 'groups:edit';
        $url = elgg_get_site_url() . "groups/invite/{$group->getGUID()}";
        $actions[$url] = 'groups:invite';
    }
    // group members
    if ($group->isMember(elgg_get_logged_in_user_entity())) {
        if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) {
            // leave
            $url = elgg_get_site_url() . "action/groups/leave?group_guid={$group->getGUID()}";
            $url = elgg_add_action_tokens_to_url($url);
            $actions[$url] = 'groups:leave';
        }
    } elseif (elgg_is_logged_in()) {
        // join - admins can always join.
        $url = elgg_get_site_url() . "action/groups/join?group_guid={$group->getGUID()}";
        $url = elgg_add_action_tokens_to_url($url);
        if ($group->isPublicMembership() || $group->canEdit()) {
            $actions[$url] = 'groups:join';
        } else {
            // request membership
            $actions[$url] = 'groups:joinrequest';
        }
    }
    if ($actions) {
        foreach ($actions as $url => $text) {
            elgg_register_menu_item('title', array('name' => $text, 'href' => $url, 'text' => elgg_echo($text), 'link_class' => 'elgg-button elgg-button-action'));
        }
    }
}
Ejemplo n.º 2
0
/**
 * Registers the buttons for title area of the group profile page
 *
 * @param ElggGroup $group
 */
function groups_register_profile_buttons($group)
{
    $user = elgg_get_logged_in_user_entity();
    $actions = array();
    // group owners
    if ($group->canEdit()) {
        // local groups except town groups cannot be edited (except by admins)
        if ($group->grouptype != 'local' || $group->grouptype == 'local' && $group->localtype == 'town' || $user->isAdmin()) {
            $url = elgg_get_site_url() . "groups/edit/{$group->getGUID()}";
            $actions[$url] = 'groups:edit';
        }
        // local groups except town groups cannot use invitation system
        if ($group->grouptype != 'local' || $group->grouptype == 'local' && $group->localtype == 'town') {
            $url = elgg_get_site_url() . "groups/invite/{$group->getGUID()}";
            $actions[$url] = 'groups:invite';
        }
    }
    // add a button to allow adding town groups (only for group members)
    if ($group->grouptype == 'local' && $group->localtype == 'departemental' && $group->isMember(elgg_get_logged_in_user_entity())) {
        $url = elgg_get_site_url() . "groups/local/add/{$group->getGUID()}";
        $actions[$url] = 'localgroups:addtown';
    }
    // group members (not for local groups except town group)
    if ($group->grouptype == 'local' && $group->localtype == 'town' || $group->grouptype != 'local') {
        if ($group->isMember(elgg_get_logged_in_user_entity())) {
            if ($group->getOwnerGUID() != elgg_get_logged_in_user_guid()) {
                // leave
                $url = elgg_get_site_url() . "action/groups/leave?group_guid={$group->getGUID()}";
                $url = elgg_add_action_tokens_to_url($url);
                $actions[$url] = 'groups:leave';
            }
        } elseif (elgg_is_logged_in()) {
            // join - admins can always join.
            $url = elgg_get_site_url() . "action/groups/join?group_guid={$group->getGUID()}";
            $url = elgg_add_action_tokens_to_url($url);
            if ($group->isPublicMembership() || $group->canEdit()) {
                $actions[$url] = 'groups:join';
            } else {
                // request membership
                $actions[$url] = 'groups:joinrequest';
            }
        }
    }
    if ($actions) {
        foreach ($actions as $url => $text) {
            elgg_register_menu_item('title', array('name' => $text, 'href' => $url, 'text' => elgg_echo($text), 'link_class' => 'elgg-button elgg-button-action'));
        }
    }
}
Ejemplo n.º 3
0
/**
 * Check the plugin/group setting if join motivation is needed
 *
 * @param ElggGroup $group (optional) the group to check for
 *
 * @return bool
 */
function group_tools_join_motivation_required(ElggGroup $group = null)
{
    static $plugin_settings;
    static $check_group = false;
    // load plugin settings
    if (!isset($plugin_settings)) {
        $plugin_settings = false;
        $setting = elgg_get_plugin_setting('join_motivation', 'group_tools', 'no');
        switch ($setting) {
            case 'yes_off':
                $check_group = true;
                break;
            case 'yes_on':
                $check_group = true;
                $plugin_settings = true;
                break;
            case 'required':
                $plugin_settings = true;
                break;
        }
    }
    // do we need to check the group settings?
    if (!$group instanceof ElggGroup || !$check_group) {
        return $plugin_settings || $check_group;
    }
    if ($group->isPublicMembership()) {
        // open group, no motivation needed
        return false;
    }
    // get group setting
    $group_setting = $group->getPrivateSetting('join_motivation');
    switch ($group_setting) {
        case 'no':
            return false;
            break;
        case 'yes':
            return true;
            break;
    }
    return $plugin_settings;
}