<?php /** * Add question page * * @package ElggQuestions */ $title = elgg_echo("questions:add"); elgg_push_breadcrumb($title); $form_vars = array(); if (questions_limited_to_groups()) { $form_vars["class"] = "questions-validate-container"; } $content = elgg_view_form("object/question/save", $form_vars); $body = elgg_view_layout("content", array("title" => $title, "content" => $content, "filter" => "")); echo elgg_view_page($title, $body);
if ($editing && !$question->canEdit()) { register_error(elgg_echo('InvalidParameterException:NoEntityFound')); forward(REFERER); } $container_guid = (int) get_input('container_guid'); if (empty($container_guid)) { $container_guid = (int) $question->owner_guid; } if ($editing && $container_guid != $question->getContainerGUID()) { $moving = true; } if ($adding && !can_write_to_container(0, $container_guid, 'object', 'question')) { register_error(elgg_echo('questions:action:question:save:error:container')); forward(REFERER); } if (questions_limited_to_groups() && $container_guid == $question->owner_guid) { register_error(elgg_echo('questions:action:question:save:error:limited_to_groups')); forward(REFERER); } $title = get_input('title'); $description = get_input('description'); $tags = string_to_tag_array(get_input('tags', '')); $access_id = (int) get_input('access_id'); if (empty($container_guid) || empty($title) || empty($description)) { register_error(elgg_echo('questions:action:question:save:error:body', array($container_guid, $title, $description))); forward(REFERER); } // make sure we have a valid access_id $access_id = questions_validate_access_id($access_id, $container_guid); $question->title = $title; $question->description = $description;
/** * Check if a user can ask a question in a container * * @param ElggEntity $container the container to check (default: page_owner) * @param ElggUser $user the user askting the question (default: current user) * * @return bool */ function questions_can_ask_question(ElggEntity $container = null, ElggUser $user = null) { // default to page owner if (!$container instanceof ElggEntity) { $container = elgg_get_page_owner_entity(); } // default to current user if (!$user instanceof ElggUser) { $user = elgg_get_logged_in_user_entity(); } if (empty($user)) { // not logged in return false; } if (!$container instanceof ElggGroup) { // personal questions return !questions_limited_to_groups(); } if ($container->questions_enable !== 'yes') { // group option not enabled return false; } if (!questions_experts_enabled() || $container->getPrivateSetting('questions_who_can_ask') !== 'experts') { // no experts enabled, or not limited to experts return $container->canWriteToContainer($user->getGUID(), 'object', ElggQuestion::SUBTYPE); } if (!questions_is_expert($container, $user)) { // limited to expert, and user isn't one return false; } return $container->canWriteToContainer($user->getGUID(), 'object', ElggQuestion::SUBTYPE); }
register_error(elgg_echo('actionunauthorized')); forward(REFERER); } $container_guid = (int) get_input('container_guid'); if (empty($container_guid)) { $container_guid = (int) $question->getOwnerGUID(); } if ($editing && $container_guid != $question->getContainerGUID()) { $moving = true; } $container = get_entity($container_guid); if ($adding && !questions_can_ask_question($container)) { register_error(elgg_echo('questions:action:question:save:error:container')); forward(REFERER); } if (questions_limited_to_groups() && $container_guid == $question->getOwnerGUID()) { register_error(elgg_echo('questions:action:question:save:error:limited_to_groups')); forward(REFERER); } $title = get_input('title'); $description = get_input('description'); $tags = string_to_tag_array(get_input('tags', '')); $access_id = (int) get_input('access_id'); $comments_enabled = get_input('comments_enabled'); if (empty($container_guid) || empty($title)) { register_error(elgg_echo('questions:action:question:save:error:body', [$container_guid, $title])); forward(REFERER); } // make sure we have a valid access_id $access_id = questions_validate_access_id($access_id, $container_guid); $question->title = $title;