/** * @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); } }
/** * Fix annotations to point to the right view. */ public static function setup_view_relationships_from_requests(PluginImportLeap $importer) { // Get all the annotations imported. if ($entry_requests = get_records_select_array('import_entry_requests', 'importid = ? AND entrytype = ?', array($importer->get('importertransport')->get('importid'), 'annotation'))) { foreach ($entry_requests as $entry_request) { $annotationids = $importer->get_artefactids_imported_by_entryid($entry_request->entryid); $annotation = new ArtefactTypeAnnotation($annotationids[0]); if (!$annotation->get('id')) { continue; } $annotation_entry = $importer->get_entry_by_id($entry_request->entryid); $view_entry_request = self::get_referent_entryid($annotation_entry, $importer); // Now see which view had this entryid. if ($viewid = $importer->get_viewid_imported_by_entryid($view_entry_request)) { // Set the view on the annotation. $annotation->set('view', $viewid); $annotation->commit(); } else { // Nothing to link this annotation to, so leave it in the temporary view. self::$savetempview = true; } } } }
* @copyright For copyright information on Mahara, please see the README file distributed with this software. * */ define('INTERNAL', 1); define('MENUITEM', 'myportfolio'); require dirname(dirname(dirname(__FILE__))) . '/init.php'; define('TITLE', get_string('editannotationfeedback', 'artefact.annotation')); safe_require('artefact', 'annotation'); $annotationfeedbackid = param_integer('id'); $viewid = param_integer('viewid'); $annotationfeedback = new ArtefactTypeAnnotationFeedback((int) $annotationfeedbackid); if ($USER->get('id') != $annotationfeedback->get('author')) { 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);
public static function instance_config_save($values, $instance) { require_once 'embeddedimage.php'; safe_require('artefact', 'annotation'); $data = array(); $view = $instance->get_view(); $configdata = $instance->get('configdata'); foreach (array('owner', 'group', 'institution') as $f) { $data[$f] = $view->get($f); } // The title will always be Annotation. $title = get_string('Annotation', 'artefact.annotation'); $data['title'] = $title; $values['title'] = $title; if (empty($configdata['artefactid'])) { // This is a new annotation. $artefact = new ArtefactTypeAnnotation(0, $data); } else { // The user is editing the annotation. $artefact = new ArtefactTypeAnnotation($configdata['artefactid']); } $artefact->set('title', $title); $artefact->set('description', $values['text']); $artefact->set('allowcomments', !empty($values['allowfeedback']) ? $values['allowfeedback'] : 0); $artefact->set('tags', $values['tags']); $artefact->set('view', $view->get('id')); $artefact->commit(); // Now fix up the text in case there were any embedded images. // Do this after saving because we may not have an artefactid yet. $newdescription = EmbeddedImage::prepare_embedded_images($values['text'], 'annotation', $artefact->get('id'), $view->get('group')); if ($newdescription !== false && $newdescription !== $values['text']) { $updatedartefact = new stdClass(); $updatedartefact->id = $artefact->get('id'); $updatedartefact->description = $newdescription; update_record('artefact', $updatedartefact, 'id'); } $values['artefactid'] = $artefact->get('id'); $instance->save_artefact_instance($artefact); unset($values['text']); unset($values['allowfeedback']); unset($values['annotationreadonlymsg']); // Pass back a list of any other blocks that need to be rendered // due to this change. $values['_redrawblocks'] = array_unique(get_column('view_artefact', 'block', 'artefact', $values['artefactid'], 'view', $instance->get('view'))); return $values; }