ScheduledAnnouncement - get extra field image from asset

pull/3768/head
Julio Montoya 5 years ago
parent a7b2fe9fc9
commit bcbfeb7d1f
  1. 45
      public/main/inc/lib/ScheduledAnnouncement.php
  2. 7
      public/main/inc/lib/extra_field_value.lib.php

@ -3,19 +3,11 @@
/* For licensing terms, see /license.txt */
/**
* Class ScheduledAnnouncement
* Requires DB change:.
*
* CREATE TABLE scheduled_announcements (id INT AUTO_INCREMENT NOT NULL, subject VARCHAR(255) NOT NULL, message LONGTEXT NOT NULL, date DATETIME DEFAULT NULL, sent TINYINT(1) NOT NULL, session_id INT NOT NULL, c_id INT DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
*
* Config setting:
* $_configuration['allow_scheduled_announcements'] = true;
*
* Setup linux cron file:
* main/cron/scheduled_announcement.php
*
* Requires:
* composer update
*/
class ScheduledAnnouncement extends Model
{
@ -124,7 +116,7 @@ class ScheduledAnnouncement extends Model
$form->addCheckBox('sent', null, get_lang('Message Sent'));
if ('edit' == $action) {
if ('edit' === $action) {
$form->addButtonUpdate(get_lang('Edit'));
}
@ -147,7 +139,7 @@ class ScheduledAnnouncement extends Model
// Setting the form elements
$header = get_lang('Add');
if ('edit' == $action) {
if ('edit' === $action) {
$header = get_lang('Edit');
}
@ -158,10 +150,14 @@ class ScheduledAnnouncement extends Model
);
$form->addHeader($header);
if ('add' == $action) {
if ('add' === $action) {
$form->addHtml(
Display::return_message(
nl2br(get_lang('This form allows scheduling announcements to be sent automatically to the students who are taking a course in a session.')),
nl2br(
get_lang(
'This form allows scheduling announcements to be sent automatically to the students who are taking a course in a session.'
)
),
'normal',
false
)
@ -190,7 +186,7 @@ class ScheduledAnnouncement extends Model
get_lang('Type'),
$typeOptions,
[
'onchange' => "javascript:
'onchange' => "javascript:
if (this.options[this.selectedIndex].value == 'base_date') {
document.getElementById('options').style.display = 'block';
document.getElementById('specific_date').style.display = 'none';
@ -243,10 +239,9 @@ class ScheduledAnnouncement extends Model
$extra = $extraField->addElements($form);
$js = $extra['jquery_ready_content'];
$form->addHtml("<script> $(function() { $js }); </script> ");
$this->setTagsInForm($form);
if ('edit' == $action) {
if ('edit' === $action) {
$form->addButtonUpdate(get_lang('Edit'));
} else {
$form->addButtonCreate(get_lang('Add'));
@ -264,9 +259,9 @@ class ScheduledAnnouncement extends Model
{
$file = $this->getAttachment($id);
if (!empty($file) && !empty($file['value'])) {
$url = api_get_path(WEB_UPLOAD_PATH).$file['value'];
$url = $file['url'];
return get_lang('Attachment').': '.Display::url(basename($file['value']), $url, ['target' => '_blank']);
return get_lang('Attachment').': '.Display::url(basename($file['url']), $url, ['target' => '_blank']);
}
return '';
@ -280,9 +275,8 @@ class ScheduledAnnouncement extends Model
public function getAttachment($id)
{
$extraFieldValue = new ExtraFieldValue('scheduled_announcement');
$attachment = $extraFieldValue->get_values_by_handler_and_field_variable($id, 'attachment');
return $attachment;
return $extraFieldValue->get_values_by_handler_and_field_variable($id, 'attachment');
}
/**
@ -420,7 +414,8 @@ class ScheduledAnnouncement extends Model
);
}
$message = get_lang('You\'re receiving a copy because, you\'re a course coach').'<br /><br />'.$message;
$message = get_lang('You\'re receiving a copy because, you\'re a course coach').
'<br /><br />'.$message;
foreach ($coachList as $courseCoachId) {
MessageManager::send_message_simple(
@ -431,7 +426,6 @@ class ScheduledAnnouncement extends Model
);
}
}
$messagesSent++;
}
}
@ -445,7 +439,7 @@ class ScheduledAnnouncement extends Model
*/
public function getTags()
{
$tags = [
return [
'((session_name))',
'((session_start_date))',
'((session_end_date))',
@ -456,8 +450,6 @@ class ScheduledAnnouncement extends Model
'((user_last_name))',
'((lp_progress))',
];
return $tags;
}
/**
@ -468,10 +460,7 @@ class ScheduledAnnouncement extends Model
return api_get_configuration_value('allow_scheduled_announcements');
}
/**
* @param FormValidator $form
*/
private function setTagsInForm(&$form)
private function setTagsInForm(FormValidator $form)
{
$form->addLabel(
get_lang('Tags'),

@ -727,7 +727,8 @@ class ExtraFieldValue extends Model
if (Database::num_rows($result)) {
$result = Database::fetch_array($result, 'ASSOC');
if ($transform) {
if (ExtraField::FIELD_TYPE_DOUBLE_SELECT == $result['field_type']) {
$fieldType = $result['field_type'];
if (ExtraField::FIELD_TYPE_DOUBLE_SELECT == $fieldType) {
if (!empty($result['value'])) {
$field_option = new ExtraFieldOption($this->type);
$options = explode('::', $result['value']);
@ -739,7 +740,7 @@ class ExtraFieldValue extends Model
}
}
}
if (ExtraField::FIELD_TYPE_SELECT_WITH_TEXT_FIELD == $result['field_type']) {
if (ExtraField::FIELD_TYPE_SELECT_WITH_TEXT_FIELD == $fieldType) {
if (!empty($result['value'])) {
$options = explode('::', $result['value']);
$field_option = new ExtraFieldOption($this->type);
@ -751,7 +752,7 @@ class ExtraFieldValue extends Model
}
}
}
if (ExtraField::FIELD_TYPE_TRIPLE_SELECT == $result['field_type']) {
if (ExtraField::FIELD_TYPE_TRIPLE_SELECT == $fieldType) {
if (!empty($result['value'])) {
$optionIds = explode(';', $result['value']);
$optionValues = [];

Loading…
Cancel
Save