コード例 #1
0
$comment = new ArtefactTypeComment($id);
if ($USER->get('id') != $comment->get('author')) {
    throw new AccessDeniedException(get_string('canteditnotauthor', 'artefact.comment'));
}
$onview = $comment->get('onview');
if ($onview && $onview != $viewid) {
    throw new NotFoundException(get_string('commentnotinview', 'artefact.comment', $id, $viewid));
}
$maxage = (int) get_config_plugin('artefact', 'comment', 'commenteditabletime');
$editableafter = time() - 60 * $maxage;
$goto = $comment->get_view_url($viewid, false);
if ($comment->get('ctime') < $editableafter) {
    $SESSION->add_error_msg(get_string('cantedittooold', 'artefact.comment', $maxage));
    redirect($goto);
}
$lastcomment = ArtefactTypeComment::last_public_comment($viewid, $comment->get('onartefact'));
if (!$comment->get('private') && $id != $lastcomment->id) {
    $SESSION->add_error_msg(get_string('cantedithasreplies', 'artefact.comment'));
    redirect($goto);
}
$elements = array();
$elements['message'] = array('type' => 'wysiwyg', 'title' => get_string('message'), 'rows' => 5, 'cols' => 80, 'defaultvalue' => $comment->get('description'), 'rules' => array('maxlength' => 8192));
if (get_config_plugin('artefact', 'comment', 'commentratings')) {
    $elements['rating'] = array('type' => 'radio', 'title' => get_string('rating', 'artefact.comment'), 'options' => array('1' => '', '2' => '', '3' => '', '4' => '', '5' => ''), 'class' => 'star', 'defaultvalue' => $comment->get('rating'));
} else {
    $elements['rating'] = array('type' => 'hidden', 'value' => $comment->get('rating'));
}
$elements['ispublic'] = array('type' => 'checkbox', 'title' => get_string('makepublic', 'artefact.comment'), 'defaultvalue' => !$comment->get('private'));
if (get_config('licensemetadata')) {
    $elements['license'] = license_form_el_basic($comment);
    $elements['licensing_advanced'] = license_form_el_advanced($comment);