|
3 | 3 | /* For licensing terms, see /license.txt */
|
4 | 4 |
|
5 | 5 | use Chamilo\CoreBundle\Entity\AccessUrl;
|
| 6 | +use Chamilo\CoreBundle\Entity\AccessUrlRelCourse; |
| 7 | +use Chamilo\CoreBundle\Entity\AccessUrlRelSession; |
| 8 | +use Chamilo\CoreBundle\Entity\AccessUrlRelUser; |
| 9 | +use Chamilo\CoreBundle\Entity\AccessUrlRelUserGroup; |
6 | 10 | use Chamilo\CoreBundle\Framework\Container;
|
7 | 11 |
|
8 | 12 | /**
|
@@ -90,27 +94,44 @@ public static function update($urlId, $url, $description, $active, bool $isLogin
|
90 | 94 | public static function delete($id)
|
91 | 95 | {
|
92 | 96 | $id = (int) $id;
|
93 |
| - $table = Database::get_main_table(TABLE_MAIN_ACCESS_URL); |
94 |
| - $tableUser = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER); |
95 |
| - $tableCourse = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); |
96 |
| - $tableSession = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_SESSION); |
97 |
| - $tableGroup = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USERGROUP); |
98 | 97 |
|
99 |
| - $sql = "DELETE FROM $tableCourse WHERE access_url_id = ".$id; |
100 |
| - Database::query($sql); |
101 | 98 | /*
|
102 | 99 | * $tableCourseCategory = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE_CATEGORY);
|
103 | 100 | $sql = "DELETE FROM $tableCourseCategory WHERE access_url_id = ".$id;
|
104 | 101 | Database::query($sql);
|
105 | 102 | */
|
106 |
| - $sql = "DELETE FROM $tableSession WHERE access_url_id = ".$id; |
107 |
| - Database::query($sql); |
108 |
| - $sql = "DELETE FROM $tableGroup WHERE access_url_id = ".$id; |
109 |
| - Database::query($sql); |
110 |
| - $sql = "DELETE FROM $tableUser WHERE access_url_id = ".$id; |
111 |
| - Database::query($sql); |
112 |
| - $sql = "DELETE FROM $table WHERE id = ".$id; |
113 |
| - Database::query($sql); |
| 103 | + $em = Container::getEntityManager(); |
| 104 | + |
| 105 | + $relEntities = [ |
| 106 | + AccessUrlRelCourse::class, |
| 107 | + AccessUrlRelSession::class, |
| 108 | + AccessUrlRelUserGroup::class, |
| 109 | + AccessUrlRelUser::class, |
| 110 | + ]; |
| 111 | + |
| 112 | + foreach ($relEntities as $relEntity) { |
| 113 | + $qb = $em->createQueryBuilder(); |
| 114 | + |
| 115 | + $em |
| 116 | + ->createQueryBuilder() |
| 117 | + ->delete($relEntity, 'rel') |
| 118 | + ->where($qb->expr()->eq('rel.url', ':id')) |
| 119 | + ->setParameter('id', $id) |
| 120 | + ->getQuery() |
| 121 | + ->execute() |
| 122 | + ; |
| 123 | + } |
| 124 | + |
| 125 | + $qb = $em->createQueryBuilder(); |
| 126 | + |
| 127 | + $em |
| 128 | + ->createQueryBuilder() |
| 129 | + ->delete(AccessUrl::class, 'au') |
| 130 | + ->where($qb->expr()->eq('au.id', ':id')) |
| 131 | + ->setParameter('id', $id) |
| 132 | + ->getQuery() |
| 133 | + ->execute() |
| 134 | + ; |
114 | 135 |
|
115 | 136 | return true;
|
116 | 137 | }
|
|
0 commit comments