Example #1
0
 /**
  * Return the widget title url
  *
  * @param string $hook         the name of the hook
  * @param string $type         the type of the hook
  * @param string $return_value current return value
  * @param array  $params       supplied params
  *
  * @return void|string
  */
 public static function widgetURL($hook, $type, $return_value, $params)
 {
     if (!empty($return_value)) {
         // already set
         return;
     }
     $entity = elgg_extract('entity', $params);
     if (!$entity instanceof \ElggWidget) {
         return;
     }
     if ($entity->handler !== 'questions') {
         return;
     }
     $owner = $entity->getOwnerEntity();
     if ($owner instanceof \ElggUser) {
         // user
         $return_value = "questions/owner/{$owner->username}";
         if ($entity->context === 'dashboard') {
             switch ($entity->content_type) {
                 case 'all':
                     $return_value = 'questions/all';
                     break;
                 case 'todo':
                     if (questions_is_expert()) {
                         $return_value = 'questions/todo';
                     }
                     break;
             }
         }
     } elseif ($owner instanceof \ElggGroup) {
         // group
         $return_value = "questions/group/{$owner->getGUID()}/all";
     } elseif ($owner instanceof \ElggSite) {
         // site
         $return_value = 'questions/all';
     }
     return $return_value;
 }
Example #2
0
/**
 * Checks if a question can be moved to the discussion in the container.
 *
 * @param ElggEntity $container the container where the question should become a discussion
 * @param ElggUser   $user      the user trying to move the question, defaults to current user
 *
 * @return bool
 */
function questions_can_move_to_discussions(ElggEntity $container, ElggUser $user = null)
{
    // make sure we have a user
    if (!$user instanceof ElggUser) {
        $user = elgg_get_logged_in_user_entity();
    }
    if (empty($user)) {
        return false;
    }
    // only if container is a group
    if (!$container instanceof ElggGroup) {
        return false;
    }
    // only experts can move
    if (!questions_is_expert($container, $user)) {
        return false;
    }
    // are discussions enabled
    if ($container->forum_enable === 'no') {
        return false;
    }
    return true;
}
Example #3
0
<?php

/**
 * Questions widget settings
 */
$widget = elgg_extract('entity', $vars);
$limit = (int) $widget->limit;
if ($limit < 1) {
    $limit = 5;
}
if ($widget->context === 'dashboard') {
    $content_type_options = ['mine' => elgg_echo('mine'), 'all' => elgg_echo('all')];
    if (questions_is_expert()) {
        $content_type_options['todo'] = elgg_echo('questions:todo');
    }
    echo '<div>';
    echo elgg_echo('widget:questions:content_type');
    echo elgg_view('input/select', ['name' => 'params[content_type]', 'value' => $widget->content_type, 'options_values' => $content_type_options, 'class' => 'mls']);
    echo '</div>';
}
echo '<div>';
echo elgg_echo('widget:numbertodisplay');
echo elgg_view('input/text', ['name' => 'params[limit]', 'value' => $limit]);
echo '</div>';
Example #4
0
}
// comments
$comments = elgg_format_element('label', ['for' => 'questions-comments'], elgg_echo('comments'));
$comments .= elgg_view('input/select', $comment_options);
echo elgg_format_element('div', [], $comments);
// access options
if ($show_access_options) {
    $access = elgg_format_element('label', ['for' => 'question_access_id'], elgg_echo('access'));
    $access .= '<br />';
    $access .= elgg_view('input/access', $access_id);
    echo elgg_format_element('div', [], $access);
} else {
    echo elgg_view('input/hidden', ['name' => 'access_id', 'value' => $access_setting]);
}
// container selection options
if (!$editing || questions_experts_enabled() && questions_is_expert(elgg_get_page_owner_entity())) {
    if ($show_group_selector && elgg_is_active_plugin('groups')) {
        $group_options = ['type' => 'group', 'limit' => false, 'metadata_name_value_pairs' => ['name' => 'questions_enable', 'value' => 'yes'], 'joins' => ['JOIN ' . elgg_get_config('dbprefix') . 'groups_entity ge ON e.guid = ge.guid'], 'order_by' => 'ge.name ASC'];
        if (!$editing) {
            $owner = elgg_get_logged_in_user_entity();
            $group_options['relationship'] = 'member';
            $group_options['relationship_guid'] = elgg_get_logged_in_user_guid();
        } else {
            $owner = $question->getOwnerEntity();
        }
        // group selector
        $groups = new ElggBatch('elgg_get_entities_from_relationship', $group_options);
        // build group optgroup
        $group_optgroup = [];
        foreach ($groups as $group) {
            // can questions be asked in this group
Example #5
0
/**
 * Elgg questions todo page
 *
 * @package ElggQuestions
 */
gatekeeper();
if (!questions_is_expert()) {
    forward("questions/all");
}
// check for a group filter
$group_guid = (int) get_input("group_guid");
if (!empty($group_guid)) {
    $group = get_entity($group_guid);
    if (!empty($group) && elgg_instanceof($group, "group")) {
        // make sure the user is an expert of this group
        if (!questions_is_expert($group)) {
            forward("questions/all");
        }
        $page_owner = $group;
        elgg_push_breadcrumb($group->name, "questions/group/" . $group->getGUID() . "/all");
    }
}
if (empty($page_owner)) {
    $page_owner = elgg_get_logged_in_user_entity();
}
// set page owner and add breadcrumb
elgg_set_page_owner_guid($page_owner->getGUID());
elgg_push_breadcrumb(elgg_echo("questions:todo"));
// add title button
elgg_register_title_button();
// prepare options
Example #6
0
/**
 * Automaticly mark an answer as the correct answer, when created by an expert
 *
 * NOTE: for now this is only supported in groups
 *
 * @param ElggEntity $container the container of the questions (group or user)
 * @param ElggUser   $user      the user doing the action (default: current user)
 *
 * @return bool
 */
function questions_auto_mark_answer_correct(ElggEntity $container, ElggUser $user = null)
{
    if (!$container instanceof ElggGroup) {
        // for now only supported in groups
        return false;
    }
    if (!$user instanceof ElggUser) {
        $user = elgg_get_logged_in_user_entity();
    }
    if (!$user instanceof ElggUser) {
        return false;
    }
    if (!questions_experts_enabled()) {
        // only applies to experts
        return false;
    }
    if (!questions_is_expert($container, $user)) {
        // not an expert
        return false;
    }
    // check group setting
    $group_setting = $container->getPrivateSetting('questions_auto_mark_correct');
    return $group_setting === 'yes';
}
Example #7
0
/**
 * Return the widget title url
 *
 * @param string $hook        the name of the hook
 * @param string $type        the type of the hook
 * @param string $returnvalue current return value
 * @param array  $params      supplied params
 *
 * @return void|string
 */
function questions_widget_url_handler($hook, $type, $returnvalue, $params)
{
    if (!empty($returnvalue)) {
        // someone already set an url
        return;
    }
    if (empty($params) || !is_array($params)) {
        return;
    }
    $widget = elgg_extract('entity', $params);
    if (!$widget instanceof ElggWidget) {
        return;
    }
    // only handle questions widget
    if ($widget->handler !== 'questions') {
        return;
    }
    // who owns the widget
    $owner = $widget->getOwnerEntity();
    if ($owner instanceof ElggUser) {
        // user
        $returnvalue = "questions/owner/{$owner->username}";
        if ($widget->context === 'dashboard') {
            switch ($widget->content_type) {
                case 'all':
                    $returnvalue = 'questions/all';
                    break;
                case 'todo':
                    if (questions_is_expert()) {
                        $returnvalue = 'questions/todo';
                    }
                    break;
            }
        }
    } elseif ($owner instanceof ElggGroup) {
        // group
        $returnvalue = "questions/group/{$owner->getGUID()}/all";
    } elseif ($owner instanceof ElggSite) {
        // site
        $returnvalue = 'questions/all';
    }
    return $returnvalue;
}
Example #8
0
<?php 
// categories support
if (elgg_view_exists("input/categories")) {
    echo elgg_view("input/categories", $vars);
}
// access options
if ($show_access_options) {
    echo "<div>";
    echo "<label for='question_access_id'>" . elgg_echo("access") . "</label><br />";
    echo elgg_view('input/access', $access_id);
    echo "</div>";
} else {
    echo elgg_view("input/hidden", array("name" => "access_id", "value" => $access_setting));
}
// container selection options
if (!$editing || questions_experts_enabled() && questions_is_expert()) {
    if (!$editing) {
        $owner = elgg_get_logged_in_user_entity();
    } else {
        $owner = $question->getOwnerEntity();
    }
    $container_options = true;
    $select = "<select name='container_guid' class='elgg-input-dropdown' id='questions-container-guid'>";
    // add user to the list
    $selected = "";
    if ($owner->getGUID() == $question->getContainerGUID()) {
        $selected = "selected='selected'";
    }
    if (!questions_limited_to_groups()) {
        $select .= "<option value='" . $owner->getGUID() . "' " . $selected . ">" . $owner->name . "</option>";
    } else {
Example #9
0
$widget = elgg_extract('entity', $vars);
$limit = (int) $widget->limit;
if ($limit < 1) {
    $limit = 5;
}
$options = ['type' => 'object', 'subtype' => 'question', 'limit' => $limit, 'full_view' => false, 'pagination' => false];
$base_url = 'questions/all';
switch ($widget->context) {
    case 'profile':
        $base_url = "questions/owner/{$widget->getOwnerEntity()->username}";
        $options['owner_guid'] = $widget->getOwnerGUID();
        break;
    case 'dashboard':
        $base_url = "questions/owner/{$widget->getOwnerEntity()->username}";
        $type = $widget->content_type;
        if ($type == 'todo' && !questions_is_expert()) {
            $type = 'mine';
        }
        // user shows owned
        switch ($type) {
            case 'todo':
                $base_url = 'questions/todo';
                // prepare options
                $dbprefix = elgg_get_config('dbprefix');
                $correct_answer_id = elgg_get_metastring_id('correct_answer');
                $site = elgg_get_site_entity();
                $user = elgg_get_logged_in_user_entity();
                $container_where = [];
                $options['wheres'] = ["NOT EXISTS (\n\t\t\t\t\tSELECT 1\n\t\t\t\t\tFROM {$dbprefix}entities e2\n\t\t\t\t\tJOIN {$dbprefix}metadata md ON e2.guid = md.entity_guid\n\t\t\t\t\tWHERE e2.container_guid = e.guid\n\t\t\t\t\tAND md.name_id = {$correct_answer_id})"];
                $options['order_by_metadata'] = ['name' => 'solution_time'];
                if (check_entity_relationship($user->getGUID(), QUESTIONS_EXPERT_ROLE, $site->getGUID())) {
Example #10
0
$limit = (int) $widget->limit;
if ($limit < 1) {
    $limit = 5;
}
if ($limit > 20) {
    $limit = 20;
}
$options = array("type" => "object", "subtype" => "question", "limit" => $limit, "full_view" => false, "pagination" => false);
$getter = "elgg_get_entities";
switch ($widget->context) {
    case "profile":
        $options["owner_guid"] = $widget->getOwnerGUID();
        break;
    case "dashboard":
        $type = $widget->content_type;
        if ($type == "todo" && !questions_is_expert()) {
            $type = "mine";
        }
        // user shows owned
        switch ($type) {
            case "todo":
                $getter = "elgg_get_entities_from_metadata";
                // prepare options
                $dbprefix = elgg_get_config("dbprefix");
                $correct_answer_id = add_metastring("correct_answer");
                $site = elgg_get_site_entity();
                $user = elgg_get_logged_in_user_entity();
                $container_where = array();
                $options["wheres"] = array("NOT EXISTS (\n\t\t\t\t\t\t\tSELECT 1\n\t\t\t\t\t\t\tFROM " . $dbprefix . "entities e2\n\t\t\t\t\t\t\tJOIN " . $dbprefix . "metadata md ON e2.guid = md.entity_guid\n\t\t\t\t\t\t\tWHERE e2.container_guid = e.guid\n\t\t\t\t\t\t\tAND md.name_id = " . $correct_answer_id . ")");
                $options["order_by_metadata"] = array("name" => "solution_time");
                if (check_entity_relationship($user->getGUID(), QUESTIONS_EXPERT_ROLE, $site->getGUID())) {
Example #11
0
/**
 * Check if a user has permissions
 *
 * @param string $hook        the name of the hook
 * @param string $type        the type of the hook
 * @param bool   $returnvalue current return value
 * @param array  $params      supplied params
 *
 * @return void|bool
 */
function questions_permissions_handler($hook, $type, $returnvalue, $params)
{
    if (empty($params) || !is_array($params)) {
        return;
    }
    // get the provided data
    $entity = elgg_extract('entity', $params);
    $user = elgg_extract('user', $params);
    if (!$user instanceof ElggUser) {
        return;
    }
    if (!$entity instanceof ElggQuestion && !$entity instanceof ElggAnswer) {
        return;
    }
    // expert only changes
    if (questions_experts_enabled()) {
        // check if an expert can edit a question
        if (!$returnvalue && $entity instanceof ElggQuestion) {
            $container = $entity->getContainerEntity();
            if (!$container instanceof ElggGroup) {
                $container = elgg_get_site_entity();
            }
            if (questions_is_expert($container, $user)) {
                $returnvalue = true;
            }
        }
        // an expert should be able to edit an answer, so fix this
        if (!$returnvalue && $entity instanceof ElggAnswer) {
            // user is not the owner
            if ($entity->getOwnerGUID() !== $user->getGUID()) {
                $question = $entity->getContainerEntity();
                if ($question instanceof ElggQuestion) {
                    $container = $question->getContainerEntity();
                    if (!$container instanceof ElggGroup) {
                        $container = elgg_get_site_entity();
                    }
                    // if the user is an expert
                    if (questions_is_expert($container, $user)) {
                        $returnvalue = true;
                    }
                }
            }
        }
    }
    // questions can't be editted by owner if it is closed
    if ($returnvalue && $entity instanceof ElggQuestion) {
        // is the question closed
        if ($entity->getStatus() === 'closed') {
            // are you the owner
            if ($user->getGUID() === $entity->getOwnerGUID()) {
                $returnvalue = false;
            }
        }
    }
    return $returnvalue;
}
Example #12
0
/**
 * Checks if a question can be moved to the discussion in the container.
 *
 * @param ElggEntity $container the container where the question should become a discussion
 * @param ElggUser $user the user trying to move the question, defaults to current user
 *
 * @return bool true is can move, false otherwise
 */
function questions_can_move_to_discussions(ElggEntity $container, ElggUser $user = null)
{
    $result = false;
    // make sure we have a user
    if (empty($user) || !elgg_instanceof($user, "user")) {
        $user = elgg_get_logged_in_user_entity();
    }
    // only if container is a group
    if (!empty($container) && elgg_instanceof($container, "group") && !empty($user)) {
        // only experts can move
        if (questions_is_expert($container, $user)) {
            // are discussions enabled
            if ($container->forum_enable != "no") {
                $result = true;
            }
        }
    }
    return $result;
}
Example #13
0
// build page elements
$title_icon = "";
$content = elgg_view_entity($question, array('full_view' => true));
// add the rest of the answers
$options = array('type' => 'object', 'subtype' => 'answer', 'container_guid' => $question->guid, 'count' => true, 'limit' => false, 'order_by' => 'e.time_created', 'pagination' => false);
if (elgg_is_active_plugin("likes")) {
    // order answers based on likes
    $dbprefix = elgg_get_config("dbprefix");
    $likes_id = add_metastring("likes");
    $options["selects"] = array("(SELECT count(a.name_id) AS likes_count\n\t\tFROM " . $dbprefix . "annotations a\n\t\tWHERE a.entity_guid = e.guid\n\t\tAND a.name_id = " . $likes_id . ") AS likes_count");
}
$answers = elgg_list_entities($options);
$count = elgg_get_entities($options);
$answer_title = elgg_view_icon("comment-o", "mrs") . $count . " " . elgg_echo('answers');
$content .= elgg_view_module('info', $answer_title, $answers, array("class" => "mtm ffd-answers"));
// add answer form
if ($question->getStatus() == "open" && $question->canWriteToContainer(0, 'object', 'answer')) {
    $add_form = elgg_view_form('object/answer/add', array(), array('container_guid' => $question->guid));
    $content .= elgg_view_module('info', elgg_echo('answers:addyours'), $add_form, array('id' => 'questions-answer-add'));
} elseif ($question->getStatus() == "closed") {
    // add an icon to show this question is closed
    $title_icon = elgg_view_icon("lock-closed");
}
// switch to go from frontend to backend
if (questions_workflow_enabled() && questions_is_expert()) {
    $overview = elgg_view('questions/overview', array('question' => $question));
} else {
    $overview = "";
}
$body = elgg_view_layout('content', array('content' => $overview . $content, 'filter' => ''));
echo elgg_view_page($title, $body);
Example #14
0
		<?php 
    echo elgg_view("input/access", $access_id);
    ?>
	</div>
<?php 
} else {
    ?>
	<?php 
    echo elgg_view("input/hidden", array("name" => "access_id", "value" => $access_setting));
}
?>

<?php 
// container selection options
$featured_groups = rijkshuisstijl_get_featured_groups();
if ($featured_groups && (!$editing || questions_experts_enabled() && questions_is_expert())) {
    if (!$editing) {
        $owner = elgg_get_logged_in_user_entity();
    } else {
        $owner = $question->getOwnerEntity();
    }
    $container_options = array();
    if (!questions_limited_to_groups()) {
        $container_options[$owner->guid] = $owner->name;
    }
    foreach ($featured_groups as $group) {
        $container_options[$group->guid] = $group->name;
    }
    ?>

	<div class="rhs-form__element">
Example #15
0
function questions_widget_url_handler($hook, $type, $returnvalue, $params)
{
    $result = $returnvalue;
    if (!$result && !empty($params) && is_array($params)) {
        $widget = elgg_extract("entity", $params);
        if (!empty($widget) && elgg_instanceof($widget, "object", "widget")) {
            // only handle questions widget
            if ($widget->handler == "questions") {
                // who owns the widget
                $owner = $widget->getOwnerEntity();
                if (elgg_instanceof($owner, "user")) {
                    // user
                    $result = "questions/owner/" . $owner->username;
                    if ($widget->context == "dashboard") {
                        switch ($widget->content_type) {
                            case "all":
                                $result = "questions/all";
                                break;
                            case "todo":
                                if (questions_is_expert()) {
                                    $result = "questions/todo";
                                    break;
                                }
                            case "mine":
                            default:
                                $result = "questions/owner/" . $owner->username;
                        }
                    }
                } elseif (elgg_instanceof($owner, "group")) {
                    // group
                    $result = "questions/group/" . $owner->getGUID() . "/all";
                } elseif (elgg_instanceof($owner, "site")) {
                    // site
                    $result = "questions/all";
                }
            }
        }
    }
    return $result;
}