Internal: Refactor add announcement function

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

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

Loading…
Cancel
Save