From 2c308e1507de64d26acec155b4ffd5dc2fbae82c Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Mon, 27 Jan 2020 16:08:44 +0100 Subject: [PATCH] Announcements: Use resource node to CRUD (WIP) --- public/main/announcements/announcements.php | 48 +-- public/main/inc/ajax/announcement.ajax.php | 17 +- public/main/inc/lib/AnnouncementEmail.php | 97 ++----- public/main/inc/lib/AnnouncementManager.php | 273 ++++++++---------- .../Repository/ResourceRepository.php | 4 +- 5 files changed, 189 insertions(+), 250 deletions(-) diff --git a/public/main/announcements/announcements.php b/public/main/announcements/announcements.php index 2333abf0e6..d3c0656a8f 100644 --- a/public/main/announcements/announcements.php +++ b/public/main/announcements/announcements.php @@ -2,6 +2,9 @@ /* For licensing terms, see /license.txt */ +use Chamilo\CoreBundle\Framework\Container; +use Chamilo\CourseBundle\Entity\CAnnouncement; + /** * @author Frederik Vermeire , UGent Internship * @author Patrick Cool , Ghent University: code cleaning @@ -12,7 +15,6 @@ * as there was no title field (the title was merged into the content field) */ -// use anonymous mode when accessing this course tool $use_anonymous = true; require_once __DIR__.'/../inc/global.inc.php'; @@ -28,6 +30,7 @@ $group_id = api_get_group_id(); $current_course_tool = TOOL_ANNOUNCEMENT; $this_section = SECTION_COURSES; $nameTools = get_lang('Announcements'); +$repo = Container::getAnnouncementRepository(); $allowToEdit = ( api_is_allowed_to_edit(false, true) || @@ -110,7 +113,7 @@ switch ($action) { } $sql = "SELECT DISTINCT announcement.id, announcement.display_order - FROM $tbl_announcement announcement + FROM $tbl_announcement announcement INNER JOIN $tbl_item_property itemproperty ON (announcement.c_id = itemproperty.c_id) WHERE @@ -494,14 +497,15 @@ switch ($action) { $announcement_to_modify = ''; } - $announcementInfo = []; + $announcementInfo = null; if (!empty($id)) { - $announcementInfo = AnnouncementManager::get_by_id($courseId, $id); + /** @var CAnnouncement $announcementInfo */ + $announcementInfo = $repo->find($id); } $showSubmitButton = true; if (!empty($announcementInfo)) { - $to = AnnouncementManager::loadEditUsers('announcement', $id); + $to = AnnouncementManager::loadEditUsers($announcementInfo); if (!empty($group_id)) { $separated = CourseManager::separateUsersGroups($to); @@ -513,9 +517,9 @@ switch ($action) { } $defaults = [ - 'title' => $announcementInfo['title'], - 'content' => $announcementInfo['content'], - 'id' => $announcementInfo['id'], + 'title' => $announcementInfo->getTitle(), + 'content' => $announcementInfo->getContent(), + 'id' => $announcementInfo->getIid(), 'users' => $to, ]; } else { @@ -530,22 +534,22 @@ switch ($action) { $form->addHtml("