From 38c0b77c587a4fb13fe8859f0acfb831c4b1e36d Mon Sep 17 00:00:00 2001 From: christian Date: Fri, 12 Jan 2024 22:34:21 -0500 Subject: [PATCH 1/2] Migration: Change tools display_order by resource_node order field --- public/main/inc/lib/groupmanager.lib.php | 57 +++++-------- public/main/inc/lib/link.lib.php | 1 - .../Api/GetGlossaryCollectionController.php | 2 +- .../Api/GetLinksCollectionController.php | 10 +-- .../Controller/Api/UpdatePositionLink.php | 7 +- .../Schema/V200/Version20230615213500.php | 3 +- .../Schema/V200/Version20240112191200.php | 79 +++++++++++++++++++ .../Repository/ResourceRepository.php | 6 +- src/CourseBundle/Entity/CGlossary.php | 19 ----- src/CourseBundle/Entity/CLink.php | 25 ------ src/CourseBundle/Entity/CLinkCategory.php | 17 ---- 11 files changed, 116 insertions(+), 110 deletions(-) create mode 100644 src/CoreBundle/Migrations/Schema/V200/Version20240112191200.php diff --git a/public/main/inc/lib/groupmanager.lib.php b/public/main/inc/lib/groupmanager.lib.php index f9f20a6030..3799dbc7cd 100644 --- a/public/main/inc/lib/groupmanager.lib.php +++ b/public/main/inc/lib/groupmanager.lib.php @@ -723,25 +723,11 @@ class GroupManager } $session = api_get_session_entity(api_get_session_id()); - //$group = api_get_group_entity(api_get_group_id()); $group = null; - $qb = $repo->getResourcesByCourse($course, $session, $group); + $qb = $repo->getResourcesByCourse($course, $session, $group, null, true, true); return $qb->getQuery()->getArrayResult(); - /*$course_info = api_get_course_info($course_code); - $courseId = $course_info['real_id']; - $table = Database::get_course_table(TABLE_GROUP_CATEGORY); - $sql = "SELECT * FROM $table - WHERE c_id = $courseId - ORDER BY display_order"; - $res = Database::query($sql); - $cats = []; - while ($cat = Database::fetch_array($res)) { - $cats[] = $cat; - } - - return $cats;*/ } /** @@ -919,14 +905,6 @@ class GroupManager if (empty($title)) { return false; } - /*$sql = "SELECT MAX(display_order)+1 as new_order - FROM $table - WHERE c_id = $course_id "; - $res = Database::query($sql); - $obj = Database::fetch_object($res); - if (!isset($obj->new_order)) { - $obj->new_order = 1; - }*/ $course = api_get_course_entity(api_get_course_int_id()); $session = api_get_session_entity(api_get_session_id()); @@ -1087,24 +1065,27 @@ class GroupManager */ public static function swap_category_order($id1, $id2) { - $table = Database::get_course_table(TABLE_GROUP_CATEGORY); - $id1 = intval($id1); - $id2 = intval($id2); - $course_id = api_get_course_int_id(); + $em = Database::getManager(); + + $groupCategoryRepo = $em->getRepository(CGroupCategory::class); + $cat1 = $groupCategoryRepo->find($id1); + $cat2 = $groupCategoryRepo->find($id2); - $sql = "SELECT iid, display_order FROM $table - WHERE iid IN ($id1,$id2) AND c_id = $course_id "; - $res = Database::query($sql); - $cat1 = Database::fetch_object($res); - $cat2 = Database::fetch_object($res); if ($cat1 && $cat2) { - $sql = "UPDATE $table SET display_order=$cat2->display_order - WHERE iid = $cat1->id AND c_id = $course_id "; - Database::query($sql); + $node1 = $cat1->getResourceNode(); + $node2 = $cat2->getResourceNode(); - $sql = "UPDATE $table SET display_order=$cat1->display_order - WHERE iid = $cat2->id AND c_id = $course_id "; - Database::query($sql); + if ($node1 && $node2) { + $order1 = $node1->getDisplayOrder(); + $order2 = $node2->getDisplayOrder(); + + $node1->setDisplayOrder($order2); + $node2->setDisplayOrder($order1); + + $em->persist($node1); + $em->persist($node2); + $em->flush(); + } } } diff --git a/public/main/inc/lib/link.lib.php b/public/main/inc/lib/link.lib.php index d9b111f549..5ed73c86ad 100644 --- a/public/main/inc/lib/link.lib.php +++ b/public/main/inc/lib/link.lib.php @@ -35,7 +35,6 @@ class Link extends Model 'title', 'description', 'category_id', - 'display_order', 'on_homepage', 'target', 'session_id', diff --git a/src/CoreBundle/Controller/Api/GetGlossaryCollectionController.php b/src/CoreBundle/Controller/Api/GetGlossaryCollectionController.php index 9dc71360eb..69604688db 100644 --- a/src/CoreBundle/Controller/Api/GetGlossaryCollectionController.php +++ b/src/CoreBundle/Controller/Api/GetGlossaryCollectionController.php @@ -32,7 +32,7 @@ class GetGlossaryCollectionController extends BaseResourceFileAction $session = $em->getRepository(Session::class)->find($sid); } - $qb = $repo->getResourcesByCourse($course, $session); + $qb = $repo->getResourcesByCourse($course, $session, null, null, true, true); if ($q) { $qb->andWhere($qb->expr()->like('resource.name', ':name')) ->setParameter('name', '%'.$q.'%') diff --git a/src/CoreBundle/Controller/Api/GetLinksCollectionController.php b/src/CoreBundle/Controller/Api/GetLinksCollectionController.php index 450d0cfd67..8f41b48b25 100644 --- a/src/CoreBundle/Controller/Api/GetLinksCollectionController.php +++ b/src/CoreBundle/Controller/Api/GetLinksCollectionController.php @@ -36,9 +36,8 @@ class GetLinksCollectionController extends BaseResourceFileAction $session = $em->getRepository(Session::class)->find($sid); } - $qb = $repo->getResourcesByCourse($course, $session); + $qb = $repo->getResourcesByCourse($course, $session, null, null, true , true); $qb->andWhere('resource.category = 0 OR resource.category is null'); - $qb->addOrderBy('resource.displayOrder', 'ASC'); $links = $qb->getQuery()->getResult(); if ($links) { @@ -51,12 +50,12 @@ class GetLinksCollectionController extends BaseResourceFileAction 'url' => $link->getUrl(), 'iid' => $link->getIid(), 'linkVisible' => $link->getFirstResourceLink()->getVisibility(), - 'position' => $link->getDisplayOrder(), + 'position' => $link->getResourceNode()->getDisplayOrder(), ]; } } - $qb = $repoCategory->getResourcesByCourse($course, $session); + $qb = $repoCategory->getResourcesByCourse($course, $session, null, null, true, true); $categories = $qb->getQuery()->getResult(); if ($categories) { /** @var CLinkCategory $category */ @@ -64,7 +63,6 @@ class GetLinksCollectionController extends BaseResourceFileAction $categoryId = $category->getIid(); $qbLink = $repo->getResourcesByCourse($course, $session); $qbLink->andWhere('resource.category = '.$categoryId); - $qbLink->addOrderBy('resource.displayOrder', 'ASC'); $links = $qbLink->getQuery()->getResult(); $categoryInfo = [ @@ -84,7 +82,7 @@ class GetLinksCollectionController extends BaseResourceFileAction 'url' => $link->getUrl(), 'iid' => $link->getIid(), 'linkVisible' => $link->getFirstResourceLink()->getVisibility(), - 'position' => $link->getDisplayOrder(), + 'position' => $link->getResourceNode()->getDisplayOrder(), ]; $dataResponse['categories'][$categoryId]['links'] = $items; diff --git a/src/CoreBundle/Controller/Api/UpdatePositionLink.php b/src/CoreBundle/Controller/Api/UpdatePositionLink.php index 605c42ac17..91b9387108 100644 --- a/src/CoreBundle/Controller/Api/UpdatePositionLink.php +++ b/src/CoreBundle/Controller/Api/UpdatePositionLink.php @@ -21,7 +21,12 @@ class UpdatePositionLink extends AbstractController $requestData = json_decode($request->getContent(), true); $newPosition = (int) $requestData['position']; - $link->setDisplayOrder($newPosition); + $resourceNode = $link->getResourceNode(); + if ($resourceNode) { + $resourceNode->setDisplayOrder($newPosition); + $em->persist($resourceNode); + $em->flush(); + } return $link; } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20230615213500.php b/src/CoreBundle/Migrations/Schema/V200/Version20230615213500.php index 3f35048b00..5c1501cc20 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20230615213500.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20230615213500.php @@ -58,10 +58,11 @@ final class Version20230615213500 extends AbstractMigrationChamilo if ($item) { $item->setDisplayOrder($position); $em->persist($item); - $em->flush(); } } } } + + $em->flush(); } } diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240112191200.php b/src/CoreBundle/Migrations/Schema/V200/Version20240112191200.php new file mode 100644 index 0000000000..3c719f9a4f --- /dev/null +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240112191200.php @@ -0,0 +1,79 @@ +getContainer(); + $doctrine = $container->get('doctrine'); + $em = $doctrine->getManager(); + + /** @var Connection $connection */ + $connection = $em->getConnection(); + + $linkCategoryRepo = $container->get(CLinkCategoryRepository::class); + $linkRepo = $container->get(CLinkRepository::class); + $groupCategoryRepo = $container->get(CGroupCategoryRepository::class); + $glossaryRepo = $container->get(CGlossaryRepository::class); + + $this->updateResourceNodeDisplayOrder($linkCategoryRepo, 'c_link_category', $em); + $this->updateResourceNodeDisplayOrder($linkRepo, 'c_link', $em); + $this->updateResourceNodeDisplayOrder($groupCategoryRepo, 'c_group_category', $em); + $this->updateResourceNodeDisplayOrder($glossaryRepo, 'c_glossary', $em); + + } + + private function updateResourceNodeDisplayOrder($resourceRepo, $tableName, $em) { + + /** @var Connection $connection */ + $connection = $em->getConnection(); + + try { + $testResult = $connection->executeQuery("SELECT display_order FROM $tableName LIMIT 1"); + $columnExists = true; + } catch (\Exception $e) { + $columnExists = false; + } + + if ($columnExists) { + $sql = "SELECT * FROM $tableName ORDER BY display_order"; + $result = $connection->executeQuery($sql); + $resources = $result->fetchAllAssociative(); + + foreach ($resources as $resourceData) { + $resourceId = (int) $resourceData['iid']; + $resourcePosition = (int) $resourceData['display_order']; + + $resource = $resourceRepo->find($resourceId); + if ($resource && $resource->hasResourceNode()) { + $resourceNode = $resource->getResourceNode(); + if ($resourceNode) { + $resourceNode->setDisplayOrder($resourcePosition); + $em->persist($resourceNode); + } + } + } + + $em->flush(); + } + } +} diff --git a/src/CoreBundle/Repository/ResourceRepository.php b/src/CoreBundle/Repository/ResourceRepository.php index 09f728b901..b57b6a84e0 100644 --- a/src/CoreBundle/Repository/ResourceRepository.php +++ b/src/CoreBundle/Repository/ResourceRepository.php @@ -387,12 +387,16 @@ abstract class ResourceRepository extends ServiceEntityRepository return $qb; } - public function getResourcesByCourse(Course $course, Session $session = null, CGroup $group = null, ResourceNode $parentNode = null, bool $displayOnlyPublished = true): QueryBuilder + public function getResourcesByCourse(Course $course, Session $session = null, CGroup $group = null, ResourceNode $parentNode = null, bool $displayOnlyPublished = true, bool $displayOrder = false): QueryBuilder { $qb = $this->getResources($parentNode); $this->addVisibilityQueryBuilder($qb, true, $displayOnlyPublished); $this->addCourseSessionGroupQueryBuilder($course, $session, $group, $qb); + if ($displayOrder) { + $qb->orderBy('node.displayOrder', 'ASC'); + } + return $qb; } diff --git a/src/CourseBundle/Entity/CGlossary.php b/src/CourseBundle/Entity/CGlossary.php index dce8f43f3f..e03d13e3b5 100644 --- a/src/CourseBundle/Entity/CGlossary.php +++ b/src/CourseBundle/Entity/CGlossary.php @@ -197,10 +197,6 @@ class CGlossary extends AbstractResource implements ResourceInterface, Stringabl #[ORM\Column(name: 'description', type: 'text', nullable: false)] protected ?string $description = null; - #[Groups(['glossary:read', 'glossary:write'])] - #[ORM\Column(name: 'display_order', type: 'integer', nullable: true)] - protected ?int $displayOrder = null; - public function __toString(): string { return $this->getName(); @@ -233,21 +229,6 @@ class CGlossary extends AbstractResource implements ResourceInterface, Stringabl return $this->description; } - public function setDisplayOrder(int $displayOrder): self - { - $this->displayOrder = $displayOrder; - - return $this; - } - - /** - * Get displayOrder. - */ - public function getDisplayOrder(): ?int - { - return $this->displayOrder; - } - public function getIid(): ?int { return $this->iid; diff --git a/src/CourseBundle/Entity/CLink.php b/src/CourseBundle/Entity/CLink.php index 3431e2f01f..c2430b3227 100644 --- a/src/CourseBundle/Entity/CLink.php +++ b/src/CourseBundle/Entity/CLink.php @@ -68,7 +68,6 @@ use Symfony\Component\Validator\Constraints as Assert; 'title' => ['type' => 'string'], 'description' => ['type' => 'string'], 'category_id' => ['type' => 'int'], - 'displayOrder' => ['type' => 'integer'], 'target' => ['type' => 'string'], 'parentResourceNodeId' => ['type' => 'integer'], 'resourceLinkList' => [ @@ -135,7 +134,6 @@ use Symfony\Component\Validator\Constraints as Assert; ], )] #[ApiFilter(SearchFilter::class, properties: ['title' => 'partial', 'resourceNode.parent' => 'exact'])] -#[ApiFilter(OrderFilter::class, properties: ['resourceNode.displayOrder'])] #[ORM\Table(name: 'c_link')] #[ORM\Entity(repositoryClass: CLinkRepository::class)] class CLink extends AbstractResource implements ResourceInterface, Stringable @@ -164,13 +162,8 @@ class CLink extends AbstractResource implements ResourceInterface, Stringable #[Groups(['link:read', 'link:write', 'link:browse'])] #[ORM\ManyToOne(targetEntity: CLinkCategory::class, inversedBy: 'links')] #[ORM\JoinColumn(name: 'category_id', referencedColumnName: 'iid', onDelete: 'SET NULL')] - #[Gedmo\SortableGroup] protected ?CLinkCategory $category = null; - #[ORM\Column(name: 'display_order', type: 'integer', nullable: false)] - #[Gedmo\SortablePosition] - protected int $displayOrder; - #[Groups(['link:read', 'link:write', 'link:browse'])] #[ORM\Column(name: 'target', type: 'string', length: 10, nullable: true)] protected ?string $target = null; @@ -180,7 +173,6 @@ class CLink extends AbstractResource implements ResourceInterface, Stringable public function __construct() { - $this->displayOrder = 0; $this->description = ''; } @@ -225,23 +217,6 @@ class CLink extends AbstractResource implements ResourceInterface, Stringable return $this->description; } - public function setDisplayOrder(int $displayOrder): self - { - $this->displayOrder = $displayOrder; - - return $this; - } - - /** - * Get displayOrder. - * - * @return int - */ - public function getDisplayOrder() - { - return $this->displayOrder; - } - public function setTarget(string $target): self { $this->target = $target; diff --git a/src/CourseBundle/Entity/CLinkCategory.php b/src/CourseBundle/Entity/CLinkCategory.php index 8b5985a4d4..a1afbbc84a 100644 --- a/src/CourseBundle/Entity/CLinkCategory.php +++ b/src/CourseBundle/Entity/CLinkCategory.php @@ -147,10 +147,6 @@ class CLinkCategory extends AbstractResource implements ResourceInterface, Strin #[ORM\Column(name: 'description', type: 'text', nullable: true)] protected ?string $description; - #[Groups(['link_category:read', 'link_category:write'])] - #[ORM\Column(name: 'display_order', type: 'integer', nullable: false)] - protected int $displayOrder; - #[Groups(['link_category:read', 'link_category:browse'])] protected bool $linkCategoryVisible = true; @@ -163,7 +159,6 @@ class CLinkCategory extends AbstractResource implements ResourceInterface, Strin public function __construct() { $this->description = ''; - $this->displayOrder = 0; $this->links = new ArrayCollection(); } @@ -201,18 +196,6 @@ class CLinkCategory extends AbstractResource implements ResourceInterface, Strin return $this->description; } - public function setDisplayOrder(int $displayOrder): self - { - $this->displayOrder = $displayOrder; - - return $this; - } - - public function getDisplayOrder(): int - { - return $this->displayOrder; - } - public function toggleVisibility(): void { $this->linkCategoryVisible = !$this->getFirstResourceLink()->getVisibility(); From 62eaaeda781b366230a6c8a219699a5c746f659d Mon Sep 17 00:00:00 2001 From: christianbeeznst Date: Sat, 13 Jan 2024 15:23:50 -0500 Subject: [PATCH 2/2] Migration: Add display_order from resource node to announcements and glossary --- .../vue/components/glossary/GlossaryForm.vue | 4 +- .../components/glossary/GlossaryTermList.vue | 8 +- assets/vue/components/links/LinkItem.vue | 9 ++- assets/vue/views/glossary/GlossaryList.vue | 2 +- assets/vue/views/links/LinksList.vue | 8 +- public/main/announcements/announcements.php | 75 +++++++------------ public/main/inc/lib/AnnouncementManager.php | 23 +++--- public/main/inc/lib/groupmanager.lib.php | 2 - .../Controller/Api/UpdatePositionLink.php | 1 - src/CoreBundle/Entity/SettingsCurrent.php | 2 +- .../Schema/V200/Version20240112191200.php | 4 +- src/CourseBundle/Entity/CAnnouncement.php | 21 ------ 12 files changed, 65 insertions(+), 94 deletions(-) diff --git a/assets/vue/components/glossary/GlossaryForm.vue b/assets/vue/components/glossary/GlossaryForm.vue index dfe2e25691..4e12961b51 100644 --- a/assets/vue/components/glossary/GlossaryForm.vue +++ b/assets/vue/components/glossary/GlossaryForm.vue @@ -117,8 +117,8 @@ const submitGlossaryForm = async () => { } try { - if (props.linkId) { - await glossaryService.updateGlossaryTerm(props.linkId, postData) + if (props.termId) { + await glossaryService.updateGlossaryTerm(props.termId, postData) } else { await glossaryService.createGlossaryTerm(postData) } diff --git a/assets/vue/components/glossary/GlossaryTermList.vue b/assets/vue/components/glossary/GlossaryTermList.vue index f52b355af7..fd99721ea1 100644 --- a/assets/vue/components/glossary/GlossaryTermList.vue +++ b/assets/vue/components/glossary/GlossaryTermList.vue @@ -12,7 +12,7 @@
{{ term.name }}
-
+
store.getters["security/isCurrentTeacher"]) defineProps({ glossaries: { diff --git a/assets/vue/components/links/LinkItem.vue b/assets/vue/components/links/LinkItem.vue index 1421ab8d8c..e818e52efd 100644 --- a/assets/vue/components/links/LinkItem.vue +++ b/assets/vue/components/links/LinkItem.vue @@ -11,7 +11,7 @@
-
+
store.getters["security/isCurrentTeacher"]) const { t } = useI18n() diff --git a/assets/vue/views/glossary/GlossaryList.vue b/assets/vue/views/glossary/GlossaryList.vue index 7ffe623a8a..c1dcfaaf2e 100644 --- a/assets/vue/views/glossary/GlossaryList.vue +++ b/assets/vue/views/glossary/GlossaryList.vue @@ -258,4 +258,4 @@ async function fetchGlossaries() { isSearchLoading.value = false } } - \ No newline at end of file + diff --git a/assets/vue/views/links/LinksList.vue b/assets/vue/views/links/LinksList.vue index a3a8388015..cac430cada 100644 --- a/assets/vue/views/links/LinksList.vue +++ b/assets/vue/views/links/LinksList.vue @@ -94,7 +94,7 @@ />
{{ category.info.name }}
-
+

{{ categoryToDelete.info.name }}

-

{{ t("With links") }}: {{ categoryToDelete.links.map((l) => l.title).join(", ") }}

+

+ {{ t("With links") }}: {{ (categoryToDelete.links || []).map((l) => l.title).join(", ") }} +

@@ -375,4 +377,4 @@ async function fetchLinks() { isLoading.value = false } } - \ No newline at end of file + diff --git a/public/main/announcements/announcements.php b/public/main/announcements/announcements.php index 01c07fa65e..c6e9ea465d 100644 --- a/public/main/announcements/announcements.php +++ b/public/main/announcements/announcements.php @@ -95,66 +95,41 @@ $thisAnnouncementId = null; switch ($action) { case 'move': - throw new Exception('@todo move'); + if (!$allowToEdit) { api_not_allowed(true); } + $em = Database::getManager(); + $repo = Container::getAnnouncementRepository(); + /* Move announcement up/down */ + $thisAnnouncementId = null; + $sortDirection = null; + if (!empty($_GET['down'])) { - $thisAnnouncementId = (int) ($_GET['down']); - $sortDirection = 'DESC'; - } - /* - if (!empty($_GET['up'])) { - $thisAnnouncementId = (int) ($_GET['up']); - $sortDirection = 'ASC'; + $thisAnnouncementId = (int) $_GET['down']; + $sortDirection = 'down'; + } elseif (!empty($_GET['up'])) { + $thisAnnouncementId = (int) $_GET['up']; + $sortDirection = 'up'; } - if (!empty($sortDirection)) { - if (!in_array(trim(strtoupper($sortDirection)), ['ASC', 'DESC'])) { - $sortDirection = 'ASC'; - } + $currentAnnouncement = $repo->find($thisAnnouncementId); + if ($currentAnnouncement) { + $resourceNode = $currentAnnouncement->getResourceNode(); + $currentDisplayOrder = $resourceNode->getDisplayOrder(); - $sql = "SELECT DISTINCT announcement.id, announcement.display_order - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property itemproperty - ON (announcement.c_id = itemproperty.c_id) - WHERE - announcement.c_id = $courseId AND - itemproperty.c_id = $courseId AND - itemproperty.ref = announcement.id AND - itemproperty.tool = '".TOOL_ANNOUNCEMENT."' AND - itemproperty.visibility <> 2 - ORDER BY display_order $sortDirection"; - $result = Database::query($sql); - $thisAnnouncementOrderFound = false; - $thisAnnouncementOrder = null; - - while (list($announcementId, $announcementOrder) = Database::fetch_row($result)) { - if ($thisAnnouncementOrderFound) { - $nextAnnouncementId = $announcementId; - $nextAnnouncementOrder = $announcementOrder; - $sql = "UPDATE $tbl_announcement SET display_order = '$nextAnnouncementOrder' - WHERE c_id = $courseId AND id = $thisAnnouncementId"; - Database::query($sql); - $sql = "UPDATE $tbl_announcement SET display_order = '$thisAnnouncementOrder' - WHERE c_id = $courseId AND id = $nextAnnouncementId"; - Database::query($sql); - break; - } - // STEP 1 : FIND THE ORDER OF THE ANNOUNCEMENT - if ($announcementId == $thisAnnouncementId) { - $thisAnnouncementOrder = $announcementOrder; - $thisAnnouncementOrderFound = true; - } - } - Display::addFlash(Display::return_message(get_lang('The announcement has been moved'))); - header('Location: '.$homeUrl); - exit; - }*/ + $newPosition = $currentDisplayOrder + ($sortDirection === 'down' ? 1 : -1); + $newPosition = max(0, $newPosition); + + $resourceNode->setDisplayOrder($newPosition); + $em->flush(); + } + + header('Location: '.$homeUrl); + exit; - break; case 'view': $interbreadcrumb[] = [ 'url' => api_get_path(WEB_CODE_PATH).'announcements/announcements.php?'.api_get_cidreq(), diff --git a/public/main/inc/lib/AnnouncementManager.php b/public/main/inc/lib/AnnouncementManager.php index 36214aa600..94d2d5aa08 100644 --- a/public/main/inc/lib/AnnouncementManager.php +++ b/public/main/inc/lib/AnnouncementManager.php @@ -1388,7 +1388,7 @@ class AnnouncementManager $group = api_get_group_entity(api_get_group_id()); if (api_is_allowed_to_edit(false, true)) { - $qb = $repo->getResourcesByCourse($course, $session, $group); + $qb = $repo->getResourcesByCourse($course, $session, $group, null, true, true); } else { $user = api_get_user_entity(); if (null === $user) { @@ -1586,19 +1586,22 @@ class AnnouncementManager href=\"".$actionUrl."&action=set_visibility&status=".$setNewStatus."&id=".$announcementId."&sec_token=".$stok."\">" .$iconVisibility.""; - // DISPLAY MOVE UP COMMAND only if it is not the top announcement - if (1 != $iterator) { - $modify_icons .= "" - .$iconUp.''; + // Move up action + if ($iterator == 1) { + $move1 = $iconUpDisabled; } else { - $modify_icons .= $iconUpDisabled; + $move1 = "".$iconUp.""; } - if ($iterator < $bottomAnnouncement) { - $modify_icons .= "" - .$iconDown.''; + $modify_icons .= $move1; + + // Move down action + if ($iterator == 4) { + $move2 = $iconDownDisabled; } else { - $modify_icons .= $iconDownDisabled; + $move2 = "".$iconDown."";; } + $modify_icons .= $move2; + if (api_is_allowed_to_edit(false, true)) { if (true === $disableEdit) { $modify_icons .= $deleteIconDisable; diff --git a/public/main/inc/lib/groupmanager.lib.php b/public/main/inc/lib/groupmanager.lib.php index 3799dbc7cd..3954574cbd 100644 --- a/public/main/inc/lib/groupmanager.lib.php +++ b/public/main/inc/lib/groupmanager.lib.php @@ -1082,8 +1082,6 @@ class GroupManager $node1->setDisplayOrder($order2); $node2->setDisplayOrder($order1); - $em->persist($node1); - $em->persist($node2); $em->flush(); } } diff --git a/src/CoreBundle/Controller/Api/UpdatePositionLink.php b/src/CoreBundle/Controller/Api/UpdatePositionLink.php index 91b9387108..d47a843b5b 100644 --- a/src/CoreBundle/Controller/Api/UpdatePositionLink.php +++ b/src/CoreBundle/Controller/Api/UpdatePositionLink.php @@ -24,7 +24,6 @@ class UpdatePositionLink extends AbstractController $resourceNode = $link->getResourceNode(); if ($resourceNode) { $resourceNode->setDisplayOrder($newPosition); - $em->persist($resourceNode); $em->flush(); } diff --git a/src/CoreBundle/Entity/SettingsCurrent.php b/src/CoreBundle/Entity/SettingsCurrent.php index 4362e285f3..9b6f0befb3 100644 --- a/src/CoreBundle/Entity/SettingsCurrent.php +++ b/src/CoreBundle/Entity/SettingsCurrent.php @@ -123,7 +123,7 @@ class SettingsCurrent return $this->selectedValue; } - public function setSelectedValue(?string $selectedValue): self + public function setSelectedValue(int|float|string|null $selectedValue): self { $this->selectedValue = $selectedValue; diff --git a/src/CoreBundle/Migrations/Schema/V200/Version20240112191200.php b/src/CoreBundle/Migrations/Schema/V200/Version20240112191200.php index 3c719f9a4f..f90c9e394c 100644 --- a/src/CoreBundle/Migrations/Schema/V200/Version20240112191200.php +++ b/src/CoreBundle/Migrations/Schema/V200/Version20240112191200.php @@ -7,6 +7,7 @@ declare(strict_types=1); namespace Chamilo\CoreBundle\Migrations\Schema\V200; use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; +use Chamilo\CourseBundle\Repository\CAnnouncementRepository; use Chamilo\CourseBundle\Repository\CGlossaryRepository; use Chamilo\CourseBundle\Repository\CGroupCategoryRepository; use Chamilo\CourseBundle\Repository\CLinkCategoryRepository; @@ -34,11 +35,13 @@ final class Version20240112191200 extends AbstractMigrationChamilo $linkRepo = $container->get(CLinkRepository::class); $groupCategoryRepo = $container->get(CGroupCategoryRepository::class); $glossaryRepo = $container->get(CGlossaryRepository::class); + $announcementRepo = $container->get(CAnnouncementRepository::class); $this->updateResourceNodeDisplayOrder($linkCategoryRepo, 'c_link_category', $em); $this->updateResourceNodeDisplayOrder($linkRepo, 'c_link', $em); $this->updateResourceNodeDisplayOrder($groupCategoryRepo, 'c_group_category', $em); $this->updateResourceNodeDisplayOrder($glossaryRepo, 'c_glossary', $em); + $this->updateResourceNodeDisplayOrder($announcementRepo, 'c_announcement', $em); } @@ -68,7 +71,6 @@ final class Version20240112191200 extends AbstractMigrationChamilo $resourceNode = $resource->getResourceNode(); if ($resourceNode) { $resourceNode->setDisplayOrder($resourcePosition); - $em->persist($resourceNode); } } } diff --git a/src/CourseBundle/Entity/CAnnouncement.php b/src/CourseBundle/Entity/CAnnouncement.php index c94351a7a3..46df6290e9 100644 --- a/src/CourseBundle/Entity/CAnnouncement.php +++ b/src/CourseBundle/Entity/CAnnouncement.php @@ -35,9 +35,6 @@ class CAnnouncement extends AbstractResource implements ResourceInterface, Strin #[ORM\Column(name: 'end_date', type: 'date', nullable: true)] protected ?DateTime $endDate = null; - #[ORM\Column(name: 'display_order', type: 'integer', nullable: false)] - protected int $displayOrder; - #[ORM\Column(name: 'email_sent', type: 'boolean', nullable: true)] protected ?bool $emailSent = null; @@ -50,7 +47,6 @@ class CAnnouncement extends AbstractResource implements ResourceInterface, Strin public function __construct() { $this->content = ''; - $this->displayOrder = 1; $this->attachments = new ArrayCollection(); } @@ -107,23 +103,6 @@ class CAnnouncement extends AbstractResource implements ResourceInterface, Strin return $this->endDate; } - public function setDisplayOrder(int $displayOrder): self - { - $this->displayOrder = $displayOrder; - - return $this; - } - - /** - * Get displayOrder. - * - * @return int - */ - public function getDisplayOrder() - { - return $this->displayOrder; - } - public function setEmailSent(bool $emailSent): self { $this->emailSent = $emailSent;