@ -2,6 +2,9 @@
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\SysAnnouncement;
use Chamilo\CoreBundle\Framework\Container;
/**
* This page allows the administrator to manage the system announcements.
*/
@ -24,11 +27,13 @@ $allowCareers = api_get_configuration_value('allow_careers_in_global_announcemen
// Setting breadcrumbs.
$interbreadcrumb[] = [
"url" => 'index.php',
"name" => get_lang('Administration'),
'url' => 'index.php',
'name' => get_lang('Administration'),
];
$visibleList = SystemAnnouncementManager::getVisibilityList();
$repo = Container::getSysAnnouncementRepository();
$visibleList = $repo->getVisibilityList();
$tool_name = null;
if (empty($_GET['lang'])) {
@ -136,30 +141,27 @@ switch ($action) {
break;
case 'edit':
// Edit an announcement.
$announcement = SystemAnnouncementManager::get_announcement($_GET['id']);
$values['id'] = $announcement->id;
$values['title'] = $announcement->title;
$values['content'] = $announcement->content;
$values['start'] = api_get_local_time($announcement->date_start);
$values['end'] = api_get_local_time($announcement->date_end);
$values['range'] = substr(api_get_local_time($announcement->date_start), 0, 16).' / '.
substr(api_get_local_time($announcement->date_end), 0, 16);
$data = (array) $announcement;
foreach ($visibleList as $key => $value) {
if (isset($data[$key])) {
$values[$key] = $data[$key];
}
}
/** @var SysAnnouncement $announcement */
$announcement = $repo->find($_GET['id']);
$values['id'] = $announcement->getId();
$values['title'] = $announcement->getTitle();
$values['content'] = $announcement->getContent();
$values['start'] = api_get_local_time($announcement->getDateStart());
$values['end'] = api_get_local_time($announcement->getDateEnd());
$values['range'] = substr(api_get_local_time($announcement->getDateStart()), 0, 16).' / '.
substr(api_get_local_time($announcement->getDateEnd()), 0, 16);
$values['roles'] = $announcement->getRoles();
if ($allowCareers) {
$values['career_id'] = $announcement->career_id ;
$values['promotion_id'] = $announcement->promotion_id ;
$values['career_id'] = $announcement->getCareer() ? $announcement->getCareer()->getId() : 0;
$values['promotion_id'] = $announcement->getPromotion() ? $announcement->getPromotion() : 0;
}
$values['lang'] = $announcement->lang ;
$values['lang'] = $announcement->getLang() ;
$values['action'] = 'edit';
$groups = SystemAnnouncementManager::get_announcement_groups($announcement->id );
$values['group'] = isset($groups['group_id']) ? $groups['group_id'] : 0;
$groups = SystemAnnouncementManager::get_announcement_groups($announcement->getId() );
$values['group'] = $groups['group_id'] ?? 0;
$action_todo = true;
break;
}
@ -276,7 +278,6 @@ if ($action_todo) {
error_log($e);
}
$group = [];
foreach ($visibleList as $key => $name) {
$group[] = $form->createElement(
@ -287,7 +288,9 @@ if ($action_todo) {
);
}
$form->addGroup($group, null, get_lang('Visible'));
//$form->addGroup($group, null, get_lang('Visible'));
$form->addSelect('roles', get_lang('Visible'), $visibleList, ['multiple' => 'multiple']);
$form->addElement('hidden', 'id');
$userGroup = new UserGroupModel();
$group_list = $userGroup->get_all();
@ -303,7 +306,7 @@ if ($action_todo) {
);
}
$values['group'] = isset($values['group']) ? $values['group'] : '0';
$values['group'] = $values['group'] ?? '0';
$form->addElement('checkbox', 'send_mail', null, get_lang('Send mail'));
if ('add' === $action) {
@ -322,19 +325,19 @@ if ($action_todo) {
if ($form->validate()) {
$values = $form->getSubmitValues();
$visibilityResult = [];
/* $visibilityResult = [];
foreach ($visibleList as $key => $value) {
if (!isset($values[$key])) {
$values[$key] = false;
}
$visibilityResult[$key] = (int) $values[$key];
}
}*/
if ('all' === $values['lang']) {
$values['lang'] = null;
}
$sendMail = isset($values['send_mail']) ? $values['send_mail'] : null;
$sendMail = $values['send_mail'] ?? null;
switch ($values['action']) {
case 'add':
@ -343,7 +346,7 @@ if ($action_todo) {
$values['content'],
$values['range_start'],
$values['range_end'],
$visibilityResult ,
$values['roles'] ,
$values['lang'],
$sendMail,
empty($values['add_to_calendar']) ? false : true,
@ -378,7 +381,7 @@ if ($action_todo) {
break;
case 'edit':
$sendMailTest = isset($values['send_email_test']) ? $values['send_email_test'] : null;
$sendMailTest = $values['send_email_test'] ?? null;
if (SystemAnnouncementManager::update_announcement(
$values['id'],
@ -386,24 +389,25 @@ if ($action_todo) {
$values['content'],
$values['range_start'],
$values['range_end'],
$visibilityResult ,
$values['roles'] ,
$values['lang'],
$sendMail,
$sendMailTest
)) {
$deletePicture = isset($values['delete_picture']) ? $values['delete_picture'] : '';
$deletePicture = $values['delete_picture'] ?? '';
if ($deletePicture) {
SystemAnnouncementManager::deleteAnnouncementPicture($values['id']);
} else {
$picture = $_FILES['picture'];
// @todo
/*$picture = $_FILES['picture'];
if (!empty($picture['name'])) {
$picture_uri = SystemAnnouncementManager::update_announcements_picture(
$values['id'],
$picture['tmp_name'],
$values['picture_crop_result']
);
}
}*/
}
if (isset($values['group'])) {
@ -434,32 +438,38 @@ if ($action_todo) {
}
if ($show_announcement_list) {
$announcements = SystemAnnouncementManager :: get_all_announcements();
$criteria = [ 'url' => api_get_url_entity()];
$announcements = $repo->findBy($criteria);
$announcement_data = [];
foreach ($announcements as $index => $announcement) {
/** @var SysAnnouncement $announcement */
foreach ($announcements as $announcement) {
$row = [];
$row[] = $announcement->id;
$row[] = Display::return_icon(($announcement->visible ? 'accept.png' : 'exclamation.png'), ($announcement->visible ? get_lang('The announcement is available') : get_lang('The announcement is not available')));
$row[] = $announcement->title;
$row[] = api_convert_and_format_date($announcement->date_start);
$row[] = api_convert_and_format_date($announcement->date_end);
$data = (array) $announcement;
foreach ($visibleList as $key => $value) {
$row[] = $announcement->getId();
$row[] = Display::return_icon(($announcement->isVisible() ? 'accept.png' : 'exclamation.png'), ($announcement->isVisible() ? get_lang('The announcement is available') : get_lang('The announcement is not available')));
$row[] = $announcement->getTitle();
$row[] = api_convert_and_format_date($announcement->getDateStart());
$row[] = api_convert_and_format_date($announcement->getDateEnd());
//$data = (array) $announcement;
$roles = [];
/*foreach ($visibleList as $key => $value) {
$value = $data[$key];
$action = $value ? 'make_invisible' : 'make_visible';
$row[] = "< a href = \"?id=".$announcement- > id."& person=".$key."& action=".$action."\">".
Display::return_icon(($value ? 'eyes.png' : 'eyes-close.png'), get_lang('Show/Hide'))."< / a > ";
}
}*/
$row[] = implode(', ', $announcement->getRoles());
/*$row[] = "< a href = \"?id=".$announcement- > id."& person=".SystemAnnouncementManager::VISIBLE_TEACHER."& action=".($announcement->visible_teacher ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_teacher ? 'eyes.png' : 'eyes-close.png'), get_lang('Show/Hide'))."< / a > ";
$row[] = "< a href = \"?id=".$announcement- > id."& person=".SystemAnnouncementManager::VISIBLE_STUDENT."& action=".($announcement->visible_student ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_student ? 'eyes.png' : 'eyes-close.png'), get_lang('Show/Hide'))."< / a > ";
$row[] = "< a href = \"?id=".$announcement- > id."& person=".SystemAnnouncementManager::VISIBLE_GUEST."& action=".($announcement->visible_guest ? 'make_invisible' : 'make_visible')."\">".Display::return_icon(($announcement->visible_guest ? 'eyes.png' : 'eyes-close.png'), get_lang('Show/Hide'))."< / a > ";*/
$row[] = $announcement->lang ;
$row[] = "< a href = \"?action=edit&id=".$announcement- > id ."\">".
$row[] = $announcement->getLang() ;
$row[] = "< a href = \"?action=edit&id=".$announcement- > getId() ."\">".
Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_SMALL)."< / a >
< a
href=\"?action=delete& id=".$announcement->id ."\"
href=\"?action=delete& id=".$announcement->getId() ."\"
title=".addslashes(api_htmlentities(get_lang('Please confirm your choice')))." class='delete-swal' >".
Display::return_icon('delete.png', get_lang('Delete'), [], ICON_SIZE_SMALL).
"< / a > ";
@ -471,12 +481,13 @@ if ($show_announcement_list) {
$table->set_header(2, get_lang('Title'));
$table->set_header(3, get_lang('Start'));
$table->set_header(4, get_lang('End'));
$table->set_header(5, get_lang('Roles'));
$count = 5 ;
foreach ($visibleList as $key => $title) {
$count = 6 ;
/* foreach ($visibleList as $key => $title) {
$table->set_header($count, $title);
$count++;
}
}*/
$table->set_header($count++, get_lang('Language'));
$table->set_header($count++, get_lang('Edit'), false, 'width="50px"');