Migration: Add display_order from resource node to announcements and glossary

pull/5061/head
christianbeeznst 11 months ago
parent 38c0b77c58
commit 62eaaeda78
  1. 4
      assets/vue/components/glossary/GlossaryForm.vue
  2. 8
      assets/vue/components/glossary/GlossaryTermList.vue
  3. 9
      assets/vue/components/links/LinkItem.vue
  4. 2
      assets/vue/views/glossary/GlossaryList.vue
  5. 8
      assets/vue/views/links/LinksList.vue
  6. 75
      public/main/announcements/announcements.php
  7. 23
      public/main/inc/lib/AnnouncementManager.php
  8. 2
      public/main/inc/lib/groupmanager.lib.php
  9. 1
      src/CoreBundle/Controller/Api/UpdatePositionLink.php
  10. 2
      src/CoreBundle/Entity/SettingsCurrent.php
  11. 4
      src/CoreBundle/Migrations/Schema/V200/Version20240112191200.php
  12. 21
      src/CourseBundle/Entity/CAnnouncement.php

@ -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)
}

@ -12,7 +12,7 @@
<div>
{{ term.name }}
</div>
<div>
<div v-if="securityStore.isAuthenticated && isCurrentTeacher">
<BaseButton
:label="t('Edit')"
class="mr-2"
@ -50,8 +50,14 @@
import BaseButton from "../basecomponents/BaseButton.vue"
import { useI18n } from "vue-i18n"
import BaseCard from "../basecomponents/BaseCard.vue"
import { useSecurityStore } from "../../store/securityStore"
import { useStore } from "vuex"
import { computed } from "vue"
const { t } = useI18n()
const securityStore = useSecurityStore()
const store = useStore()
const isCurrentTeacher = computed(() => store.getters["security/isCurrentTeacher"])
defineProps({
glossaries: {

@ -11,7 +11,7 @@
</a>
</h6>
</div>
<div class="flex gap-2">
<div class="flex gap-2" v-if="securityStore.isAuthenticated && isCurrentTeacher">
<BaseButton
type="black"
icon="check"
@ -63,6 +63,13 @@ import BaseButton from "../basecomponents/BaseButton.vue"
import { useI18n } from "vue-i18n"
import BaseIcon from "../basecomponents/BaseIcon.vue"
import { isVisible, VISIBLE } from "./linkVisibility"
import { useSecurityStore } from "../../store/securityStore"
import { useStore } from "vuex"
import { computed } from "vue"
const store = useStore()
const securityStore = useSecurityStore()
const isCurrentTeacher = computed(() => store.getters["security/isCurrentTeacher"])
const { t } = useI18n()

@ -258,4 +258,4 @@ async function fetchGlossaries() {
isSearchLoading.value = false
}
}
</script>
</script>

@ -94,7 +94,7 @@
/>
<h5>{{ category.info.name }}</h5>
</div>
<div class="flex gap-2">
<div class="flex gap-2" v-if="securityStore.isAuthenticated && isCurrentTeacher">
<BaseButton
:label="t('Edit')"
icon="edit"
@ -156,7 +156,9 @@
>
<div v-if="categoryToDelete">
<p class="mb-2 font-semibold">{{ categoryToDelete.info.name }}</p>
<p>{{ t("With links") }}: {{ categoryToDelete.links.map((l) => l.title).join(", ") }}</p>
<p>
{{ t("With links") }}: {{ (categoryToDelete.links || []).map((l) => l.title).join(", ") }}
</p>
</div>
</BaseDialogDelete>
</div>
@ -375,4 +377,4 @@ async function fetchLinks() {
isLoading.value = false
}
}
</script>
</script>

@ -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(),

@ -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."</a>";
// DISPLAY MOVE UP COMMAND only if it is not the top announcement
if (1 != $iterator) {
$modify_icons .= "<a href=\"".$actionUrl."&action=move&up=".$announcementId."&sec_token=".$stok."\">"
.$iconUp.'</a>';
// Move up action
if ($iterator == 1) {
$move1 = $iconUpDisabled;
} else {
$modify_icons .= $iconUpDisabled;
$move1 = "<a href=\"".$actionUrl."&action=move&up=".$announcementId."&sec_token=".$stok."\">".$iconUp."</a>";
}
if ($iterator < $bottomAnnouncement) {
$modify_icons .= "<a href=\"".$actionUrl."&action=move&down=".$announcementId."&sec_token=".$stok."\">"
.$iconDown.'</a>';
$modify_icons .= $move1;
// Move down action
if ($iterator == 4) {
$move2 = $iconDownDisabled;
} else {
$modify_icons .= $iconDownDisabled;
$move2 = "<a href=\"".$actionUrl."&action=move&down=".$announcementId."&sec_token=".$stok."\">".$iconDown."</a>";;
}
$modify_icons .= $move2;
if (api_is_allowed_to_edit(false, true)) {
if (true === $disableEdit) {
$modify_icons .= $deleteIconDisable;

@ -1082,8 +1082,6 @@ class GroupManager
$node1->setDisplayOrder($order2);
$node2->setDisplayOrder($order1);
$em->persist($node1);
$em->persist($node2);
$em->flush();
}
}

@ -24,7 +24,6 @@ class UpdatePositionLink extends AbstractController
$resourceNode = $link->getResourceNode();
if ($resourceNode) {
$resourceNode->setDisplayOrder($newPosition);
$em->persist($resourceNode);
$em->flush();
}

@ -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;

@ -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);
}
}
}

@ -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;

Loading…
Cancel
Save