Exemplo n.º 1
0
<?php

$question = elgg_extract('entity', $vars);
$show_group_selector = (bool) elgg_extract('show_group_selector', $vars, true);
$editing = true;
$container_options = false;
$show_access_options = true;
$access_setting = false;
if (!$question) {
    $editing = false;
    $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)];
Exemplo n.º 2
0
/**
 * Notify the experts that a new question was asked
 *
 * @param ElggQuestion $entity the question to notify about
 * @param bool         $moving is this question being moved
 *
 * @return void
 */
function questions_notify_experts(ElggQuestion $entity, $moving = false)
{
    // only if experts enabled
    if (!questions_experts_enabled()) {
        return;
    }
    // validate input
    if (!$entity instanceof ElggQuestion) {
        return;
    }
    $experts = [];
    $container = $entity->getContainerEntity();
    if (!$container instanceof ElggGroup) {
        $container = elgg_get_site_entity();
    }
    // get experts
    $options = ['type' => 'user', 'site_guids' => false, 'limit' => false, 'relationship' => QUESTIONS_EXPERT_ROLE, 'relationship_guid' => $container->getGUID(), 'inverse_relationship' => true];
    $users = elgg_get_entities_from_relationship($options);
    if (!empty($users)) {
        $experts = $users;
    }
    // trigger a hook so others can extend the list
    $params = ['entity' => $entity, 'experts' => $experts, 'moving' => $moving];
    $experts = elgg_trigger_plugin_hook('notify_experts', 'questions', $params, $experts);
    if (empty($experts) || !is_array($experts)) {
        return;
    }
    $subject_key = 'questions:notify_experts:create:subject';
    $message_key = 'questions:notify_experts:create:message';
    if ($moving) {
        $subject_key = 'questions:notify_experts:moving:subject';
        $message_key = 'questions:notify_experts:moving:message';
    }
    $subject = elgg_echo($subject_key);
    foreach ($experts as $expert) {
        if (!$expert instanceof ElggUser) {
            continue;
        }
        $message = elgg_echo($message_key, [$expert->name, $entity->title, $entity->getURL()]);
        notify_user($expert->getGUID(), $entity->getOwnerGUID(), $subject, $message, null, 'email');
    }
}
Exemplo n.º 3
0
/**
 * Check if a user can answer a question
 *
 * @param ElggQuestion $question the question that needs answer
 * @param ElggUser     $user     the user askting the question (default: current user)
 *
 * @return bool
 */
function questions_can_answer_question(ElggQuestion $question, ElggUser $user = null)
{
    static $general_experts_only;
    // default to page owner
    if (!$question instanceof ElggQuestion) {
        return false;
    }
    // default to current user
    if (!$user instanceof ElggUser) {
        $user = elgg_get_logged_in_user_entity();
    }
    if (empty($user)) {
        // not logged in
        return false;
    }
    $container = $question->getContainerEntity();
    if (!questions_experts_enabled()) {
        return questions_can_ask_question($container, $user);
    }
    // get plugin setting
    if (!isset($general_experts_only)) {
        $general_experts_only = questions_experts_only_answer();
    }
    $is_expert = questions_is_expert($container, $user);
    // check general setting
    if ($general_experts_only && !$is_expert) {
        return false;
    }
    if (!$container instanceof ElggGroup) {
        return true;
    }
    // check group settings
    $group_experts_only = false;
    if ($container->getPrivateSetting('questions_who_can_answer') === 'experts') {
        $group_experts_only = true;
    }
    if ($group_experts_only && !$is_expert) {
        return false;
    }
    // are you a group member or can you edit the group
    return $container->isMember($user) || $container->canEdit($user->getGUID());
}