Calendar: Add allow_careers_in_global_agenda conf option - refs BT#19497

Allow career/promotions in global calendar. Require DB changes:

```sql
ALTER TABLE sys_calendar ADD COLUMN career_id INT DEFAULT 0;
ALTER TABLE sys_calendar ADD COLUMN promotion_id INT DEFAULT 0;
```
pull/4204/head
Angel Fernando Quiroz Campos 4 years ago
parent 2c9b120182
commit aea292da3e
  1. 12
      main/calendar/agenda.php
  2. 5
      main/calendar/agenda_js.php
  3. 6
      main/inc/ajax/agenda.ajax.php
  4. 49
      main/inc/lib/agenda.lib.php
  5. 10
      main/inc/lib/career.lib.php
  6. 14
      main/inc/lib/system_announcements.lib.php
  7. 5
      main/install/configuration.dist.php
  8. 92
      main/template/default/agenda/month.tpl

@ -172,6 +172,8 @@ if ($allowToEdit) {
$endDate = $values['date_range_end'];
$notificationCount = $_REQUEST['notification_count'] ?? [];
$notificationPeriod = $_REQUEST['notification_period'] ?? [];
$careerId = $_REQUEST['career_id'] ?? 0;
$promotionId = $_REQUEST['promotion_id'] ?? 0;
$reminders = $notificationCount ? array_map(null, $notificationCount, $notificationPeriod) : [];
@ -190,7 +192,9 @@ if ($allowToEdit) {
'',
$values['invitees'] ?? [],
$values['collective'] ?? false,
$reminders
$reminders,
(int) $careerId,
(int) $promotionId
);
if (!empty($values['repeat']) && !empty($eventId)) {
@ -248,6 +252,8 @@ if ($allowToEdit) {
$comment = $values['comment'] ?? '';
$notificationCount = $_REQUEST['notification_count'] ?? [];
$notificationPeriod = $_REQUEST['notification_period'] ?? [];
$careerId = $_REQUEST['career_id'] ?? 0;
$promotionId = $_REQUEST['promotion_id'] ?? 0;
$reminders = $notificationCount ? array_map(null, $notificationCount, $notificationPeriod) : [];
@ -299,7 +305,9 @@ if ($allowToEdit) {
0,
$values['invitees'] ?? [],
$values['collective'] ?? false,
$reminders
$reminders,
(int) $careerId,
(int) $promotionId
);
if (!empty($values['repeat']) && !empty($eventId)) {

@ -300,6 +300,11 @@ if (api_get_configuration_value('agenda_reminders')) {
$form->addHtml('<hr>');
}
if (api_get_configuration_value('allow_careers_in_global_agenda') && 'admin' === $agenda->type) {
Career::addCareerFieldsToForm($form);
$form->addHtml('<hr>');
}
$form->addHtml('<div id="attachment_block" style="display: none">');
$form->addLabel(get_lang('Attachment'), '<div id="attachment_text" style="display: none"></div>');
$form->addHtml('</div>');

@ -49,6 +49,8 @@ switch ($action) {
$isCollective = isset($_REQUEST['collective']);
$notificationCount = $_REQUEST['notification_count'] ?? [];
$notificationPeriod = $_REQUEST['notification_period'] ?? [];
$careerId = $_REQUEST['career_id'] ?? 0;
$promotionId = $_REQUEST['promotion_id'] ?? 0;
$reminders = $notificationCount ? array_map(null, $notificationCount, $notificationPeriod) : [];
@ -67,7 +69,9 @@ switch ($action) {
'',
$inviteesList,
$isCollective,
$reminders
$reminders,
(int) $careerId,
(int) $promotionId
);
echo $eventId;

@ -252,7 +252,9 @@ class Agenda
$color = '',
array $inviteesList = [],
bool $isCollective = false,
array $reminders = []
array $reminders = [],
int $careerId = 0,
int $promotionId = 0
) {
$start = api_get_utc_datetime($start);
$end = api_get_utc_datetime($end);
@ -446,6 +448,11 @@ class Agenda
'access_url_id' => api_get_current_access_url_id(),
];
if (api_get_configuration_value('allow_careers_in_global_agenda')) {
$attributes['career_id'] = $careerId;
$attributes['promotion_id'] = $promotionId;
}
$id = Database::insert(
$this->tbl_global_agenda,
$attributes
@ -856,7 +863,9 @@ class Agenda
$authorId = 0,
array $inviteesList = [],
bool $isCollective = false,
array $remindersList = []
array $remindersList = [],
int $careerId = 0,
int $promotionId = 0
) {
$id = (int) $id;
$start = api_get_utc_datetime($start);
@ -1165,6 +1174,11 @@ class Agenda
'all_day' => $allDay,
];
if (api_get_configuration_value('allow_careers_in_global_agenda')) {
$attributes['career_id'] = $careerId;
$attributes['promotion_id'] = $promotionId;
}
if ($updateContent) {
$attributes['content'] = $content;
}
@ -2385,6 +2399,32 @@ class Agenda
$event['has_children'] = 0;
$event['description'] = $row['content'];
if (api_get_configuration_value('allow_careers_in_global_agenda')) {
$event['career'] = null;
$event['promotion'] = null;
if (!empty($row['career_id'])) {
$careerInfo = (new Career())->get($row['career_id']);
unset($careerInfo['status'], $careerInfo['created_at'], $careerInfo['updated_at']);
$event['career'] = $careerInfo;
}
if (!empty($row['promotion_id'])) {
$promotionInfo = (new Promotion())->get($row['promotion_id']);
unset(
$promotionInfo['career_id'],
$promotionInfo['status'],
$promotionInfo['created_at'],
$promotionInfo['updated_at']
);
$event['promotion'] = $promotionInfo;
}
}
$my_events[] = $event;
$this->events[] = $event;
}
@ -2876,6 +2916,11 @@ class Agenda
$form->addHtml('<hr>');
}
if (api_get_configuration_value('allow_careers_in_global_agenda') && 'admin' === $this->type) {
Career::addCareerFieldsToForm($form);
$form->addHtml('<hr>');
}
if ($id) {
$form->addButtonUpdate(get_lang('ModifyEvent'));
} else {

@ -1456,8 +1456,6 @@ class Career extends Model
var $txtPromotion = $("#promotion_id");
$("#career_id").on("change", function () {
$("#promotion").show();
var id = this.value;
$txtPromotion.empty().append($("<option>", {
@ -1491,24 +1489,22 @@ class Career extends Model
]
);
$display = 'none;';
$options = [];
$options = [
'0' => get_lang('All'),
];
if (isset($values['promotion_id'])) {
$promotion = new Promotion();
$promotion = $promotion->get($values['promotion_id']);
if ($promotion) {
$options = [$promotion['id'] => $promotion['name']];
$display = 'block';
}
}
$form->addHtml('<div id="promotion" style="display:'.$display.';">');
$form->addSelect(
'promotion_id',
get_lang('Promotion'),
$options,
['id' => 'promotion_id']
);
$form->addHtml('</div>');
}
}

@ -378,7 +378,19 @@ class SystemAnnouncementManager
$date_end,
false,
$title,
$original_content
$original_content,
[],
false,
null,
[],
[],
null,
'',
[],
false,
[],
$params['career_id'] ?? 0,
$params['promotion_id'] ?? 0
);
}

@ -1549,6 +1549,11 @@ ALTER TABLE notification_event_rel_user ADD CONSTRAINT FK_USER FOREIGN KEY (user
// ALTER TABLE sys_announcement ADD COLUMN promotion_id INT DEFAULT 0;
//$_configuration['allow_careers_in_global_announcements'] = false;
// Allow career/promotions in global calendar. Require DB changes:
// ALTER TABLE sys_calendar ADD COLUMN career_id INT DEFAULT 0;
// ALTER TABLE sys_calendar ADD COLUMN promotion_id INT DEFAULT 0;
//$_configuration['allow_careers_in_global_agenda'] = false;
// Hide start/end dates in "My courses" page (user_portal.php)
//$_configuration['hide_session_dates_in_user_portal'] = false;

@ -1,5 +1,6 @@
{% set agenda_collective_invitations = 'agenda_collective_invitations'|api_get_configuration_value %}
{% set agenda_reminders = 'agenda_reminders'|api_get_configuration_value %}
{% set career_in_global_events = 'allow_careers_in_global_agenda'|api_get_configuration_value %}
<style>
.fc-day-grid-event > .fc-content {
@ -331,6 +332,11 @@ $(function() {
$('#collective').prop('checked', false).show();
{% endif %}
{% if career_in_global_events %}
$('#career_id, #promotion_id').parent().show();
$('#form_career_id_edit, #form_promotion_id_edit').text('').hide();
{% endif %}
//Reset the CKEditor content that persist in memory
CKEDITOR.instances['content'].setData('');
allFields.removeClass("ui-state-error");
@ -603,6 +609,29 @@ $(function() {
});
{% endif %}
{% if career_in_global_events %}
$('select#promotion_id').on('refreshed.bs.select', function () {
$('select#promotion_id').val(function () {
if (calEvent.promotion
&& calEvent.career
&& $('select#career_id').val() == calEvent.career.id
) {
return calEvent.promotion.id;
}
return '0';
}).trigger('change');
});
$('select#career_id').val(function () {
if (calEvent.career) {
return calEvent.career.id;
}
return '';
}).trigger('change');
{% endif %}
$("#title_edit").show();
$("#content_edit").show();
{% if agenda_collective_invitations and 'personal' == type %}
@ -619,6 +648,32 @@ $(function() {
.show();
{% endif %}
{% if career_in_global_events %}
var $careerFieldParent = $('#career_id').parents('.col-sm-8');
var $promotionFieldParent = $('#promotion_id').parents('.col-sm-8');
if ($careerFieldParent.find('#form_career_id_edit').length === 0) {
$careerFieldParent.append('<p id="form_career_id_edit" class="form-control-static"></p>');
}
if ($promotionFieldParent.find('#form_promotion_id_edit').length === 0) {
$promotionFieldParent.append('<p id="form_promotion_id_edit" class="form-control-static"></p>');
}
$('#form_career_id_edit, #form_promotion_id_edit').text('');
$('#career_id, #promotion_id').parent().hide();
if (calEvent.career && 'admin' === calEvent.type) {
$('#form_career_id_edit').text(calEvent.career.name).show();
$('#promotion').show();
$('#form_promotion_id_edit').text('{{ 'All'|get_lang|escape('js') }}').show();
}
if (calEvent.promotion && 'admin' === calEvent.type) {
$('#form_promotion_id_edit').text(calEvent.promotion.name);
}
{% endif %}
$("#title").hide();
$("#content").hide();
$("#comment").hide();
@ -841,6 +896,23 @@ $(function() {
});
{% endif %}
{% if career_in_global_events %}
$('#simple_career_field').hide();
$('#simple_promotion_field').hide();
$('#simple_career').html();
$('#simple_promotion').html('{{ 'All'|get_lang|escape('js') }}');
if (calEvent.career) {
$('#simple_career_field').show();
$('#simple_promotion_field').show();
$('#simple_career').html(calEvent.career.name);
}
if (calEvent.promotion) {
$('#simple_promotion').html(calEvent.promotion.name);
}
{% endif %}
{% if agenda_collective_invitations and 'personal' == type %}
$('#simple_invitees').html(function () {
if (!calEvent.invitees) {
@ -996,6 +1068,26 @@ $(function() {
<div class="col-sm-offset-3 col-sm-9" id="simple_notification_list"></div>
</div>
{% endif %}
{% if career_in_global_events %}
<div class="form-group" id="simple_career_field">
<label class="col-sm-3 control-label">
<b>{{ "Career" |get_lang}}</b>
</label>
<div class="col-sm-9">
<p class="form-control-static" id="simple_career"></p>
</div>
</div>
<div class="form-group" id="simple_promotion_field">
<label class="col-sm-3 control-label">
<b>{{ "Promotion" |get_lang}}</b>
</label>
<div class="col-sm-9">
<p class="form-control-static" id="simple_promotion"></p>
</div>
</div>
{% endif %}
</form>
</div>

Loading…
Cancel
Save