/** * 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); } }