Esempio n. 1
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');
    }
}
Esempio n. 2
0
File: save.php Progetto: remy40/gvrs
$title = get_input('title', '', false);
$description = get_input('description');
$tags = string_to_tag_array(get_input('tags', ''));
if (empty($container_guid) || empty($title) || empty($description)) {
    register_error(elgg_echo('questions:empty_fields'));
    forward(REFERER);
}
$question->title = $title;
$question->description = $description;
$question->tags = $tags;
$question->access_id = ACCESS_LOGGED_IN;
$question->container_guid = $container_guid;
try {
    $question->save();
    if ($adding) {
        add_to_river('river/object/question/create', 'create', elgg_get_logged_in_user_guid(), $question->guid, $question->access_id);
    }
} catch (Exception $e) {
    register_error(elgg_echo('questions:save_error'));
    register_error($e->getMessage());
    forward(REFERER);
}
elgg_clear_sticky_form('question');
$container = $question->getContainerEntity();
if ($container instanceof ElggUser) {
    $url = "/questions/owner/{$container->username}";
} else {
    $url = "/questions/group/{$container->guid}/all";
}
forward(get_input('forward', $adding ? $url : $question->getURL()));