Internal: Move display_order from ResourceNode to ResourceLink (#5143)
* Internal: Move display_order from ResourceNode to ResourceLink #5137 * Internal: Use ResourceLink $displayOrder instead of ResourceNode $displayOrder #5137 * Internal: Remove ResourceNode $displayOrder #5137 * Vendor: Bump stof/doctrine-extensions-bundle version to 1.10 #5137 * Forum: Fix query to get forums in category ordered by resourceLink.displayOrder * LP: Refactoring delete method to mark the resource link as deleted instead of remove the lp as resource * LP: Fix query to set a custom order in lp list * LP: Fix buttons to sort learn paths * Rename ResourceNode::getResourceLinkByTypeGroup to ResourceNode::getResourceLinkByContext and change order or its params * LP: Change display resource link display order when moving category position * LP: Fix layout for old list view * Forum: Fix sorting for forums and categories * Course Progress: Fix sorting for sections * Internal: Enable SoftDeleteable for ResourceLink entities * Remove ResourceLink::VISIBILITY_DELETED in favor of soft delete * Internal: Refactoring migration about display_order in course tools * LP: Refactoring the category delete method to make a soft delete of the resource link * LP: Refactoring the thematic delete method to make a soft delete of the resource link * LP: Refactoring the forum delete methods to make a soft delete of the resource link * Add shortcut method to remove resource link from its resource * CI: Fix ResourceNodeRepositoryTest by adding a link to the resource node * Internal: Migration: Drop display_order column from c_lp table * Internal: Migration: Drop position column from c_lp_category table * Internal: Migration: Drop cat_order column from c_forum_category table * Internal: Migration: Drop forum_order column from c_forum_forum table * Internal: Migration: Drop display_order column from c_thematic table * Minor: Format code * Announcement: Fix order of the course announcements * Internal: Refactoring migration * Internal: Migration: Drop display_order column from c_glossary table * Refactoring method to move display order of resource linkspull/5244/head
parent
eb59045868
commit
054905286b
@ -0,0 +1,42 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Chamilo\CoreBundle\Migrations\Schema\V200; |
||||
|
||||
use Chamilo\CoreBundle\Migrations\AbstractMigrationChamilo; |
||||
use Doctrine\DBAL\Schema\Schema; |
||||
|
||||
class Version20240313111800 extends AbstractMigrationChamilo |
||||
{ |
||||
private array $changes = [ |
||||
'c_lp' => 'display_order', |
||||
'c_lp_category' => 'position', |
||||
'c_forum_category' => 'cat_order', |
||||
'c_forum_forum' => 'forum_order', |
||||
'c_thematic' => 'display_order', |
||||
'c_announcement' => 'display_order', |
||||
'c_glossary' => 'display_order', |
||||
]; |
||||
|
||||
public function getDescription(): string |
||||
{ |
||||
$tables = array_keys($this->changes); |
||||
$columns = array_values($this->changes); |
||||
|
||||
return sprintf( |
||||
'Removing %s columns from % tables', |
||||
implode(', ', $columns), |
||||
implode(', ', $tables) |
||||
); |
||||
} |
||||
|
||||
public function up(Schema $schema): void |
||||
{ |
||||
foreach ($this->changes as $table => $column) { |
||||
$this->addSql("ALTER TABLE $table DROP $column"); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,53 @@ |
||||
<?php |
||||
|
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
declare(strict_types=1); |
||||
|
||||
namespace Chamilo\CoreBundle\Repository; |
||||
|
||||
use Chamilo\CoreBundle\Entity\AbstractResource; |
||||
use Chamilo\CoreBundle\Entity\Course; |
||||
use Chamilo\CoreBundle\Entity\ResourceLink; |
||||
use Chamilo\CoreBundle\Entity\Session; |
||||
use Chamilo\CoreBundle\Entity\User; |
||||
use Chamilo\CoreBundle\Entity\Usergroup; |
||||
use Chamilo\CourseBundle\Entity\CGroup; |
||||
use Doctrine\ORM\EntityManagerInterface; |
||||
use Gedmo\Sortable\Entity\Repository\SortableRepository; |
||||
|
||||
class ResourceLinkRepository extends SortableRepository |
||||
{ |
||||
public function __construct(EntityManagerInterface $em) |
||||
{ |
||||
parent::__construct($em, $em->getClassMetadata(ResourceLink::class)); |
||||
} |
||||
|
||||
public function remove(ResourceLink $resourceLink): void |
||||
{ |
||||
$em = $this->getEntityManager(); |
||||
|
||||
// To move the resource link at the end to reorder the list |
||||
$resourceLink->setDisplayOrder(-1); |
||||
|
||||
$em->flush(); |
||||
// soft delete handled by Gedmo\SoftDeleteable |
||||
$em->remove($resourceLink); |
||||
$em->flush(); |
||||
} |
||||
|
||||
public function removeByResourceInContext( |
||||
AbstractResource $resource, |
||||
Course $course, |
||||
?Session $session = null, |
||||
?CGroup $group = null, |
||||
?Usergroup $usergroup = null, |
||||
?User $user = null, |
||||
): void { |
||||
$link = $resource->getResourceNode()->getResourceLinkByContext($course, $session, $group, $usergroup, $user); |
||||
|
||||
if ($link) { |
||||
$this->remove($link); |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue