|
21 | 21 | */
|
22 | 22 | class ResourceLinkRepository extends SortableRepository
|
23 | 23 | {
|
| 24 | + private array $toolList = [ |
| 25 | + 'course_description' => '/main/course_description/index.php', |
| 26 | + 'document' => '/resources/document/%resource_node_id%/', |
| 27 | + 'learnpath' => '/main/lp/lp_controller.php', |
| 28 | + 'link' => '/resources/links/%resource_node_id%/', |
| 29 | + 'quiz' => '/main/exercise/exercise.php', |
| 30 | + 'announcement' => '/main/announcements/announcements.php', |
| 31 | + 'glossary' => '/resources/glossary/%resource_node_id%/', |
| 32 | + 'attendance' => '/main/attendance/index.php', |
| 33 | + 'course_progress' => '/main/course_progress/index.php', |
| 34 | + 'agenda' => '/resources/ccalendarevent', |
| 35 | + 'forum' => '/main/forum/index.php', |
| 36 | + 'student_publication' => '/resources/assignment/%resource_node_id%', |
| 37 | + 'survey' => '/main/survey/survey_list.php', |
| 38 | + 'notebook' => '/main/notebook/index.php', |
| 39 | + ]; |
| 40 | + |
24 | 41 | public function __construct(EntityManagerInterface $em)
|
25 | 42 | {
|
26 | 43 | parent::__construct($em, $em->getClassMetadata(ResourceLink::class));
|
@@ -53,4 +70,100 @@ public function removeByResourceInContext(
|
53 | 70 | $this->remove($link);
|
54 | 71 | }
|
55 | 72 | }
|
| 73 | + |
| 74 | + /** |
| 75 | + * Retrieves the list of available tools filtered by a predefined tool list. |
| 76 | + * |
| 77 | + * @return array The list of tools with their IDs and titles. |
| 78 | + */ |
| 79 | + public function getAvailableTools(): array |
| 80 | + { |
| 81 | + $queryBuilder = $this->_em->createQueryBuilder(); |
| 82 | + $queryBuilder |
| 83 | + ->select('DISTINCT t.id, t.title') |
| 84 | + ->from('ChamiloCoreBundle:ResourceLink', 'rl') |
| 85 | + ->innerJoin('ChamiloCoreBundle:ResourceType', 'rt', 'WITH', 'rt.id = rl.resourceTypeGroup') |
| 86 | + ->innerJoin('ChamiloCoreBundle:Tool', 't', 'WITH', 't.id = rt.tool') |
| 87 | + ->where('rl.course IS NOT NULL') |
| 88 | + ->andWhere('t.title IN (:toolList)') |
| 89 | + ->setParameter('toolList', array_keys($this->toolList)); |
| 90 | + |
| 91 | + $result = $queryBuilder->getQuery()->getArrayResult(); |
| 92 | + |
| 93 | + $tools = []; |
| 94 | + foreach ($result as $row) { |
| 95 | + $tools[$row['id']] = ucfirst(str_replace('_', ' ', $row['title'])); |
| 96 | + } |
| 97 | + |
| 98 | + return $tools; |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * Retrieves a usage report of tools with dynamic links. |
| 103 | + * |
| 104 | + * @return array The tool usage data including counts, last update timestamps, and dynamic links. |
| 105 | + */ |
| 106 | + public function getToolUsageReportByTools(array $toolIds): array |
| 107 | + { |
| 108 | + $queryBuilder = $this->_em->createQueryBuilder(); |
| 109 | + |
| 110 | + $queryBuilder |
| 111 | + ->select( |
| 112 | + 'COUNT(rl.id) AS resource_count', |
| 113 | + 'IDENTITY(rl.course) AS course_id', |
| 114 | + 'IDENTITY(rl.session) AS session_id', |
| 115 | + 'IDENTITY(c.resourceNode) AS course_resource_node_id', |
| 116 | + 't.title AS tool_name', |
| 117 | + 'c.title AS course_name', |
| 118 | + 's.title AS session_name', |
| 119 | + 'MAX(rl.updatedAt) AS last_updated' |
| 120 | + ) |
| 121 | + ->from('ChamiloCoreBundle:ResourceLink', 'rl') |
| 122 | + ->innerJoin('ChamiloCoreBundle:ResourceType', 'rt', 'WITH', 'rt.id = rl.resourceTypeGroup') |
| 123 | + ->innerJoin('ChamiloCoreBundle:Tool', 't', 'WITH', 't.id = rt.tool') |
| 124 | + ->innerJoin('ChamiloCoreBundle:Course', 'c', 'WITH', 'c.id = rl.course') |
| 125 | + ->leftJoin('ChamiloCoreBundle:Session', 's', 'WITH', 's.id = rl.session') |
| 126 | + ->where($queryBuilder->expr()->in('t.id', ':toolIds')) |
| 127 | + ->groupBy('rl.course, rl.session, t.title') |
| 128 | + ->orderBy('t.title', 'ASC') |
| 129 | + ->addOrderBy('c.title', 'ASC') |
| 130 | + ->addOrderBy('s.title', 'ASC') |
| 131 | + ->setParameter('toolIds', $toolIds); |
| 132 | + |
| 133 | + $result = $queryBuilder->getQuery()->getArrayResult(); |
| 134 | + |
| 135 | + return array_map(function ($row) { |
| 136 | + $toolName = $row['tool_name']; |
| 137 | + $baseLink = $this->toolList[$toolName] ?? null; |
| 138 | + $link = '-'; |
| 139 | + if ($baseLink) { |
| 140 | + $link = str_replace( |
| 141 | + ['%resource_node_id%'], |
| 142 | + [$row['course_resource_node_id']], |
| 143 | + $baseLink |
| 144 | + ); |
| 145 | + |
| 146 | + $queryParams = [ |
| 147 | + 'cid' => $row['course_id'], |
| 148 | + ]; |
| 149 | + |
| 150 | + if (!empty($row['session_id'])) { |
| 151 | + $queryParams['sid'] = $row['session_id']; |
| 152 | + } |
| 153 | + |
| 154 | + $link .= '?' . http_build_query($queryParams); |
| 155 | + } |
| 156 | + |
| 157 | + return [ |
| 158 | + 'tool_name' => $toolName, |
| 159 | + 'session_id' => $row['session_id'], |
| 160 | + 'session_name' => $row['session_name'] ?: '-', |
| 161 | + 'course_id' => $row['course_id'], |
| 162 | + 'course_name' => $row['course_name'], |
| 163 | + 'resource_count' => (int) $row['resource_count'], |
| 164 | + 'last_updated' => $row['last_updated'] ?: '-', |
| 165 | + 'link' => $link, |
| 166 | + ]; |
| 167 | + }, $result); |
| 168 | + } |
56 | 169 | }
|
0 commit comments