1 | <?php |
||
2 | |||
3 | /* For licensing terms, see /license.txt */ |
||
4 | |||
5 | use Chamilo\CoreBundle\Entity\Course; |
||
0 ignored issues
–
show
|
|||
6 | use Chamilo\CoreBundle\Entity\ExtraField; |
||
7 | use Chamilo\CoreBundle\Entity\Repository\SequenceResourceRepository; |
||
8 | use Chamilo\CoreBundle\Entity\SequenceResource; |
||
9 | use Chamilo\CourseBundle\Entity\CCourseDescription; |
||
10 | use Chamilo\UserBundle\Entity\User; |
||
11 | |||
12 | /** |
||
13 | * Session about page |
||
14 | * Show information about a session and its courses. |
||
15 | * |
||
16 | * @author Angel Fernando Quiroz Campos <[email protected]> |
||
17 | * @author Julio Montoya |
||
18 | */ |
||
19 | $cidReset = true; |
||
20 | |||
21 | require_once __DIR__.'/../inc/global.inc.php'; |
||
22 | |||
23 | if ((api_get_setting('course_catalog_published') != 'true' && api_is_anonymous()) || api_get_configuration_value('session_about_block_all_access') == 'true') { |
||
24 | api_not_allowed(true); |
||
25 | } |
||
26 | |||
27 | $sessionId = isset($_GET['session_id']) ? (int) $_GET['session_id'] : 0; |
||
28 | |||
29 | $em = Database::getManager(); |
||
30 | |||
31 | $session = api_get_session_entity($sessionId); |
||
32 | |||
33 | if (!$session) { |
||
0 ignored issues
–
show
|
|||
34 | api_not_allowed(true); |
||
35 | } |
||
36 | |||
37 | if (api_is_multiple_url_enabled()) { |
||
38 | $accessUrlId = api_get_current_access_url_id(); |
||
39 | $sessionOnUrl = UrlManager::relation_url_session_exist($sessionId, $accessUrlId); |
||
40 | |||
41 | if (!$sessionOnUrl) { |
||
42 | api_not_allowed(true); |
||
43 | } |
||
44 | } |
||
45 | |||
46 | $htmlHeadXtra[] = api_get_asset('readmore-js/readmore.js'); |
||
47 | $courses = []; |
||
48 | $sessionCourses = $em->getRepository('ChamiloCoreBundle:Session')->getCoursesOrderedByPosition($session); |
||
49 | $fieldsRepo = $em->getRepository('ChamiloCoreBundle:ExtraField'); |
||
50 | $fieldTagsRepo = $em->getRepository('ChamiloCoreBundle:ExtraFieldRelTag'); |
||
51 | $userRepo = UserManager::getRepository(); |
||
52 | /** @var SequenceResourceRepository $sequenceResourceRepo */ |
||
53 | $sequenceResourceRepo = $em->getRepository('ChamiloCoreBundle:SequenceResource'); |
||
54 | |||
55 | $tagField = $fieldsRepo->findOneBy([ |
||
56 | 'extraFieldType' => ExtraField::COURSE_FIELD_TYPE, |
||
57 | 'variable' => 'tags', |
||
58 | ]); |
||
59 | |||
60 | $courseValues = new ExtraFieldValue('course'); |
||
61 | $userValues = new ExtraFieldValue('user'); |
||
62 | $sessionValues = new ExtraFieldValue('session'); |
||
63 | |||
64 | /** @var Course $sessionCourse */ |
||
65 | foreach ($sessionCourses as $sessionCourse) { |
||
66 | $courseTags = []; |
||
67 | |||
68 | if (!is_null($tagField)) { |
||
69 | $courseTags = $fieldTagsRepo->getTags($tagField, $sessionCourse->getId()); |
||
70 | } |
||
71 | |||
72 | $courseCoaches = $userRepo->getCoachesForSessionCourse($session, $sessionCourse); |
||
73 | $coachesData = []; |
||
74 | /** @var User $courseCoach */ |
||
75 | foreach ($courseCoaches as $courseCoach) { |
||
76 | $coachData = [ |
||
77 | 'complete_name' => UserManager::formatUserFullName($courseCoach), |
||
78 | 'image' => UserManager::getUserPicture( |
||
79 | $courseCoach->getId(), |
||
80 | USER_IMAGE_SIZE_ORIGINAL |
||
81 | ), |
||
82 | 'diploma' => $courseCoach->getDiplomas(), |
||
83 | 'openarea' => $courseCoach->getOpenarea(), |
||
84 | 'extra_fields' => $userValues->getAllValuesForAnItem( |
||
85 | $courseCoach->getId(), |
||
86 | null, |
||
87 | true |
||
88 | ), |
||
89 | ]; |
||
90 | |||
91 | $coachesData[] = $coachData; |
||
92 | } |
||
93 | |||
94 | $cd = new CourseDescription(); |
||
95 | $cd->set_course_id($sessionCourse->getId()); |
||
96 | $cd->set_session_id($session->getId()); |
||
97 | $descriptionsData = $cd->get_description_data(); |
||
98 | |||
99 | $courseDescription = []; |
||
100 | $courseObjectives = []; |
||
101 | $courseTopics = []; |
||
102 | $courseMethodology = []; |
||
103 | $courseMaterial = []; |
||
104 | $courseResources = []; |
||
105 | $courseAssessment = []; |
||
106 | $courseCustom = []; |
||
107 | |||
108 | if (!empty($descriptionsData['descriptions'])) { |
||
109 | foreach ($descriptionsData['descriptions'] as $descriptionInfo) { |
||
110 | switch ($descriptionInfo['description_type']) { |
||
111 | case CCourseDescription::TYPE_DESCRIPTION: |
||
112 | $courseDescription[] = $descriptionInfo; |
||
113 | break; |
||
114 | case CCourseDescription::TYPE_OBJECTIVES: |
||
115 | $courseObjectives[] = $descriptionInfo; |
||
116 | break; |
||
117 | case CCourseDescription::TYPE_TOPICS: |
||
118 | $courseTopics[] = $descriptionInfo; |
||
119 | break; |
||
120 | case CCourseDescription::TYPE_METHODOLOGY: |
||
121 | $courseMethodology[] = $descriptionInfo; |
||
122 | break; |
||
123 | case CCourseDescription::TYPE_COURSE_MATERIAL: |
||
124 | $courseMaterial[] = $descriptionInfo; |
||
125 | break; |
||
126 | case CCourseDescription::TYPE_RESOURCES: |
||
127 | $courseResources[] = $descriptionInfo; |
||
128 | break; |
||
129 | case CCourseDescription::TYPE_ASSESSMENT: |
||
130 | $courseAssessment[] = $descriptionInfo; |
||
131 | break; |
||
132 | case CCourseDescription::TYPE_CUSTOM: |
||
133 | $courseCustom[] = $descriptionInfo; |
||
134 | break; |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | |||
139 | $courses[] = [ |
||
140 | 'course' => $sessionCourse, |
||
141 | 'description' => $courseDescription, |
||
142 | 'image' => CourseManager::getPicturePath($sessionCourse, true), |
||
143 | 'tags' => $courseTags, |
||
144 | 'objectives' => $courseObjectives, |
||
145 | 'topics' => $courseTopics, |
||
146 | 'methodology' => $courseMethodology, |
||
147 | 'material' => $courseMaterial, |
||
148 | 'resources' => $courseResources, |
||
149 | 'assessment' => $courseAssessment, |
||
150 | 'custom' => array_reverse($courseCustom), |
||
151 | 'coaches' => $coachesData, |
||
152 | 'extra_fields' => $courseValues->getAllValuesForAnItem( |
||
153 | $sessionCourse->getId(), |
||
154 | null, |
||
155 | true |
||
156 | ), |
||
157 | ]; |
||
158 | } |
||
159 | |||
160 | $sessionDates = SessionManager::parseSessionDates( |
||
161 | [ |
||
162 | 'display_start_date' => $session->getDisplayStartDate(), |
||
163 | 'display_end_date' => $session->getDisplayEndDate(), |
||
164 | 'access_start_date' => $session->getAccessStartDate(), |
||
165 | 'access_end_date' => $session->getAccessEndDate(), |
||
166 | 'coach_access_start_date' => $session->getCoachAccessStartDate(), |
||
167 | 'coach_access_end_date' => $session->getCoachAccessEndDate(), |
||
168 | ], |
||
169 | true |
||
170 | ); |
||
171 | |||
172 | $requirements = $sequenceResourceRepo->getRequirements( |
||
173 | $session->getId(), |
||
174 | SequenceResource::SESSION_TYPE |
||
175 | ); |
||
176 | |||
177 | $hasRequirements = false; |
||
178 | foreach ($requirements as $sequence) { |
||
179 | if (!empty($sequence['requirements'])) { |
||
180 | $hasRequirements = true; |
||
181 | break; |
||
182 | } |
||
183 | } |
||
184 | |||
185 | /* View */ |
||
186 | $template = new Template($session->getName(), true, true, false, true, false); |
||
187 | $template->assign('show_tutor', ('true' === api_get_setting('show_session_coach') ? true : false)); |
||
188 | $template->assign('page_url', api_get_path(WEB_PATH)."session/{$session->getId()}/about/"); |
||
189 | $template->assign('session', $session); |
||
190 | $template->assign('session_date', $sessionDates); |
||
191 | $template->assign( |
||
192 | 'is_subscribed', |
||
193 | SessionManager::isUserSubscribedAsStudent( |
||
194 | $session->getId(), |
||
195 | api_get_user_id() |
||
196 | ) |
||
197 | ); |
||
198 | $template->assign( |
||
199 | 'subscribe_button', |
||
200 | CoursesAndSessionsCatalog::getRegisteredInSessionButton( |
||
201 | $session->getId(), |
||
202 | $session->getName(), |
||
203 | $hasRequirements, |
||
204 | true, |
||
205 | true |
||
206 | ) |
||
207 | ); |
||
208 | $template->assign( |
||
209 | 'user_session_time', |
||
210 | SessionManager::getDayLeftInSession( |
||
211 | ['id' => $session->getId(), 'duration' => $session->getDuration()], |
||
212 | api_get_user_id() |
||
213 | ) |
||
214 | ); |
||
215 | |||
216 | $plugin = BuyCoursesPlugin::create(); |
||
217 | $checker = $plugin->isEnabled(); |
||
218 | $sessionIsPremium = null; |
||
219 | if ($checker) { |
||
220 | $sessionIsPremium = $plugin->getItemByProduct( |
||
221 | $sessionId, |
||
222 | BuyCoursesPlugin::PRODUCT_TYPE_SESSION |
||
223 | ); |
||
224 | if ($sessionIsPremium) { |
||
0 ignored issues
–
show
The expression
$sessionIsPremium of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent. Consider making the comparison explicit by using ![]() |
|||
225 | ChamiloSession::write('SessionIsPremium', true); |
||
226 | ChamiloSession::write('sessionId', $sessionId); |
||
227 | } |
||
228 | } |
||
229 | |||
230 | $redirectToSession = api_get_configuration_value('allow_redirect_to_session_after_inscription_about'); |
||
231 | $redirectToSession = $redirectToSession ? '?s='.$sessionId : false; |
||
232 | |||
233 | $coursesInThisSession = SessionManager::get_course_list_by_session_id($sessionId); |
||
234 | $coursesCount = count($coursesInThisSession); |
||
235 | $redirectToSession = 1 == $coursesCount && $redirectToSession |
||
236 | ? ($redirectToSession.'&cr='.array_values($coursesInThisSession)[0]['directory']) |
||
237 | : $redirectToSession; |
||
238 | |||
239 | $template->assign('redirect_to_session', $redirectToSession); |
||
240 | $template->assign('courses', $courses); |
||
241 | $essence = Essence\Essence::instance(); |
||
242 | $template->assign('essence', $essence); |
||
243 | $template->assign( |
||
244 | 'session_extra_fields', |
||
245 | $sessionValues->getAllValuesForAnItem($session->getId(), null, true) |
||
246 | ); |
||
247 | $template->assign('has_requirements', $hasRequirements); |
||
248 | $template->assign('sequences', $requirements); |
||
249 | $template->assign('is_premium', $sessionIsPremium); |
||
250 | $layout = $template->get_template('session/about.tpl'); |
||
251 | $content = $template->fetch($layout); |
||
252 | $template->assign('content', $content); |
||
253 | $template->display_one_col_template(); |
||
254 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: