Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 97 additions & 2 deletions main/inc/lib/ScheduledAnnouncement.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ public function returnSimpleForm($id, $url, $action, $sessionInfo = [])

$form->addHidden('session_id', $sessionInfo['id']);
$form->addDateTimePicker('date', get_lang('Date'));

$useBaseProgress = api_get_configuration_value('scheduled_announcements_use_base_progress');
if ($useBaseProgress) {
$extraFieldValue = new ExtraFieldValue('scheduled_announcement');
$baseProgress = $extraFieldValue->get_values_by_handler_and_field_variable(
$id,
'use_base_progress'
);
$form->addNumeric ('progress',
get_lang('Progress'),
[
'step' => 1,
'min' => 1,
'max' => 100,
'value' => $baseProgress['value'],
],
true
);
}

$form->addText('subject', get_lang('Subject'));
$form->addHtmlEditor('message', get_lang('Message'));

Expand Down Expand Up @@ -185,6 +205,11 @@ public function returnForm($url, $action, $sessionInfo = [])
$typeOptions['base_date'] = get_lang('BaseDate');
}

$useBaseProgress = api_get_configuration_value('scheduled_announcements_use_base_progress');
if ($useBaseProgress) {
$typeOptions['base_progress'] = get_lang('BaseProgress');
}

$form->addSelect(
'type',
get_lang('Type'),
Expand All @@ -194,16 +219,36 @@ public function returnForm($url, $action, $sessionInfo = [])
if (this.options[this.selectedIndex].value == 'base_date') {
document.getElementById('options').style.display = 'block';
document.getElementById('specific_date').style.display = 'none';
} else {
document.getElementById('base_progress').style.display = 'none';
} else if (this.options[this.selectedIndex].value == 'specific_date') {
document.getElementById('options').style.display = 'none';
document.getElementById('specific_date').style.display = 'block';
document.getElementById('base_progress').style.display = 'none';
} else {
document.getElementById('options').style.display = 'block';
document.getElementById('specific_date').style.display = 'none';
document.getElementById('base_progress').style.display = 'block';
}
", ]
);

$form->addHtml('<div id="specific_date">');
$form->addDateTimePicker('date', get_lang('Date'));
$form->addHtml('</div>');

$form->addHtml('<div id="base_progress" style="display:none">');
$form->addNumeric ('progress',
get_lang('Progress'),
[
'step' => 1,
'min' => 1,
'max' => 100,
'value' => 100,
],
true
);
$form->addHtml('</div>');

$form->addHtml('<div id="options" style="display:none">');

$startDate = $sessionInfo['access_start_date'];
Expand Down Expand Up @@ -344,7 +389,19 @@ public function sendPendingMessages($urlId = 0)
$coachList = array_unique($coachList);
}

$this->update(['id' => $result['id'], 'sent' => 1]);
$useBaseProgress = api_get_configuration_value('scheduled_announcements_use_base_progress');
if ($useBaseProgress) {
$baseProgress = $extraFieldValue->get_values_by_handler_and_field_variable(
$result['id'],
'use_base_progress'
);
if (empty($baseProgress) || empty($baseProgress['value']) || $baseProgress['value'] < 1) {
$this->update(['id' => $result['id'], 'sent' => 1]);
}
} else {
$this->update(['id' => $result['id'], 'sent' => 1]);
}

$attachments = $this->getAttachmentToString($result['id']);
$subject = $result['subject'];

Expand All @@ -371,6 +428,44 @@ public function sendPendingMessages($urlId = 0)
);
}

if ($useBaseProgress) {
$baseProgress = $extraFieldValue->get_values_by_handler_and_field_variable(
$result['id'],
'use_base_progress'
);
if (!empty($baseProgress) && !empty($baseProgress['value']) && $baseProgress['value'] >= 1) {
if ((is_numeric($progress) && $progress > $baseProgress['value']) || !is_numeric($progress)) {
continue;
} else {
$comment = json_decode($baseProgress['comment'], true);
if ($comment !== null && is_array($comment)) {
if (isset($comment['sended']) && is_array($comment['sended'])) {
$userFound = false;
foreach ($comment['sended'] as $item) {
if (isset($item['user']) && $item['user'] === $user['user_id']) {
$userFound = true;
break;
}
}
if ($userFound) {
continue;
} else {
$comment['sended'][] = ['user' => $user['user_id'], 'send_date' => time(), 'progress_user' => $progress, 'progress_mark' => $baseProgress['value']];
$newExtraFieldParams = $baseProgress;
$newExtraFieldParams['comment'] = json_encode($comment);
$extraFieldValue->save($newExtraFieldParams);
}
}
} else {
$comment['sended'][] = ['user' => $user['user_id'], 'send_date' => time(), 'progress_user' => $progress, 'progress_mark' => $baseProgress['value']];
$newExtraFieldParams = $baseProgress;
$newExtraFieldParams['comment'] = json_encode($comment);
$extraFieldValue->save($newExtraFieldParams);
}
}
}
}

if (is_numeric($progress)) {
$progress = $progress.'%';
} else {
Expand Down
3 changes: 3 additions & 0 deletions main/install/configuration.dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,9 @@
'[email protected]',
]
];*/
// Add a new type of scheduled announcement, based on user course session progress
// Requires a "use_base_progress" extra field in: main/admin/extra_fields.php?type=scheduled_announcement&action=add
//$_configuration['scheduled_announcements_use_base_progress'] = false;
// Allow ticket projects to be access by specific chamilo roles
/*$_configuration['ticket_project_user_roles'] = [
'permissions' => [
Expand Down
13 changes: 13 additions & 0 deletions main/session/scheduled_announcement.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
$values = $form->getSubmitValues();
switch ($values['type']) {
case 'base_date':
case 'base_progress':
$numberDays = (int) $values['days'];
switch ($values['base_date']) {
case 'start_date':
Expand All @@ -81,6 +82,11 @@
break;
}
$values['date'] = $newDate->format('Y-m-d h:i:s');

if ($values['type'] == 'base_progress') {
$values['extra_use_base_progress'] = $values['progress'];
}

break;
case 'specific_date':
$values['date'] = api_get_utc_datetime($values['date']);
Expand Down Expand Up @@ -131,7 +137,14 @@
$values['date'] = api_get_utc_datetime($values['date']);
$res = $object->update($values);

$values['extra_use_base_progress'] = $values['progress'];
$extraFieldValue = new ExtraFieldValue('scheduled_announcement');
$baseProgress = $extraFieldValue->get_values_by_handler_and_field_variable(
$id,
'use_base_progress'
);
$values['extra_use_base_progress_comment'] = $baseProgress["comment"];

$values['item_id'] = $id;
$extraFieldValue->saveFieldValues($values);

Expand Down
Loading