Improve student publication UI see BT#12100

ofaj
Julio 9 years ago
parent 66f42828e0
commit 7e7ba82f47
  1. 7
      main/template/default/work/comments.tpl
  2. 2
      main/template/default/work/view.tpl
  3. 13
      main/work/edit.php
  4. 103
      main/work/view.php
  5. 54
      main/work/work.lib.php

@ -1,4 +1,4 @@
<hr>
<hr />
<h3>
{{ 'Comments' | get_lang }}
</h3>
@ -9,7 +9,7 @@
<div class="page-header">
<a href="{{ _p.web_code }}">
<img height="24" src="{{ comment.picture }}"/> {{ comment.complete_name }}
</a>- {{ comment.sent_at | api_get_local_time }}
</a>- {{ comment.sent_at_with_label }}
</div>
<p>
{% if comment.comment is not empty %}
@ -35,6 +35,3 @@
{% endfor %}
</ul>
<br />
<hr>
{{ form }}

@ -13,7 +13,7 @@
</p>
{% endif %}
{{ score_form }}
{{ form }}
{% if work.contains_file and work.show_content %}
<h3>

@ -306,20 +306,7 @@ if (!empty($work_id)) {
if (api_resource_is_locked_by_gradebook($work_id, LINK_STUDENTPUBLICATION)) {
echo Display::display_warning_message(get_lang('ResourceLockedByGradebook'));
} else {
/*$comments = getWorkComments($work_item);
$template = $tpl->get_template('work/comments.tpl');
$tpl->assign('comments', $comments);
$commentForm = getWorkCommentForm($work_item, 'edit');
*/
if (api_is_allowed_to_session_edit()) {
//$tpl->assign('form', $commentForm);
}
$content .= $form->returnForm();
/*$content .= $form->returnForm();
$content .= $tpl->fetch($template);*/
}
} elseif ($is_author) {
if (empty($work_item['qualificator_id']) || $work_item['qualificator_id'] == 0) {

@ -72,9 +72,21 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
}
switch ($action) {
case 'update_score':
case 'send_comment':
if (isset($_FILES['attachment'])) {
$_POST['attachment'] = $_FILES['attachment'];
}
addWorkComment(
api_get_course_info(),
api_get_user_id(),
$my_folder_data,
$work,
$_POST
);
if (api_is_allowed_to_edit()) {
$work_table = Database :: get_course_table(TABLE_STUDENT_PUBLICATION);
$work_table = Database:: get_course_table(TABLE_STUDENT_PUBLICATION);
$sql = "UPDATE $work_table
SET
qualificator_id = '".api_get_user_id()."',
@ -82,6 +94,9 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
date_of_qualification = '".api_get_utc_datetime()."'
WHERE c_id = ".$courseInfo['real_id']." AND id = $id";
Database::query($sql);
Display::addFlash(Display::return_message(get_lang('Updated')));
$resultUpload = uploadWork($my_folder_data, $courseInfo, true, $work);
if ($resultUpload) {
$work_table = Database:: get_course_table(
@ -89,58 +104,22 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
);
if (isset($resultUpload['url']) && !empty($resultUpload['url'])) {
$title = isset($resultUpload['filename']) && !empty($resultUpload['filename']) ? $resultUpload['filename'] : get_lang('Untitled');
$title = isset($resultUpload['filename']) && !empty($resultUpload['filename']) ? $resultUpload['filename'] : get_lang(
'Untitled'
);
$urlToSave = Database::escape_string($resultUpload['url']);
$title = Database::escape_string($title);
$sql = "UPDATE $work_table SET
url_correction = '".$urlToSave."',
title_correction = '".$title."'
WHERE iid = ".$work['iid'];
url_correction = '".$urlToSave."',
title_correction = '".$title."'
WHERE iid = ".$work['iid'];
Database::query($sql);
Display::addFlash(
Display::return_message(get_lang('FileUploadSucces'))
);
}
}
if (isset($_POST['send_email'])) {
$urlToSave = api_get_path(WEB_CODE_PATH).'work/view.php?'.api_get_cidreq().'&id='.$id;
$subject = sprintf(get_lang('ThereIsANewWorkFeedback'), $work['title']);
$message = sprintf(get_lang('ThereIsANewWorkFeedbackInWorkXHere'), $work['title'], $urlToSave);
MessageManager::send_message_simple(
$work['user_id'],
$subject,
$message,
api_get_user_id(),
isset($_POST['send_to_drh_users'])
);
Display::addFlash(
Display::return_message(get_lang('MessageSent'))
);
}
Display::addFlash(
Display::return_message(get_lang('Updated'))
);
}
header('Location: '.$url);
exit;
break;
case 'send_comment':
if (isset($_FILES["file"])) {
$_POST['file'] = $_FILES["file"];
}
addWorkComment(
api_get_course_info(),
api_get_user_id(),
$my_folder_data,
$work,
$_POST
);
Display::addFlash(Display::return_message(get_lang('CommentCreated')));
header('Location: '.$url);
exit;
@ -171,7 +150,7 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
}
$comments = getWorkComments($work);
$commentForm = getWorkCommentForm($work);
$commentForm = getWorkCommentForm($work, $my_folder_data);
$tpl = new Template();
@ -216,40 +195,6 @@ if ((user_is_author($id) || $isDrhOfCourse || (api_is_allowed_to_edit() || api_i
}
}
$qualification = $my_folder_data['qualification'];
if (api_is_allowed_to_edit() && !empty($qualification) && intval($qualification) > 0) {
$form = new FormValidator(
'form',
'POST',
api_get_self()."?action=update_score&".api_get_cidreq()."&id=".$id,
'',
array('enctype' => "multipart/form-data")
);
$form->addElement('hidden', 'id', $id);
$form->addFloat(
'qualification',
array(get_lang('Qualification'), " / ".$qualification),
false,
[],
false,
0,
$qualification
);
$form->addFile('file', get_lang('Correction'));
$form->addCheckBox(
'send_email',
null,
get_lang('SendMailToStudent')
);
$form->setDefaults(['qualification' => $work['qualification']]);
$form->addButtonUpdate(get_lang('Update'));
$tpl->assign('score_form', $form->returnForm());
} else {
$tpl->assign('score_form', $actions);
}
$tpl->assign('actions', $actions);
if (api_is_allowed_to_session_edit()) {
$tpl->assign('form', $commentForm);

@ -3166,6 +3166,7 @@ function getWorkComment($id, $courseInfo = array())
$comment['file_path'] = $filePath;
$comment['file_url'] = $fileUrl;
$comment['file_name_to_show'] = $fileName;
$comment['sent_at_with_label'] = Display::dateToStringAgoAndLongDate($comment['sent_at']);
}
return $comment;
@ -3204,8 +3205,14 @@ function deleteCommentFile($id, $courseInfo = array())
*/
function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
{
$fileData = isset($data['attachment']) ? $data['attachment'] : null;
$commentTable = Database::get_course_table(TABLE_STUDENT_PUBLICATION_ASSIGNMENT_COMMENT);
// If no attachment and no comment then don't save comment
if (empty($fileData['name']) && empty($data['comment'])) {
return false;
}
$params = array(
'work_id' => $work['id'],
'c_id' => $work['c_id'],
@ -3217,12 +3224,14 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
$commentId = Database::insert($commentTable, $params);
if ($commentId) {
Display::addFlash(
Display::return_message(get_lang('CommentAdded'))
);
$sql = "UPDATE $commentTable SET id = iid WHERE iid = $commentId";
Database::query($sql);
}
$userIdListToSend = array();
if (api_is_allowed_to_edit()) {
if (isset($data['send_mail']) && $data['send_mail']) {
// Teacher sends a feedback
@ -3263,7 +3272,6 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
}
}
$fileData = isset($data['file']) ? $data['file'] : null;
if (!empty($commentId) && !empty($fileData)) {
$workParent = get_work_data_by_id($work['parent_id']);
if (!empty($workParent)) {
@ -3285,25 +3293,51 @@ function addWorkComment($courseInfo, $userId, $parentWork, $work, $data)
/**
* @param array $work
* @param string $page
*
* @return string
*/
function getWorkCommentForm($work, $page = 'view')
function getWorkCommentForm($work, $workParent)
{
$url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&action=send_comment&'.api_get_cidreq().'&page='.$page;
$url = api_get_path(WEB_CODE_PATH).'work/view.php?id='.$work['id'].'&action=send_comment&'.api_get_cidreq();
$form = new FormValidator(
'work_comment',
'post',
$url
$url,
'',
array('enctype' => "multipart/form-data")
);
$form->addElement('file', 'file', get_lang('Attachment'));
$form->addHtmlEditor('comment', get_lang('Comment'));
$qualification = $workParent['qualification'];
if (api_is_allowed_to_edit()) {
if (!empty($qualification) && intval($qualification) > 0) {
$form->addFloat(
'qualification',
array(get_lang('Qualification'), " / ".$qualification),
false,
[],
false,
0,
$qualification
);
$form->addFile('file', get_lang('Correction'));
$form->setDefaults(['qualification' => $work['qualification']]);
}
}
$form->addHtmlEditor('comment', get_lang('Comment'), false);
$form->addFile('attachment', get_lang('Attachment'));
$form->addElement('hidden', 'id', $work['id']);
$form->addElement('hidden', 'page', $page);
if (api_is_allowed_to_edit()) {
$form->addElement('checkbox', 'send_mail', null, get_lang('SendMail'));
$form->addCheckBox(
'send_email',
null,
get_lang('SendMailToStudent')
);
}
$form->addButtonSend(get_lang('Send'), 'button');
return $form->returnForm();

Loading…
Cancel
Save