Adding event comments see BT#7802

Requires DB change + configuration setting 'allow_agenda_event_comment'
1.9.x
Julio Montoya 10 years ago
parent c7955a6c0d
commit 3a7cf71e15
  1. 36
      main/calendar/agenda.lib.php
  2. 12
      main/calendar/agenda.php
  3. 8
      main/calendar/agenda_js.php
  4. 4
      main/calendar/agenda_list.php
  5. 46
      main/cron/import_csv.php
  6. 2
      main/install/configuration.dist.php
  7. 8
      main/template/default/agenda/event_list.tpl
  8. 34
      main/template/default/agenda/month.tpl

@ -16,6 +16,7 @@ class Agenda
public $senderId; public $senderId;
/** @var array */ /** @var array */
public $course; public $course;
public $comment;
/** /**
* Constructor * Constructor
@ -114,6 +115,7 @@ class Agenda
* @param int $parentEventId * @param int $parentEventId
* @param array $attachmentArray $_FILES[''] * @param array $attachmentArray $_FILES['']
* @param string $attachmentComment * @param string $attachmentComment
* @param string $eventComment
* *
* @return int * @return int
*/ */
@ -127,7 +129,8 @@ class Agenda
$addAsAnnouncement = false, $addAsAnnouncement = false,
$parentEventId = null, $parentEventId = null,
$attachmentArray = array(), $attachmentArray = array(),
$attachmentComment = null $attachmentComment = null,
$eventComment = null
) { ) {
$start = api_get_utc_datetime($start); $start = api_get_utc_datetime($start);
$end = api_get_utc_datetime($end); $end = api_get_utc_datetime($end);
@ -160,6 +163,12 @@ class Agenda
'c_id' => $this->course['real_id'] 'c_id' => $this->course['real_id']
); );
$allow = api_get_configuration_value('allow_agenda_event_comment');
if ($allow) {
$attributes['comment'] = $eventComment;
}
if (!empty($parentEventId)) { if (!empty($parentEventId)) {
$attributes['parent_event_id'] = $parentEventId; $attributes['parent_event_id'] = $parentEventId;
} }
@ -533,6 +542,7 @@ class Agenda
* @param int $editRepeatType * @param int $editRepeatType
* @param array $attachmentArray * @param array $attachmentArray
* @param string $attachmentComment * @param string $attachmentComment
* @param string $comment
* *
* @return bool * @return bool
*/ */
@ -545,7 +555,8 @@ class Agenda
$content, $content,
$usersToSend = array(), $usersToSend = array(),
$attachmentArray = array(), $attachmentArray = array(),
$attachmentComment = null $attachmentComment = null,
$comment = null
) { ) {
$start = api_get_utc_datetime($start); $start = api_get_utc_datetime($start);
$end = api_get_utc_datetime($end); $end = api_get_utc_datetime($end);
@ -594,6 +605,12 @@ class Agenda
'all_day' => $allDay 'all_day' => $allDay
); );
$allow = api_get_configuration_value('allow_agenda_event_comment');
if ($allow) {
$attributes['comment'] = $comment;
}
Database::update( Database::update(
$this->tbl_course_agenda, $this->tbl_course_agenda,
$attributes, $attributes,
@ -1322,6 +1339,7 @@ class Agenda
} }
$sql .= $dateCondition; $sql .= $dateCondition;
$allowComments = api_get_configuration_value('allow_agenda_event_comment');
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result)) { if (Database::num_rows($result)) {
@ -1428,9 +1446,16 @@ class Agenda
$event['parent_event_id'] = $row['parent_event_id']; $event['parent_event_id'] = $row['parent_event_id'];
$event['has_children'] = $this->hasChildren($row['id'], $course_id) ? 1 : 0; $event['has_children'] = $this->hasChildren($row['id'], $course_id) ? 1 : 0;
if ($allowComments) {
$event['comment'] = $row['comment'];
} else {
$event['comment'] = null;
}
$this->events[] = $event; $this->events[] = $event;
} }
} }
return $this->events; return $this->events;
} }
@ -1822,6 +1847,11 @@ class Agenda
); );
if ($this->type == 'course') { if ($this->type == 'course') {
$allow = api_get_configuration_value('allow_agenda_event_comment');
if ($allow) {
$form->addElement('textarea', 'comment', get_lang('Comment'));
}
$form->addElement('file', 'user_upload', get_lang('AddAnAttachment')); $form->addElement('file', 'user_upload', get_lang('AddAnAttachment'));
if ($showAttachmentForm) { if ($showAttachmentForm) {
@ -1839,7 +1869,7 @@ class Agenda
} }
} }
$form->addElement('textarea', 'file_comment', get_lang('Comment')); $form->addElement('textarea', 'file_comment', get_lang('FileComment'));
} }
if (empty($id)) { if (empty($id)) {

@ -114,6 +114,8 @@ if (api_is_allowed_to_edit(false, true) OR
$attachment = $sendAttachment ? $_FILES['user_upload'] : null; $attachment = $sendAttachment ? $_FILES['user_upload'] : null;
$attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null; $attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null;
$comment = isset($values['comment']) ? $values['comment'] : null;
$startDate = $values['date_range_start']; $startDate = $values['date_range_start'];
$endDate = $values['date_range_end']; $endDate = $values['date_range_end'];
@ -127,7 +129,8 @@ if (api_is_allowed_to_edit(false, true) OR
$sendEmail, $sendEmail,
null, null,
$attachment, $attachment,
$attachmentComment $attachmentComment,
$comment
); );
if (!empty($values['repeat']) && !empty($eventId)) { if (!empty($values['repeat']) && !empty($eventId)) {
@ -174,6 +177,7 @@ if (api_is_allowed_to_edit(false, true) OR
$sendAttachment = isset($_FILES['user_upload']) ? true : false; $sendAttachment = isset($_FILES['user_upload']) ? true : false;
$attachment = $sendAttachment ? $_FILES['user_upload'] : null; $attachment = $sendAttachment ? $_FILES['user_upload'] : null;
$attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null; $attachmentComment = isset($values['file_comment']) ? $values['file_comment'] : null;
$comment = isset($values['comment']) ? $values['comment'] : null;
// This is a sub event. Delete the current and create another BT#7803 // This is a sub event. Delete the current and create another BT#7803
@ -190,7 +194,8 @@ if (api_is_allowed_to_edit(false, true) OR
false, false,
null, null,
$attachment, $attachment,
$attachmentComment $attachmentComment,
$comment
); );
$message = Display::return_message(get_lang('Updated'), 'confirmation'); $message = Display::return_message(get_lang('Updated'), 'confirmation');
@ -209,7 +214,8 @@ if (api_is_allowed_to_edit(false, true) OR
$values['content'], $values['content'],
$values['users_to_send'], $values['users_to_send'],
$attachment, $attachment,
$attachmentComment $attachmentComment,
$comment
); );
if (!empty($values['repeat']) && !empty($eventId)) { if (!empty($values['repeat']) && !empty($eventId)) {

@ -1,5 +1,6 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
/** /**
* @package chamilo.calendar * @package chamilo.calendar
*/ */
@ -221,10 +222,15 @@ $form->addElement('label', get_lang('Date'), '<span id="start_date"></span><span
$form->addElement('text', 'title', get_lang('Title'), array('id' => 'title')); $form->addElement('text', 'title', get_lang('Title'), array('id' => 'title'));
$form->addElement('textarea', 'content', get_lang('Description'), array('id' => 'content')); $form->addElement('textarea', 'content', get_lang('Description'), array('id' => 'content'));
$allowEventComment = api_get_configuration_value('allow_agenda_event_comment');
if ($agenda->type == 'course') { if ($agenda->type == 'course') {
$form->addElement('html', '<div id="add_as_announcement_div" style="display: none">'); $form->addElement('html', '<div id="add_as_announcement_div" style="display: none">');
$form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement')); $form->addElement('checkbox', 'add_as_annonuncement', null, get_lang('AddAsAnnouncement'));
$form->addElement('html', '</div>'); $form->addElement('html', '</div>');
if ($allowEventComment) {
$form->addElement('textarea', 'comment', get_lang('Comment'), array('id' => 'comment'));
}
} }
$tpl->assign('form_add', $form->return_form()); $tpl->assign('form_add', $form->return_form());
@ -234,6 +240,8 @@ $content = $tpl->fetch('default/agenda/month.tpl');
$message = Session::read('message'); $message = Session::read('message');
$tpl->assign('message', $message); $tpl->assign('message', $message);
$tpl->assign('allow_agenda_event_comment', $allowEventComment);
Session::erase('message'); Session::erase('message');
$tpl->assign('content', $content); $tpl->assign('content', $content);

@ -3,9 +3,7 @@
/** /**
* @package chamilo.calendar * @package chamilo.calendar
*/ */
/**
* INIT SECTION
*/
// name of the language file that needs to be included // name of the language file that needs to be included
$language_file = array('agenda', 'group', 'announcements'); $language_file = array('agenda', 'group', 'announcements');

@ -644,17 +644,47 @@ class ImportCsv
{ {
$data = Import::csv_to_array($file); $data = Import::csv_to_array($file);
if ($this->getDumpValues()) {
// Remove all calendar items
$truncateTables = array(
Database::get_course_table(TABLE_AGENDA),
Database::get_course_table(TABLE_AGENDA_ATTACHMENT),
Database::get_course_table(TABLE_AGENDA_REPEAT),
Database::get_course_table(TABLE_AGENDA_REPEAT_NOT),
Database::get_main_table(TABLE_PERSONAL_AGENDA),
Database::get_main_table(TABLE_PERSONAL_AGENDA_REPEAT_NOT),
Database::get_main_table(TABLE_PERSONAL_AGENDA_REPEAT)
);
foreach ($truncateTables as $table) {
$sql = "TRUNCATE $table";
Database::query($sql);
}
$table = Database::get_course_table(TABLE_ITEM_PROPERTY);
$sql = "DELETE FROM $table WHERE tool = 'calendar_event'";
Database::query($sql);
}
if (!empty($data)) { if (!empty($data)) {
$this->logger->addInfo(count($data) . " records found."); $this->logger->addInfo(count($data) . " records found.");
$eventsToCreate = array(); $eventsToCreate = array();
$errorFound = false; $errorFound = false;
foreach ($data as $row) { foreach ($data as $row) {
$sessionId = null;
$externalSessionId = null;
if (isset($row['external_sessionID'])) {
$externalSessionId = $row['external_sessionID'];
$sessionId = SessionManager::get_session_id_from_original_id( $sessionId = SessionManager::get_session_id_from_original_id(
$row['external_sessionID'], $externalSessionId,
$this->extraFieldIdNameList['session'] $this->extraFieldIdNameList['session']
); );
}
$courseCode = null;
if (isset($row['coursecode'])) {
$courseCode = $row['coursecode']; $courseCode = $row['coursecode'];
}
$courseInfo = api_get_course_info($courseCode); $courseInfo = api_get_course_info($courseCode);
if (empty($courseInfo)) { if (empty($courseInfo)) {
@ -662,7 +692,7 @@ class ImportCsv
} }
if (empty($sessionId)) { if (empty($sessionId)) {
$this->logger->addInfo("external_sessionID: ".$row['external_sessionID']." does not exists."); $this->logger->addInfo("external_sessionID: ".$externalSessionId." does not exists.");
} }
$teacherId = null; $teacherId = null;
@ -793,6 +823,12 @@ class ImportCsv
$agenda->setSessionId($event['session_id']); $agenda->setSessionId($event['session_id']);
$agenda->setSenderId($event['sender_id']); $agenda->setSenderId($event['sender_id']);
$eventComment = $event['comment'];
// To use the event comment you need
// ALTER TABLE c_calendar_event ADD COLUMN comment TEXT;
// add in configuration.php allow_agenda_event_comment = true
if (empty($courseInfo)) { if (empty($courseInfo)) {
$this->logger->addInfo( $this->logger->addInfo(
"No course found for added: #".$event['course_id']." Skipping ..." "No course found for added: #".$event['course_id']." Skipping ..."
@ -814,7 +850,11 @@ class ImportCsv
$event['title'], $event['title'],
$content, $content,
array('everyone'), // send to array('everyone'), // send to
false //$addAsAnnouncement = false false, //$addAsAnnouncement = false
null, // $parentEventId
array(), //$attachmentArray = array(),
null, //$attachmentComment = null,
$eventComment
); );
if (!empty($eventId)) { if (!empty($eventId)) {

@ -284,3 +284,5 @@ $_configuration['system_stable'] = NEW_VERSION_STABLE;
//); //);
// Shows a warning message explaining that the site uses cookies // Shows a warning message explaining that the site uses cookies
//$_configuration['cookie_warning'] = false; //$_configuration['cookie_warning'] = false;
// Allows a comment field in the course calendar events. Requires DB change
//$_configuration['allow_agenda_event_comment'] = false;

@ -29,7 +29,15 @@
</td> </td>
<td style="width:50%"> <td style="width:50%">
{{ event.title }} {{ event.title }}
{% if event.description %}
<p>{{ event.description}}</p> <p>{{ event.description}}</p>
{% endif %}
{% if event.comment %}
<p>{{ event.comment}}</p>
{% endif %}
{{ event.attachment }} {{ event.attachment }}
</td> </td>

@ -230,21 +230,25 @@ $(document).ready(function() {
delay: 2000 delay: 2000
}, },
content: event.attachment, content: event.attachment,
position: { at:'top right' , my:'bottom right'}, position: { at:'top right' , my:'bottom right'}
}).removeData('qtip'); // this is an special hack to add multiple qtip in the same target }).removeData('qtip'); // this is an special hack to add multiple qtip in the same target
} }
if (event.description) { if (event.description) {
var comment = '';
if (event.comment) {
comment = event.comment;
}
element.qtip({ element.qtip({
hide: { hide: {
delay: 2000 delay: 2000
}, },
content: event.description, content: event.description + ' ' + comment,
position: { at:'top left' , my:'bottom left'} position: { at:'top left' , my:'bottom left'}
}); });
} }
}, },
eventClick: function(calEvent, jsEvent, view) { eventClick: function(calEvent, jsEvent, view) {
//var start_date = Math.round(calEvent.start.getTime() / 1000);
var start_date = $.datepicker.formatDate("yy-mm-dd", calEvent.start) + " " + calEvent.start.toTimeString().substr(0, 8); var start_date = $.datepicker.formatDate("yy-mm-dd", calEvent.start) + " " + calEvent.start.toTimeString().substr(0, 8);
if (calEvent.allDay == 1) { if (calEvent.allDay == 1) {
@ -293,14 +297,21 @@ $(document).ready(function() {
if ($("#content").parent().find('#content_edit').length == 0) { if ($("#content").parent().find('#content_edit').length == 0) {
$("#content").parent().append('<div id="content_edit"></div>'); $("#content").parent().append('<div id="content_edit"></div>');
} }
$("#content_edit").html(calEvent.description); $("#content_edit").html(calEvent.description);
if ($("#comment").parent().find('#comment_edit').length == 0) {
$("#comment").parent().append('<div id="comment_edit"></div>');
}
$("#comment_edit").html(calEvent.comment);
$("#title_edit").show(); $("#title_edit").show();
$("#content_edit").show(); $("#content_edit").show();
$("#comment_edit").show();
$("#title").hide(); $("#title").hide();
$("#content").hide(); $("#content").hide();
$("#comment").hide();
allFields.removeClass( "ui-state-error" ); allFields.removeClass( "ui-state-error" );
@ -337,7 +348,6 @@ $(document).ready(function() {
calEvent.end = calEvent.end; calEvent.end = calEvent.end;
calEvent.allDay = calEvent.allDay; calEvent.allDay = calEvent.allDay;
calEvent.description = $("#content").val(); calEvent.description = $("#content").val();
calendar.fullCalendar('updateEvent', calendar.fullCalendar('updateEvent',
calEvent, calEvent,
true // make the event "stick" true // make the event "stick"
@ -450,13 +460,14 @@ $(document).ready(function() {
$("#simple_title").html(calEvent.title); $("#simple_title").html(calEvent.title);
$("#simple_content").html(calEvent.description); $("#simple_content").html(calEvent.description);
$("#simple_comment").html(calEvent.comment);
$("#simple-dialog-form").dialog("open"); $("#simple-dialog-form").dialog("open");
$("#simple-dialog-form").dialog({ $("#simple-dialog-form").dialog({
buttons: { buttons: {
'{{"ExportiCalConfidential"|get_lang}}' : function() { '{{"ExportiCalConfidential"|get_lang}}' : function() {
url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential"; url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=confidential";
window.location.href = url; window.location.href = url;
}, },
'{{"ExportiCalPrivate"|get_lang}}': function() { '{{"ExportiCalPrivate"|get_lang}}': function() {
url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private"; url = "ical_export.php?id=" + calEvent.id+'&course_id='+calEvent.course_id+"&class=private";
@ -528,6 +539,17 @@ $(document).ready(function() {
<div id="simple_content"></div> <div id="simple_content"></div>
</div> </div>
</div> </div>
{% if allow_agenda_event_comment %}
<div class="control-group">
<label class="control-label">
<b>{{ "Comment" |get_lang}}</b>
</label>
<div class="controls">
<div id="simple_comment"></div>
</div>
</div>
{% endif %}
</form> </form>
</div> </div>
</div> </div>

Loading…
Cancel
Save