Example #1
0
 /**
  * @param array $data Parameters:
  *                    - viewid (int)
  *                    - annotationid (int)
  */
 public function __construct($data, $cron = false)
 {
     parent::__construct($data, $cron);
     $annotation = new ArtefactTypeAnnotation($this->annotationid);
     $annotationfeedback = new ArtefactTypeAnnotationfeedback($this->annotationfeedbackid);
     $this->overridemessagecontents = true;
     if ($onartefact = $annotation->get('artefact')) {
         // Feedback on artefact.
         $userid = null;
         require_once get_config('docroot') . 'artefact/lib.php';
         $artefactinstance = artefact_instance_from_id($onartefact);
         if ($artefactinstance->feedback_notify_owner()) {
             $userid = $artefactinstance->get('owner');
             $groupid = $artefactinstance->get('group');
             $institutionid = $artefactinstance->get('institution');
         }
         if (empty($this->url)) {
             $this->url = 'artefact/artefact.php?artefact=' . $onartefact . '&view=' . $this->viewid;
         }
     } else {
         if ($onview = $annotation->get('view')) {
             // Feedback on view.
             if (!($viewrecord = get_record('view', 'id', $onview))) {
                 throw new ViewNotFoundException(get_string('viewnotfound', 'error', $onview));
             }
             $userid = $viewrecord->owner;
             $groupid = $viewrecord->group;
             $institutionid = $viewrecord->institution;
             if (empty($this->url)) {
                 $this->url = 'view/view.php?id=' . $onview;
             }
         } else {
             // Something is wrong.
             throw new ViewNotFoundException(get_string('invalidannotationfeedbacklinkerror', 'artefact.annotation'));
         }
     }
     // Now fetch the users that will need to get notified about this event
     // depending on whether the page has an owner, group, or institution id set.
     if (!empty($userid)) {
         $this->users = activity_get_users($this->get_id(), array($userid));
     } else {
         if (!empty($groupid)) {
             require_once get_config('docroot') . 'lib/group.php';
             $sql = "SELECT u.*\n                    FROM {usr} u, {group_member} m, {group} g\n                    WHERE g.id = m.group\n                    AND m.member = u.id\n                    AND m.group = ?\n                    AND (g.feedbacknotify = " . GROUP_ROLES_ALL . "\n                         OR (g.feedbacknotify = " . GROUP_ROLES_NONMEMBER . " AND (m.role = 'tutor' OR m.role = 'admin'))\n                         OR (g.feedbacknotify = " . GROUP_ROLES_ADMIN . " AND m.role = 'admin')\n                        )";
             $this->users = get_records_sql_array($sql, array($groupid));
         } else {
             if (!empty($institutionid)) {
                 require_once get_config('libroot') . 'institution.php';
                 $institution = new Institution($institutionid);
                 $admins = $institution->institution_and_site_admins();
                 $this->users = get_records_sql_array("SELECT * FROM {usr} WHERE id IN (" . implode(',', $admins) . ")", array());
             }
         }
     }
     if (empty($this->users)) {
         // no one to notify - possibe if group 'feedbacknotify' is set to 0
         return;
     }
     $title = $onartefact ? $artefactinstance->get('title') : $viewrecord->title;
     $this->urltext = $title;
     $body = $annotationfeedback->get('description');
     $posttime = strftime(get_string('strftimedaydatetime'), $annotationfeedback->get('ctime'));
     // Internal
     $this->message = strip_tags(str_shorten_html($body, 200, true));
     // Seen as things like emaildigest base the message on $this->message
     // we need to set the language for the $removedbyline here based on first user.
     $user = $this->users[0];
     $lang = empty($user->lang) || $user->lang == 'default' ? get_config('lang') : $user->lang;
     // Comment deleted notification
     if ($deletedby = $annotationfeedback->get('deletedby')) {
         $this->strings = (object) array('subject' => (object) array('key' => 'annotationfeedbackdeletednotificationsubject', 'section' => 'artefact.annotation', 'args' => array($title)));
         $deletedmessage = ArtefactTypeAnnotationfeedback::deleted_by_types_description();
         $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.annotation');
         $this->message = $removedbyline . ":\n" . $this->message;
         foreach ($this->users as $key => $user) {
             if (empty($user->lang) || $user->lang == 'default') {
                 // check to see if we need to show institution language
                 $instlang = get_user_institution_language($user->id);
                 $lang = empty($instlang) || $instlang == 'default' ? get_config('lang') : $instlang;
             } else {
                 $lang = $user->lang;
             }
             // For email we can send the message in the user's preferred language
             $removedbyline = get_string_from_language($lang, $deletedmessage[$deletedby], 'artefact.annotation');
             $this->users[$key]->htmlmessage = get_string_from_language($lang, 'annotationfeedbackdeletedhtml', 'artefact.annotation', hsc($title), $removedbyline, clean_html($body), get_config('wwwroot') . $this->url, hsc($title));
             $this->users[$key]->emailmessage = get_string_from_language($lang, 'annotationfeedbackdeletedtext', 'artefact.annotation', $title, $removedbyline, trim(html2text(htmlspecialchars($body))), $title, get_config('wwwroot') . $this->url);
         }
         return;
     }
     $this->strings = (object) array('subject' => (object) array('key' => 'newannotationfeedbacknotificationsubject', 'section' => 'artefact.annotation', 'args' => array($title)));
     $this->url .= '&showcomment=' . $annotationfeedback->get('id');
     // Email
     $author = $annotationfeedback->get('author');
     foreach ($this->users as $key => $user) {
         $authorname = empty($author) ? $annotationfeedback->get('authorname') : display_name($author, $user);
         if (empty($user->lang) || $user->lang == 'default') {
             // check to see if we need to show institution language
             $instlang = get_user_institution_language($user->id);
             $lang = empty($instlang) || $instlang == 'default' ? get_config('lang') : $instlang;
         } else {
             $lang = $user->lang;
         }
         $this->users[$key]->htmlmessage = get_string_from_language($lang, 'annotationfeedbacknotificationhtml', 'artefact.annotation', hsc($authorname), hsc($title), $posttime, clean_html($body), get_config('wwwroot') . $this->url);
         $this->users[$key]->emailmessage = get_string_from_language($lang, 'annotationfeedbacknotificationtext', 'artefact.annotation', $authorname, $title, $posttime, trim(html2text(htmlspecialchars($body))), get_config('wwwroot') . $this->url);
     }
 }
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));
}
Example #3
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');
 }
Example #4
0
    throw new AccessDeniedException(get_string('canteditnotauthor', 'artefact.annotation'));
}
$annotationid = $annotationfeedback->get('onannotation');
$annotation = new ArtefactTypeAnnotation($annotationid);
$onview = $annotation->get('view');
if ($onview && $onview != $viewid) {
    throw new NotFoundException(get_string('annotationfeedbacknotinview', 'artefact.annotation', $annotationfeedbackid, $viewid));
}
$maxage = (int) get_config_plugin('artefact', 'annotation', 'commenteditabletime');
$editableafter = time() - 60 * $maxage;
$goto = $annotation->get_view_url($viewid, false);
if ($annotationfeedback->get('ctime') < $editableafter) {
    $SESSION->add_error_msg(get_string('cantedittooold', 'artefact.annotation', $maxage));
    redirect($goto);
}
$lastcomment = ArtefactTypeAnnotationfeedback::last_public_annotation_feedback($annotationid, $viewid, $annotation->get('artefact'));
if (!$annotationfeedback->get('private') && $annotationfeedbackid != $lastcomment->id) {
    $SESSION->add_error_msg(get_string('cantedithasreplies', 'artefact.annotation'));
    redirect($goto);
}
$elements = array();
$elements['message'] = array('type' => 'wysiwyg', 'title' => get_string('Annotationfeedback', 'artefact.annotation'), 'rows' => 5, 'cols' => 80, 'defaultvalue' => $annotationfeedback->get('description'), 'rules' => array('maxlength' => 8192));
$elements['ispublic'] = array('type' => 'checkbox', 'title' => get_string('makepublic', 'artefact.annotation'), 'defaultvalue' => !$annotationfeedback->get('private'));
// What is this annotation feedback linked to? Store it in hidden fields.
$elements['viewid'] = array('type' => 'hidden', 'value' => $viewid);
$elements['artefactid'] = array('type' => 'hidden', 'value' => $annotation->get('artefact'));
// Save the artefactid of the annotation.
$elements['annotationid'] = array('type' => 'hidden', 'value' => $annotationid);
$elements['submit'] = array('type' => 'submitcancel', 'value' => array(get_string('save'), get_string('cancel')), 'goto' => $goto);
$form = pieform(array('name' => 'edit_annotation_feedback', 'method' => 'post', 'plugintype' => 'artefact', 'pluginname' => 'annotation', 'elements' => $elements));
function edit_annotation_feedback_validate(Pieform $form, $values)
Example #5
0
 public static function instance_config_form(BlockInstance $instance)
 {
     global $USER;
     $instance->set('artefactplugin', 'annotation');
     // Get the saved configs in the artefact
     $configdata = $instance->get('configdata');
     if (!($height = get_config('blockeditorheight'))) {
         $cfheight = param_integer('cfheight', 0);
         $height = $cfheight ? $cfheight * 0.7 : 150;
     }
     // Default annotation text.
     $text = '';
     $tags = '';
     $artefactid = '';
     $readonly = false;
     $textreadonly = false;
     $view = $instance->get_view();
     if (!empty($configdata['artefactid'])) {
         $artefactid = $configdata['artefactid'];
         try {
             $artefact = $instance->get_artefact_instance($artefactid);
             // Get the annotation record -> to get the artefact it's linked to.
             $annotation = new ArtefactTypeAnnotation($artefactid);
             // Get the total annotation feedback inserted so far by anyone.
             $totalannotationfeedback = ArtefactTypeAnnotationfeedback::count_annotation_feedback($artefactid, array($view->get('id')), array($annotation->get('artefact')));
             $readonly = $artefact->get('owner') !== $view->get('owner') || $artefact->get('group') !== $view->get('group') || $artefact->get('institution') !== $view->get('institution') || $artefact->get('locked') || !$USER->can_edit_artefact($artefact);
             if (isset($totalannotationfeedback[$view->get('id')])) {
                 $textreadonly = $totalannotationfeedback[$view->get('id')]->total > 0;
             }
             $text = $artefact->get('description');
             $tags = $artefact->get('tags');
         } catch (ArtefactNotFoundException $e) {
             unset($artefactid);
         }
     }
     $elements = array('text' => array('type' => $textreadonly ? 'html' : 'wysiwyg', 'class' => '', 'title' => get_string('Annotation', 'artefact.annotation'), 'width' => '100%', 'height' => $height . 'px', 'defaultvalue' => $text, 'rules' => array('maxlength' => 65536)), 'annotationreadonlymsg' => array('type' => 'html', 'class' => 'message info' . ($textreadonly ? '' : ' hidden'), 'value' => get_string('annotationreadonlymessage', 'blocktype.annotation/annotation'), 'help' => true), 'allowfeedback' => array('type' => 'switchbox', 'title' => get_string('allowannotationfeedback', 'artefact.annotation'), 'defaultvalue' => !empty($artefact) ? $artefact->get('allowcomments') : 1), 'tags' => array('type' => 'tags', 'class' => $readonly ? 'hidden' : '', 'width' => '100%', 'title' => get_string('tags'), 'description' => get_string('tagsdescprofile'), 'defaultvalue' => $tags), 'tagsreadonly' => array('type' => 'html', 'class' => $readonly ? '' : 'hidden', 'width' => '100%', 'title' => get_string('tags'), 'value' => '<div id="instconf_tagsreadonly_display">' . (is_array($tags) ? hsc(join(', ', $tags)) : '') . '</div>'));
     if ($textreadonly) {
         // The annotation is displayed as html, need to populate its value.
         $elements['text']['value'] = $text;
     }
     return $elements;
 }