Example #1
0
function add_annotation_feedback_form_submit(Pieform $form, $values)
{
    global $USER;
    $data = (object) array('title' => get_string('Annotation', 'artefact.annotation'), 'description' => $values['message'], 'onannotation' => $values['annotationid']);
    // hidden fields.
    $artefactid = $values['artefactid'];
    $viewid = $values['viewid'];
    $blockid = $values['blockid'];
    if ($artefactid) {
        $artefact = artefact_instance_from_id($artefactid);
        $data->artefact = $artefactid;
        $data->owner = $artefact->get('owner');
        $data->group = $artefact->get('group');
        $data->institution = $artefact->get('institution');
    } else {
        if ($viewid) {
            $view = new View($viewid);
            $data->view = $viewid;
            $data->owner = $view->get('owner');
            $data->group = $view->get('group');
            $data->institution = $view->get('institution');
        }
    }
    if ($author = $USER->get('id')) {
        $anonymous = false;
        $data->author = $author;
    } else {
        $anonymous = true;
        $data->authorname = $values['authorname'];
    }
    if (isset($values['moderate']) && $values['ispublic'] && !$USER->can_edit_view($view)) {
        $data->private = 1;
        $data->requestpublic = 'author';
        $moderated = true;
    } else {
        $data->private = (int) (!$values['ispublic']);
        $moderated = false;
    }
    $private = $data->private;
    $annotationfeedback = new ArtefactTypeAnnotationfeedback(0, $data);
    $annotation = new ArtefactTypeAnnotation($values['annotationid']);
    db_begin();
    $annotationfeedback->commit();
    $url = $annotation->get_view_url($view->get('id'), true, false);
    $goto = get_config('wwwroot') . $url;
    if (isset($data->requestpublic) && $data->requestpublic === 'author' && $data->owner) {
        $arg = $author ? display_name($USER, null, true) : $data->authorname;
        $moderatemsg = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'makepublicrequestsubject', 'section' => 'artefact.annotation', 'args' => array()), 'message' => (object) array('key' => 'makepublicrequestbyauthormessage', 'section' => 'artefact.annotation', 'args' => array(hsc($arg))), 'urltext' => (object) array('key' => 'Annotation', 'section' => 'artefact.annotation')), 'users' => array($data->owner), 'url' => $url);
    }
    require_once 'activity.php';
    $data = (object) array('annotationfeedbackid' => $annotationfeedback->get('id'), 'annotationid' => $values['annotationid'], 'viewid' => $viewid, 'artefactid' => $artefactid);
    activity_occurred('annotationfeedback', $data, 'artefact', 'annotation');
    if (isset($moderatemsg)) {
        activity_occurred('maharamessage', $moderatemsg);
    }
    db_commit();
    if (param_exists('offset')) {
        $options = ArtefactTypeAnnotationfeedback::get_annotation_feedback_options();
        $options->showcomment = 'last';
        $options->artefact = $artefactid;
        $options->view = $viewid;
        $options->annotation = $values['annotationid'];
        $options->block = $blockid;
        $newlist = ArtefactTypeAnnotationfeedback::get_annotation_feedback($options);
    } else {
        $newlist = null;
    }
    // If you're anonymous and your message is moderated or private, then you won't
    // be able to tell what happened to it. So we'll provide some more explanation in
    // the feedback message.
    if ($anonymous && $moderated) {
        $message = get_string('annotationfeedbacksubmittedmoderatedanon', 'artefact.annotation');
    } else {
        if ($anonymous && $private) {
            $message = get_string('annotationfeedbacksubmittedprivateanon', 'artefact.annotation');
        } else {
            $message = get_string('annotationfeedbacksubmitted', 'artefact.annotation');
        }
    }
    $form->reply(PIEFORM_OK, array('message' => $message, 'goto' => $goto, 'data' => $newlist));
}
Example #2
0
 /**
  * Create an annotationfeedback record in the database for the feedback entry.
  */
 private static function create_annotationfeedback($entry, $importer, $annotationid)
 {
     $config = self::get_annotationfeedback_entry_data($entry, $importer, $annotationid);
     $content = $config['content'];
     $annotationfeedback = new ArtefactTypeAnnotationfeedback();
     $annotationfeedback->set('title', $content['title']);
     $annotationfeedback->set('description', $content['description']);
     if ($content['ctime']) {
         $annotationfeedback->set('ctime', $content['ctime']);
     }
     if ($content['mtime']) {
         $annotationfeedback->set('mtime', $content['mtime']);
     }
     $annotationfeedback->set('owner', $config['owner']);
     if ($content['authorname']) {
         $annotationfeedback->set('authorname', $content['authorname']);
     } else {
         $annotationfeedback->set('author', $content['author']);
     }
     $annotationfeedback->set('private', $content['private']);
     $annotationfeedback->set('onannotation', $annotationid);
     $annotationfeedback->commit();
     // return the newly created artefactid for the feedback.
     return $annotationfeedback->get('id');
 }