Internal: Refactor add announcement function

pull/3466/head
Julio Montoya 4 years ago
parent d528506d14
commit a638fef9aa
  1. 24
      public/main/inc/lib/AnnouncementManager.php

@ -780,43 +780,31 @@ class AnnouncementManager
) {
$courseInfo = api_get_course_info();
// Database definitions
$table = Database::get_course_table(TABLE_ANNOUNCEMENT);
$order = self::getLastAnnouncementOrder($courseInfo);
$now = api_get_utc_datetime();
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
$authorId = api_get_user_id();
$course = api_get_course_entity($courseId);
$announcement = new CAnnouncement();
$announcement
->setCId($courseId)
->setContent($newContent)
->setTitle($title)
->setEndDate(new DateTime($now))
->setDisplayOrder($order)
->setSessionId($sessionId)
;
$repo = Container::getAnnouncementRepository();
$repo->addResourceToCourse(
$announcement,
ResourceLink::VISIBILITY_PUBLISHED,
api_get_user_entity($authorId),
api_get_course_entity($courseId),
->setParent($course)
->addCourseLink(
$course,
api_get_session_entity($sessionId),
api_get_group_entity()
);
$repo = Container::getAnnouncementRepository();
$repo->getEntityManager()->flush();
$last_id = $announcement->getIid();
// Store the attach file
if ($last_id) {
$sql = "UPDATE $table SET id = iid
WHERE iid = $last_id";
Database::query($sql);
if (!empty($file)) {
self::add_announcement_attachment_file(
$announcement,

Loading…
Cancel
Save