Example #1
0
 /**
  * Fetching the annotations for an artefact to display on a view
  *
  * @param   object  $annotationartefact  The annotation artefact to display feedbacks for.
  * @param   object  $view     The view on which the annotation artefact is linked to.
  * @param   int     $blockid  The id of the block instance that connects the artefact to the view
  * @param   int     @annotationscountonview The number annotations alread on the view. If one is already
  *                            on there, don't add the add_annotation_feedback_form as it's already been
  *                            created.
  * @param   bool    $html     Whether to return the information rendered as html or not
  * @param   bool    $editing  Whether we are view edit mode or not
  */
 public function get_annotation_feedback_for_view($annotationartefact, $view, $blockid, $html = true, $editing = false)
 {
     global $USER;
     if (!is_object($annotationartefact) || !is_object($view)) {
         throw new MaharaException(get_string('annotationinformationerror', 'artefact.annotation'));
     }
     // If there is annotation feedback, retrieve it so it can be displayed -
     // even if no annotation feedback is turned on.
     $options = ArtefactTypeAnnotationfeedback::get_annotation_feedback_options();
     // Don't paginate when the annotation is on a view.  It gets mixed up
     // with the pagination of feedback on a view.
     $options->limit = 0;
     $options->view = $view->get('id');
     $options->annotation = $annotationartefact->get('id');
     $options->block = $blockid;
     $annotationfeedback = ArtefactTypeAnnotationfeedback::get_annotation_feedback($options);
     $annotationfeedbackcount = isset($annotationfeedback->count) ? $annotationfeedback->count : 0;
     if ($html) {
         // Return the rendered form.
         $smarty = smarty_core();
         if ($annotationartefact->get('allowcomments') && !$editing) {
             $addannotationfeedbackform = pieform(ArtefactTypeAnnotationfeedback::add_annotation_feedback_form(false, $annotationartefact->get('approvecomments'), $annotationartefact, $view, null, $blockid));
             $smarty->assign('addannotationfeedbackform', $addannotationfeedbackform);
         } else {
             // The user has switched off annotation feedback. Don't create the add annotation feedback form.
             $smarty->assign('addannotationfeedbackform', null);
         }
         $smarty->assign('blockid', $blockid);
         $smarty->assign('annotationfeedbackcount', $annotationfeedbackcount);
         $smarty->assign('annotationfeedback', $annotationfeedback);
         $smarty->assign('editing', $editing);
         $smarty->assign('allowfeedback', $USER->is_logged_in() && $annotationartefact->get('allowcomments'));
         $render = $smarty->fetch('artefact:annotation:annotationfeedbackview.tpl');
         return array($annotationfeedbackcount, $render);
     } else {
         // Return the array of raw data unrendered.
         return array($annotationfeedbackcount, $annotationfeedback);
     }
 }
Example #2
0
    $extradata->blockid = $blockid;
}
if (empty($extradata->view) || empty($extradata->annotation) || empty($extradata->blockid)) {
    json_reply('local', get_string('annotationinformationerror', 'artefact.annotation'));
}
if (!can_view_view($extradata->view)) {
    json_reply('local', get_string('noaccesstoview', 'view'));
}
if (!artefact_in_view($extradata->annotation, $extradata->view)) {
    json_reply('local', get_string('accessdenied', 'error'));
}
if (!empty($extradata->artefact) && !artefact_in_view($extradata->artefact, $extradata->view)) {
    json_reply('local', get_string('accessdenied', 'error'));
}
if ($ispagination) {
    // This is not really working yet. Need to do more work on artefact/artefact.php
    $options = ArtefactTypeAnnotationfeedback::get_annotation_feedback_options();
    $options->limit = $limit;
    $options->offset = $offset;
    $options->view = $extradata->view;
    $options->annotation = $extradata->annotation;
    $options->artefact = $extradata->artefact;
    $options->block = $extradata->blockid;
    $annotationfeedback = ArtefactTypeAnnotationfeedback::get_annotation_feedback($options);
    json_reply(false, array('data' => $annotationfeedback));
} else {
    $view = new View($extradata->view);
    $annotationartefact = artefact_instance_from_id($extradata->annotation);
    list($feedbackcount, $annotationfeedback) = ArtefactTypeAnnotationfeedback::get_annotation_feedback_for_view($annotationartefact, $view, $extradata->blockid);
    json_reply(false, array('data' => $annotationfeedback));
}