Exemple #1
0
function edit_comment_submit(Pieform $form, $values)
{
    global $viewid, $comment, $SESSION, $goto, $USER;
    require_once 'embeddedimage.php';
    db_begin();
    $comment->set('rating', valid_rating($values['rating']));
    require_once get_config('libroot') . 'view.php';
    $view = new View($viewid);
    $owner = $view->get('owner');
    $group = $comment->get('group');
    $newdescription = EmbeddedImage::prepare_embedded_images($values['message'], 'comment', $comment->get('id'), $group);
    $comment->set('description', $newdescription);
    $approvecomments = $view->get('approvecomments');
    if (!empty($group) && ($approvecomments || !$approvecomments && $view->user_comments_allowed($USER) == 'private') && $values['ispublic'] && !$USER->can_edit_view($view)) {
        $comment->set('requestpublic', 'author');
    } else {
        if (($approvecomments || !$approvecomments && $view->user_comments_allowed($USER) == 'private') && $values['ispublic'] && (!empty($owner) && $owner != $comment->get('author'))) {
            $comment->set('requestpublic', 'author');
        } else {
            $comment->set('private', 1 - (int) $values['ispublic']);
            $comment->set('requestpublic', null);
        }
    }
    $comment->commit();
    require_once 'activity.php';
    $data = (object) array('commentid' => $comment->get('id'), 'viewid' => $viewid);
    activity_occurred('feedback', $data, 'artefact', 'comment');
    if ($comment->get('requestpublic') == 'author') {
        if (!empty($owner)) {
            edit_comment_notify($view, $comment->get('author'), $owner);
        } else {
            if (!empty($group)) {
                $group_admins = group_get_admin_ids($group);
                // TODO: need to notify the group admins bug #1197197
            }
        }
    }
    db_commit();
    $SESSION->add_ok_msg(get_string('commentupdated', 'artefact.comment'));
    redirect($goto);
}
 public static function build_html(&$data)
 {
     global $USER, $THEME;
     $candelete = $data->canedit || $USER->get('admin');
     $deletedmessage = array();
     foreach (self::deleted_messages() as $k => $v) {
         $deletedmessage[$k] = get_string($v, 'artefact.comment');
     }
     $authors = array();
     $lastcomment = self::last_public_comment($data->view, $data->artefact);
     $editableafter = time() - 60 * get_config_plugin('artefact', 'comment', 'commenteditabletime');
     foreach ($data->data as &$item) {
         $item->ts = strtotime($item->ctime);
         $item->date = format_date($item->ts, 'strftimedatetime');
         if ($item->ts < strtotime($item->lastcontentupdate)) {
             $item->updated = format_date(strtotime($item->lastcontentupdate), 'strftimedatetime');
         }
         $item->isauthor = $item->author && $item->author == $USER->get('id');
         if (!empty($item->attachments)) {
             if ($data->isowner) {
                 $item->attachmessage = get_string('feedbackattachmessage', 'artefact.comment', get_string('feedbackattachdirname', 'artefact.comment'));
             }
             foreach ($item->attachments as &$a) {
                 $a->attachid = $a->attachment;
                 $a->attachtitle = $a->title;
                 $a->attachsize = display_size($a->size);
             }
         }
         if ($item->private) {
             $item->pubmessage = get_string('thiscommentisprivate', 'artefact.comment');
         }
         if (isset($data->showcomment) && $data->showcomment == $item->id) {
             $item->highlight = 1;
         }
         $is_export_preview = param_integer('export', 0);
         if ($item->deletedby) {
             $item->deletedmessage = $deletedmessage[$item->deletedby];
         } else {
             if (($candelete || $item->isauthor) && !$is_export_preview) {
                 $item->deleteform = pieform(self::delete_comment_form($item->id));
             }
         }
         // Comment authors can edit recent comments if they're private or if no one has replied yet.
         if (!$item->deletedby && $item->isauthor && !$is_export_preview && ($item->private || $item->id == $lastcomment->id) && $item->ts > $editableafter) {
             $item->canedit = 1;
         }
         // Form to make private comment public, or request that a
         // private comment be made public
         if (!$item->deletedby && $item->private && $item->author && $data->owner && ($item->isauthor || $data->isowner)) {
             if (empty($item->requestpublic) && $data->isowner || $item->isauthor && $item->requestpublic == 'owner' || $data->isowner && $item->requestpublic == 'author') {
                 if (!$is_export_preview) {
                     $item->makepublicform = pieform(self::make_public_form($item->id));
                 }
             } else {
                 if ($item->isauthor && $item->requestpublic == 'author' || $data->isowner && $item->requestpublic == 'owner') {
                     $item->makepublicrequested = 1;
                 }
             }
         } else {
             if (!$item->deletedby && $item->private && !$item->author && $data->owner && $data->isowner && $item->requestpublic == 'author' && !$is_export_preview) {
                 $item->makepublicform = pieform(self::make_public_form($item->id));
             } else {
                 if (!$item->deletedby && $item->private && !$data->owner && $item->group && $item->requestpublic == 'author') {
                     // no owner as comment is on a group view / artefact
                     if ($item->isauthor) {
                         $item->makepublicrequested = 1;
                     } else {
                         if ($data->artefact && $data->canedit || $data->view && $data->canedit && !$is_export_preview) {
                             $item->makepublicform = pieform(self::make_public_form($item->id));
                         } else {
                             $item->makepublicrequested = 1;
                         }
                     }
                 }
             }
         }
         if ($item->author) {
             if (isset($authors[$item->author])) {
                 $item->author = $authors[$item->author];
             } else {
                 $item->author = $authors[$item->author] = (object) array('id' => $item->author, 'username' => $item->username, 'firstname' => $item->firstname, 'lastname' => $item->lastname, 'preferredname' => $item->preferredname, 'email' => $item->email, 'staff' => $item->staff, 'admin' => $item->admin, 'deleted' => $item->deleted, 'profileicon' => $item->profileicon, 'profileurl' => profile_url($item->author));
             }
         }
         if (get_config_plugin('artefact', 'comment', 'commentratings') and $item->rating) {
             $item->ratingdata = (object) array('value' => valid_rating($item->rating), 'min_rating' => MIN_RATING, 'max_rating' => MAX_RATING, 'export' => $data->export);
         }
     }
     $extradata = array('view' => $data->view);
     $data->jsonscript = 'artefact/comment/comments.json.php';
     if (!empty($data->artefact)) {
         $data->baseurl = get_config('wwwroot') . 'artefact/artefact.php?view=' . $data->view . '&artefact=' . $data->artefact;
         $extradata['artefact'] = $data->artefact;
     } else {
         $data->baseurl = get_config('wwwroot') . 'view/view.php?id=' . $data->view;
     }
     $smarty = smarty_core();
     $smarty->assign_by_ref('data', $data->data);
     $smarty->assign('canedit', $data->canedit);
     $smarty->assign('viewid', $data->view);
     $smarty->assign('position', $data->position);
     $smarty->assign('baseurl', $data->baseurl);
     $data->tablerows = $smarty->fetch('artefact:comment:commentlist.tpl');
     $pagination = build_pagination(array('id' => 'feedback_pagination', 'class' => 'center', 'url' => $data->baseurl, 'jsonscript' => $data->jsonscript, 'datatable' => 'feedbacktable', 'count' => $data->count, 'limit' => $data->limit, 'offset' => $data->offset, 'forceoffset' => isset($data->forceoffset) ? $data->forceoffset : null, 'resultcounttextsingular' => get_string('comment', 'artefact.comment'), 'resultcounttextplural' => get_string('comments', 'artefact.comment'), 'extradata' => $extradata));
     $data->pagination = $pagination['html'];
     $data->pagination_js = $pagination['javascript'];
 }