Example #1
0
function delete_annotation_feedback_submit(Pieform $form, $values)
{
    global $USER;
    $annotationfeedback = new ArtefactTypeAnnotationfeedback((int) $values['annotationfeedbackid']);
    $view = new View($values['viewid']);
    $annotationid = $annotationfeedback->get('onannotation');
    $annotation = new ArtefactTypeAnnotation((int) $annotationid);
    if ($USER->get('id') == $annotationfeedback->get('author')) {
        $deletedby = 'author';
    } else {
        if ($USER->can_edit_view($view)) {
            $deletedby = 'owner';
        } else {
            if ($USER->get('admin')) {
                $deletedby = 'admin';
            }
        }
    }
    $viewid = $view->get('id');
    if ($artefactid = $annotation->get('artefact')) {
        $url = 'artefact/artefact.php?view=' . $viewid . '&artefact=' . $artefactid;
    } else {
        $url = $view->get_url(false);
    }
    db_begin();
    $annotationfeedback->set('deletedby', $deletedby);
    $annotationfeedback->commit();
    if ($deletedby != 'author') {
        // Notify author
        if ($artefactid) {
            $title = get_field('artefact', 'title', 'id', $artefactid);
        } else {
            $title = get_field('view', 'title', 'id', $viewid);
        }
        $title = hsc($title);
        $data = (object) array('subject' => false, 'message' => false, 'strings' => (object) array('subject' => (object) array('key' => 'annotationfeedbackdeletednotificationsubject', 'section' => 'artefact.annotation', 'args' => array($title)), 'message' => (object) array('key' => 'annotationfeedbackdeletedauthornotification', 'section' => 'artefact.annotation', 'args' => array($title, html2text($annotationfeedback->get('description')))), 'urltext' => (object) array('key' => $artefactid ? 'artefact' : 'view')), 'users' => array($annotationfeedback->get('author')), 'url' => $url);
        activity_occurred('maharamessage', $data);
    }
    if ($deletedby != 'owner' && $annotationfeedback->get('owner') != $USER->get('id')) {
        // Notify owner
        $data = (object) array('annotationfeedbackid' => $annotationfeedback->get('id'), 'annotationid' => $annotationid, 'viewid' => $viewid, 'artefactid' => $artefactid);
        activity_occurred('annotationfeedback', $data, 'artefact', 'annotation');
    }
    db_commit();
    if (param_exists('offset')) {
        $options = ArtefactTypeAnnotationfeedback::get_annotation_feedback_options();
        $options->showcomment = $annotationfeedback->get('id');
        $options->artefact = $artefactid;
        $options->view = $viewid;
        $options->annotation = $annotationid;
        $options->block = $values['blockid'];
        $newlist = ArtefactTypeAnnotationfeedback::get_annotation_feedback($options);
    } else {
        $newlist = null;
    }
    $form->reply(PIEFORM_OK, array('message' => get_string('annotationfeedbackremoved', 'artefact.annotation'), 'goto' => get_config('wwwroot') . $url, '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');
 }