Exemple #1
0
/**
 * Make sure the provided access_id is valid for this container
 *
 * @param int $access_id      the current access_id
 * @param int $container_guid the container where the entity will be placed
 *
 * @return int
 */
function questions_validate_access_id($access_id, $container_guid)
{
    $access_id = sanitise_int($access_id);
    if ($access_id === ACCESS_DEFAULT) {
        $access_id = get_default_access();
    }
    if (empty($container_guid)) {
        return $access_id;
    }
    $container = get_entity($container_guid);
    if (empty($container)) {
        return $access_id;
    }
    if ($container instanceof ElggUser) {
        // is a default level defined in the plugin settings
        $personal_access_id = questions_get_personal_access_level();
        if ($personal_access_id !== false) {
            $access_id = $personal_access_id;
        } else {
            // make sure access_id is not a group acl
            $acl = get_access_collection($access_id);
            if (!empty($acl) && $acl->owner_guid != $container->getGUID()) {
                // this acl is a group acl, so set to something else
                $access_id = ACCESS_LOGGED_IN;
            }
        }
    } elseif ($container instanceof ElggGroup) {
        // is a default level defined in the plugin settings
        $group_access_id = questions_get_group_access_level($container);
        if ($group_access_id !== false) {
            $access_id = $group_access_id;
        } else {
            // friends access not allowed in groups
            if ($access_id === ACCESS_FRIENDS) {
                // so set it to group access
                $access_id = (int) $container->group_acl;
            }
            // check if access is an acl
            $acl = get_access_collection($access_id);
            if (!empty($acl) && $acl->owner_guid != $container->getGUID()) {
                // this acl is an acl, make sure it's the group acl
                $access_id = (int) $container->group_acl;
            }
        }
    }
    return $access_id;
}
Exemple #2
0
    $question = new ElggQuestion();
    $question->container_guid = elgg_get_page_owner_guid();
    $question->access_id = get_default_access(null, ['entity_type' => $question->getType(), 'entity_subtype' => $question->getSubtype(), 'container_guid' => $question->getContainerGUID()]);
}
$container = $question->getContainerEntity();
$title = ['name' => 'title', 'id' => 'question_title', 'value' => elgg_get_sticky_value('question', 'title', $question->title), 'required' => true];
$description = ['name' => 'description', 'id' => 'question_description', 'value' => elgg_get_sticky_value('question', 'description', $question->description)];
$tags = ['name' => 'tags', 'id' => 'question_tags', 'value' => elgg_get_sticky_value('question', 'tags', $question->tags)];
$comment_options = ['name' => 'comments_enabled', 'id' => 'questions-comments', 'value' => elgg_get_sticky_value('question', 'comments_enabled', $question->comments_enabled), 'options_values' => ['on' => elgg_echo('on'), 'off' => elgg_echo('off')], 'class' => 'mls'];
if ($container instanceof ElggUser) {
    $access_setting = questions_get_personal_access_level();
    if ($access_setting !== false) {
        $show_access_options = false;
    }
} elseif ($container instanceof ElggGroup) {
    $access_setting = questions_get_group_access_level($container);
    if ($access_setting !== false) {
        $show_access_options = false;
    }
}
$access_id = ['name' => 'access_id', 'id' => 'question_access_id', 'value' => (int) elgg_get_sticky_value('question', 'access_id', $question->access_id)];
// clear sticky form
elgg_clear_sticky_form('question');
?>
<div>
	<label for='question_title'><?php 
echo elgg_echo('questions:edit:question:title');
?>
</label>
	<?php 
echo elgg_view('input/text', $title);